diff options
Diffstat (limited to 'src/md/visitor/linting.rs')
-rw-r--r-- | src/md/visitor/linting.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/md/visitor/linting.rs b/src/md/visitor/linting.rs new file mode 100644 index 0000000..d64b03e --- /dev/null +++ b/src/md/visitor/linting.rs @@ -0,0 +1,40 @@ +use crate::md::panhelper; +use crate::SubplotError; + +use pandoc_ast::{Block, MutVisitor}; + +#[derive(Default)] +pub struct LintingVisitor { + pub issues: Vec<SubplotError>, +} + +impl MutVisitor for LintingVisitor { + fn visit_vec_block(&mut self, vec_block: &mut Vec<Block>) { + for block in vec_block { + match block { + Block::CodeBlock(attr, _) => { + if panhelper::is_class(attr, "file") || panhelper::is_class(attr, "example") { + let newlines: Vec<_> = + panhelper::find_attr_kv(attr, "add-newline").collect(); + match newlines.len() { + 0 => {} + 1 => match newlines[0].to_ascii_lowercase().as_ref() { + "auto" | "yes" | "no" => {} + _ => self.issues.push(SubplotError::UnrecognisedAddNewline( + panhelper::get_filename(attr), + newlines[0].to_owned(), + )), + }, + _ => self.issues.push(SubplotError::RepeatedAddNewlineAttribute( + panhelper::get_filename(attr), + )), + } + } + } + _ => { + self.visit_block(block); + } + } + } + } +} |