diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-12-28 18:28:32 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-12-28 18:28:32 +0200 |
commit | 5906a497322277da04e6b4a3f7dc8b558b45e38a (patch) | |
tree | c06fb243de17c54bbb5adf748a5c3a5afc6cbc04 | |
parent | e9cb02bbfc6c1ff5321abfaaf1275dd301423b75 (diff) | |
download | subplot-5906a497322277da04e6b4a3f7dc8b558b45e38a.tar.gz |
refactor: drop unused extract_metadata function
This was orphaned when we dropped the functionality to extract YAML
metadata embedded in the Markdown source. Because the function was
exported, tools didn't complain that it's unused.
Sponsored-by: author
-rw-r--r-- | src/ast.rs | 45 | ||||
-rw-r--r-- | src/lib.rs | 2 |
2 files changed, 1 insertions, 46 deletions
@@ -46,51 +46,6 @@ impl AbstractSyntaxTree { } } -/// Extract YAML metadata from a Markdown document. -pub fn extract_metadata(markdown: &str) -> Result<(YamlMetadata, &str), Error> { - trace!("Extracting YAML from Markdown"); - let (yaml, md) = if let Some((yaml, markdown)) = get_yaml(&LEADING_YAML_PATTERN, markdown) { - trace!("Found leading YAML: {:?}", yaml); - (yaml, markdown) - } else if let Some((yaml, _markdown)) = get_yaml(&TRAILING_YAML_PATTERN, markdown) { - trace!("Found trailing YAML: {:?}", yaml); - (yaml, markdown) - } else { - trace!("No YAML to be found"); - return Err(Error::NoMetadata); - }; - let meta = YamlMetadata::new(yaml)?; - trace!("Parsing markdown: OK"); - Ok((meta, md)) -} - -// Extract a YAML metadata block using a given regex. -fn get_yaml<'a>(pat: &Regex, markdown: &'a str) -> Option<(&'a str, &'a str)> { - trace!("Markdown: {:?}", markdown); - if let Some(c) = pat.captures(markdown) { - trace!("YAML regex matches: {:?}", c); - let yaml = c.name("yaml"); - let text = c.name("text"); - trace!("YAML metadata: {:?}", yaml); - trace!("markdown: {:?}", text); - if yaml.is_some() && text.is_some() { - trace!("YAML regex captures YAML and text"); - let yaml = yaml?; - let text = text?; - let yaml = &markdown[yaml.start()..yaml.end()]; - let text = &markdown[text.start()..text.end()]; - assert!(yaml.starts_with("---")); - assert!(yaml.ends_with("...\n")); - return Some((yaml, text)); - } else { - trace!("YAML regex fails to capture YAML"); - } - } else { - trace!("YAML regex does not match"); - } - None -} - // Parse Markdown into a sequence of Blocks. fn parse_blocks(markdown: &str) -> Vec<Block> { trace!("Parsing blocks"); @@ -73,4 +73,4 @@ mod codegen; pub use codegen::generate_test_program; mod ast; -pub use ast::{extract_metadata, AbstractSyntaxTree, YamlMetadata}; +pub use ast::{AbstractSyntaxTree, YamlMetadata}; |