diff options
Diffstat (limited to 'src/ast.rs')
-rw-r--r-- | src/ast.rs | 38 |
1 files changed, 14 insertions, 24 deletions
@@ -279,7 +279,7 @@ pub enum Error { /// block we can work with, in any input file. By being strict here we /// make it easier to tell the user when a metadata block has, say, a /// misspelled field. -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Clone, Deserialize)] #[serde(deny_unknown_fields)] pub struct YamlMetadata { title: String, @@ -288,6 +288,7 @@ pub struct YamlMetadata { date: Option<String>, classes: Option<Vec<String>>, bibliography: Option<Vec<PathBuf>>, + markdowns: Vec<PathBuf>, bindings: Option<Vec<PathBuf>>, documentclass: Option<String>, #[serde(default)] @@ -301,7 +302,13 @@ impl YamlMetadata { Ok(meta) } - fn to_map(&self) -> Map<String, MetaValue> { + /// Name of file with the Markdown for the subplot document. + pub fn markdown(&self) -> &Path { + &self.markdowns[0] + } + + /// Convert into a pandoc_ast::Map. + pub fn to_map(&self) -> Map<String, MetaValue> { trace!("Creating metadata map from parsed YAML"); let mut map: Map<String, MetaValue> = Map::new(); @@ -367,8 +374,8 @@ fn meta_path_bufs(v: &[PathBuf]) -> MetaValue { #[cfg(test)] mod test { - use super::{extract_metadata, parse_code_block_attrs, AbstractSyntaxTree, YamlMetadata}; - use std::path::PathBuf; + use super::{parse_code_block_attrs, YamlMetadata}; + use std::path::{Path, PathBuf}; #[test] fn code_block_attrs() { @@ -392,26 +399,6 @@ mod test { } #[test] - fn parses_leading_meta() { - let markdown = "\n\n---\ntitle: Foo Bar\n...\nfoobar\n"; - let (meta, markdown) = extract_metadata(markdown).unwrap(); - let ast = AbstractSyntaxTree::new(meta, markdown); - let doc = ast.to_pandoc(); - let keys: Vec<String> = doc.meta.keys().cloned().collect(); - assert_eq!(keys, ["title"]); - } - - #[test] - fn parses_trailing_meta() { - let markdown = "foobar\n---\ntitle: Foo Bar\n...\n\n\n"; - let (meta, markdown) = extract_metadata(markdown).unwrap(); - let ast = AbstractSyntaxTree::new(meta, markdown); - let doc = ast.to_pandoc(); - let keys: Vec<String> = doc.meta.keys().cloned().collect(); - assert_eq!(keys, ["title"]); - } - - #[test] fn full_meta() { let meta = YamlMetadata::new( "\ @@ -425,6 +412,8 @@ impls: bibliography: - foo.bib - bar.bib +markdowns: +- test.md bindings: - foo.yaml - bar.yaml @@ -438,6 +427,7 @@ bindings: meta.bibliography.unwrap(), &[path("foo.bib"), path("bar.bib")] ); + assert_eq!(meta.markdowns, vec![Path::new("test.md")]); assert_eq!( meta.bindings.unwrap(), &[path("foo.yaml"), path("bar.yaml")] |