From 1bd5ab49f17699fd3ae08cd847221ce969e38337 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 22 Jan 2023 11:40:51 +0200 Subject: chore: unused code from ast.rs Sponsored-by: author --- src/ast.rs | 106 +------------------------------------------------------------ 1 file changed, 1 insertion(+), 105 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index b60df71..ed163f0 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,9 +1,7 @@ use lazy_static::lazy_static; -use log::trace; -use pandoc_ast::{Map, MetaValue}; use regex::Regex; use serde::Deserialize; -use serde_yaml::{Mapping, Value}; +use serde_yaml::Value; use std::collections::{BTreeMap, HashMap}; use std::path::{Path, PathBuf}; @@ -58,9 +56,7 @@ pub struct YamlMetadata { impl YamlMetadata { #[cfg(test)] fn new(yaml_text: &str) -> Result { - trace!("Parsing YAML"); let meta: Self = serde_yaml::from_str(yaml_text)?; - trace!("parsed metadata: {:#?}", meta); Ok(meta) } @@ -122,106 +118,6 @@ impl YamlMetadata { None } } - - /// Convert into a pandoc_ast::Map. - pub fn to_map(&self) -> Map { - trace!("Creating metadata map from parsed YAML"); - let mut map: Map = Map::new(); - - map.insert("title".into(), meta_string(&self.title)); - - if let Some(v) = &self.subtitle { - map.insert("subtitle".into(), meta_string(v)); - } - - if let Some(authors) = &self.authors { - let authors: Vec = authors - .iter() - .map(|s| MetaValue::MetaString(s.into())) - .collect(); - map.insert("author".into(), MetaValue::MetaList(authors)); - } - - if let Some(v) = &self.date { - map.insert("date".into(), meta_string(v)); - } - - if let Some(v) = &self.classes { - map.insert("classes".into(), meta_strings(v)); - } - - if !self.impls.is_empty() { - let impls = self - .impls - .iter() - .map(|(k, v)| (k.to_owned(), Box::new(meta_path_bufs(v)))) - .collect(); - map.insert("impls".into(), MetaValue::MetaMap(impls)); - } - - if let Some(v) = &self.bibliography { - map.insert("bibliography".into(), meta_path_bufs(v)); - } - - if let Some(v) = &self.bindings { - map.insert("bindings".into(), meta_path_bufs(v)); - } - - if let Some(v) = &self.documentclass { - map.insert("documentclass".into(), meta_string(v)); - } - - if let Some(pandoc) = &self.pandoc { - for (key, value) in pandoc.iter() { - map.insert(key.to_string(), value_to_pandoc(value)); - } - } - - trace!("Created metadata map from parsed YAML"); - map - } -} - -fn mapping_to_pandoc(mapping: &Mapping) -> MetaValue { - let mut map = Map::new(); - for (key, value) in mapping.iter() { - let key = if let MetaValue::MetaString(s) = value_to_pandoc(key) { - s - } else { - panic!("key not a string: {:?}", key); - }; - map.insert(key, Box::new(value_to_pandoc(value))); - } - - MetaValue::MetaMap(map) -} - -fn value_to_pandoc(data: &Value) -> MetaValue { - match data { - Value::Null => unreachable!("null not OK"), - Value::Number(_) => unreachable!("number not OK"), - Value::Sequence(_) => unreachable!("sequence not OK"), - - Value::Bool(b) => MetaValue::MetaBool(*b), - Value::String(s) => MetaValue::MetaString(s.clone()), - Value::Mapping(mapping) => mapping_to_pandoc(mapping), - } -} - -fn meta_string(s: &str) -> MetaValue { - MetaValue::MetaString(s.to_string()) -} - -fn meta_strings(v: &[String]) -> MetaValue { - MetaValue::MetaList(v.iter().map(|s| meta_string(s)).collect()) -} - -fn meta_path_buf(p: &Path) -> MetaValue { - meta_string(&p.display().to_string()) -} - -fn meta_path_bufs(v: &[PathBuf]) -> MetaValue { - MetaValue::MetaList(v.iter().map(|p| meta_path_buf(p)).collect()) } #[cfg(test)] -- cgit v1.2.1