diff options
Diffstat (limited to 'src/md/panhelper.rs')
-rw-r--r-- | src/md/panhelper.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/md/panhelper.rs b/src/md/panhelper.rs new file mode 100644 index 0000000..f7ab801 --- /dev/null +++ b/src/md/panhelper.rs @@ -0,0 +1,26 @@ +use pandoc_ast::Attr; + +/// Is a code block marked as being of a given type? +pub fn is_class(attr: &Attr, class: &str) -> bool { + let (_id, classes, _kvpairs) = attr; + classes.iter().any(|s| s == class) +} + +/// Utility function to find key/value pairs from an attribute +pub fn find_attr_kv<'a>(attr: &'a Attr, key: &'static str) -> impl Iterator<Item = &'a str> { + attr.2.iter().flat_map(move |(key_, value)| { + if key == key_ { + Some(value.as_ref()) + } else { + None + } + }) +} + +/// Get the filename for a fenced code block tagged .file. +/// +/// The filename is the first (and presumably only) identifier for the +/// block. +pub fn get_filename(attr: &Attr) -> String { + attr.0.to_string() +} |