pub struct Document { /* private fields */ }
Expand description
A parsed Subplot document.
Pandoc works by parsing its various input files and constructing an abstract syntax tree or AST. When Pandoc generates output, it works based on the AST. This way, the input parsing and output generation are cleanly separated.
A Pandoc filter can modify the AST before output generation starts working. This allows the filter to make changes to what gets output, without having to understand the input documents at all.
This function is a Pandoc filter, to be use with pandoc_ast::filter, for typesetting Subplot documents.
Example
fix this example;
let markdown = "\
---
title: Test Title
...
This is a test document.
";
use std::io::Write;
use tempfile::NamedTempFile;
let mut f = NamedTempFile::new().unwrap();
f.write_all(markdown.as_bytes()).unwrap();
let filename = f.path();
use subplot;
let basedir = std::path::Path::new(".");
let style = subplot::Style::default();
let doc = subplot::Document::from_file(&basedir, filename, style, None).unwrap();
assert_eq!(doc.files(), &[]);
Implementations
sourceimpl Document
impl Document
sourcepub fn from_json<P>(
basedir: P,
markdowns: Vec<PathBuf>,
json: &str,
style: Style,
template: Option<&str>
) -> Result<Document, SubplotError> where
P: AsRef<Path> + Debug,
pub fn from_json<P>(
basedir: P,
markdowns: Vec<PathBuf>,
json: &str,
style: Style,
template: Option<&str>
) -> Result<Document, SubplotError> where
P: AsRef<Path> + Debug,
Construct a Document from a JSON AST
sourcepub fn from_file(
basedir: &Path,
filename: &Path,
style: Style,
template: Option<&str>
) -> Result<Document, SubplotError>
pub fn from_file(
basedir: &Path,
filename: &Path,
style: Style,
template: Option<&str>
) -> Result<Document, SubplotError>
Construct a Document from a named file.
The file can be in any format Pandoc understands. This runs Pandoc to parse the file into an AST, so it can be a little slow.
sourcepub fn from_file_with_pullmark(
basedir: &Path,
filename: &Path,
style: Style,
template: Option<&str>
) -> Result<Document, SubplotError>
pub fn from_file_with_pullmark(
basedir: &Path,
filename: &Path,
style: Style,
template: Option<&str>
) -> Result<Document, SubplotError>
Construct a Document from a named file, using the pullmark_cmark crate.
The file can be in the CommonMark format, with some extensions. This uses the pulldown-cmark crate to parse the file into an AST.
sourcepub fn ast(&self) -> Result<String, SubplotError>
pub fn ast(&self) -> Result<String, SubplotError>
Return the AST of a Document, serialized as JSON.
This is useful in a Pandoc filter, so that the filter can give it back to Pandoc for typesetting.
sourcepub fn sources(&mut self, template: Option<&str>) -> Vec<PathBuf>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn sources(&mut self, template: Option<&str>) -> Vec<PathBuf>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Return all source filenames for the document.
The sources are any files that affect the output so that if the source file changes, the output needs to be re-generated.
sourcepub fn lint(&self) -> Result<(), SubplotError>
pub fn lint(&self) -> Result<(), SubplotError>
Check the document for common problems.
sourcepub fn check_named_files_exist(
&mut self,
template: &str
) -> Result<bool, SubplotError>
pub fn check_named_files_exist(
&mut self,
template: &str
) -> Result<bool, SubplotError>
Check that all named files (in matched steps) are actually present in the document.
sourcepub fn check_embedded_files_are_used(
&mut self,
template: &str
) -> Result<bool, SubplotError>
pub fn check_embedded_files_are_used(
&mut self,
template: &str
) -> Result<bool, SubplotError>
Check that all embedded files are used by matched steps.
sourcepub fn check_matched_steps_have_impl(&mut self, template: &str) -> bool
pub fn check_matched_steps_have_impl(&mut self, template: &str) -> bool
Check that all matched steps actually have function implementations
sourcepub fn scenarios(&mut self) -> Result<Vec<Scenario>, SubplotError>
pub fn scenarios(&mut self) -> Result<Vec<Scenario>, SubplotError>
Return all scenarios in a document.
sourcepub fn matched_scenarios(
&mut self,
template: &str
) -> Result<Vec<MatchedScenario>, SubplotError>
pub fn matched_scenarios(
&mut self,
template: &str
) -> Result<Vec<MatchedScenario>, SubplotError>
Return matched scenarios in a document.
sourcepub fn template(&self) -> Result<&str, SubplotError>
pub fn template(&self) -> Result<&str, SubplotError>
Extract a template name from this document
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more