diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-09-14 14:14:38 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-09-16 16:40:18 +0300 |
commit | 458525d21c9960d98fa932be06cf133cd910ce7b (patch) | |
tree | 08f3d913e388c5870231b757f64ed0fe157ba105 /src/bin/cli/mod.rs | |
parent | 9198b69c561e582704dbd99000d59e474c406a67 (diff) | |
download | subplot-458525d21c9960d98fa932be06cf133cd910ce7b.tar.gz |
feat! parse Markdown input with pull-cmark instead of Pandoc
This is a first step towards being able to use Subplot codegen from a
project's build.rs, and with only pure-Rust build dependencies.
Replace Pandoc for parsing Markdown input with pulldown-cmark. This is
mostly a drop-in replacement, but not entirely. The YAML parsing is
more strict now.
Note that this is a breaking change. Some subplots that used to work,
and still work with docgen, no longer work with the new parser. Major
differences are:
* Only specific fields are supported. All the Markdown files in the
Subplot source tree work. If anything else is needed, and it likely
is, the new parser needs to be extended.
* The bindings, functions, classes, and bibliography fields MUST be
lists of strings. A single string value will no longer work.
Sponsored-by: pep.foundation
Diffstat (limited to 'src/bin/cli/mod.rs')
-rw-r--r-- | src/bin/cli/mod.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index 30f5601..c53da0f 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -33,6 +33,28 @@ where Ok(doc) } +#[instrument(level = "trace")] +pub fn load_document_with_pullmark<P>(filename: P, style: Style) -> Result<Document> +where + P: AsRef<Path> + Debug, +{ + let filename = filename.as_ref(); + let base_path = subplot::get_basedir_from(filename); + event!( + Level::TRACE, + ?filename, + ?base_path, + "Loading document based at `{}` called `{}` with {:?} using pullmark-cmark", + base_path.display(), + filename.display(), + style + ); + let doc = Document::from_file_with_pullmark(&base_path, filename, style)?; + event!(Level::TRACE, "Loaded doc from file OK"); + + Ok(doc) +} + pub fn extract_file<'a>(doc: &'a Document, filename: &str) -> Result<&'a DataFile> { for file in doc.files() { if file.filename() == filename { |