Read more about installation and examples here
The main feature of
paperis parsing text files (such as .txt or .docx) into their corresponding html version.
The tools recursively goes through the source directory, and generate a
distdir that keeps the same folder structure as the source file.
It also generate an
index.htmlwhich indexes all the links to .html files inside
$ cargo run -- --help USAGE: paper.exe [OPTIONS] FLAGS: -h, --help Print help information -V, --version Print version information OPTIONS: -i, --input <FILE>... Path to file(s) -o, --output <FILE> Path to output file -s, --stylesheet <URL or FILE> Link to stylesheet
What I love about this project so much is the ease of introducing new features. Let's look at the project' structure.
+-- src +-- cli | +-- arg_parser.rs | +-- generator.rs | +-- mod.rs +-- file_parser | +-- asset | +-- template.html | +-- source_file.rs | +-- template_file.rs | +-- mod.rs | +-- main.rs
There are two modules represent the two main features:
clihas all the logic for working with parsing and caching CLI arguments, as well as running the program
file_parserhas all the logic for working with reading and parsing the content of file_parser
+-- src +-- cli +-- arg_parser.rs +-- generator.rs +-- mod.rs
ArgsParserhas a single responsibility: to parse the arguments from the CLI and cache it.
Generatoracts as a coordinator, controling the flow of the program. It sends out users' input to modules and generate the corresponding results.
ArgsParseris injected into
ArgsParseris a wrapper on top of
clap.rs, but it can be easily switched to another library. As long as the parser provides parsed arguments,
+-- src +-- file_parser +-- asset +-- template.html +-- source_file.rs +-- template_file.rs +-- mod.rs
SourceFilerepresents the parsed text file (raw data). It has all the logic to parse and store the read content.
Templaterepresents the html file (dist file). The destination where it should be is separated from the class to keep its single reposibility of converting text to html. In the future, if there's a need for parsing more than just paragraphs (e.g. anchor, image, etc.), they will also be inside