summaryrefslogtreecommitdiff
path: root/src/md/panhelper.rs
blob: f7ab8018375c3ab7b9116dd70a79f620e62e3811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()
}