summaryrefslogtreecommitdiff
path: root/src/md/visitor/linting.rs
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2023-02-01 23:49:11 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2023-02-01 23:49:11 +0000
commitb6df0fa5b7046bad97f63dc928a9776cecaee623 (patch)
tree7f2fe57569bdf9d77d0bc30e3fac78ba2d32ff92 /src/md/visitor/linting.rs
parente1d63019fdd6f0d24703197b6a6029f26e6f089f (diff)
parentb160ad5b9f0e38859b0a6d3c3262afbb39067584 (diff)
downloadsubplot-b6df0fa5b7046bad97f63dc928a9776cecaee623.tar.gz
Merge branch 'liw/refactor-md' into 'main'
improve Markdown API See merge request subplot/subplot!307
Diffstat (limited to 'src/md/visitor/linting.rs')
-rw-r--r--src/md/visitor/linting.rs40
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);
+ }
+ }
+ }
+ }
+}