summaryrefslogtreecommitdiff
path: root/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast.rs')
-rw-r--r--src/ast.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ast.rs b/src/ast.rs
index f627178..bc3547d 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -89,6 +89,12 @@ impl<'a> Document {
{
let mut ast: Pandoc = serde_json::from_str(json)?;
let meta = Metadata::new(basedir, &ast)?;
+ let mut linter = LintingVisitor::default();
+ linter.walk_pandoc(&mut ast);
+ if !linter.issues.is_empty() {
+ // Currently we can't really return more than one error so return one
+ return Err(linter.issues.remove(0));
+ }
let files = DataFiles::new(&mut ast);
Ok(Document::new(markdowns, ast, meta, files))
}
@@ -1077,6 +1083,41 @@ impl MutVisitor for BlockClassVisitor {
}
}
+#[derive(Default)]
+struct LintingVisitor {
+ 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 is_class(attr, "file") {
+ let newlines: Vec<_> = 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(
+ get_filename(&attr),
+ newlines[0].to_owned(),
+ )),
+ },
+ _ => self.issues.push(SubplotError::RepeatedAddNewlineAttribute(
+ get_filename(&attr),
+ )),
+ }
+ }
+ }
+ _ => {
+ self.visit_block(block);
+ }
+ }
+ }
+ }
+}
+
/// Get the base directory given the name of the markdown file.
///
/// All relative filename, such as bindings files, are resolved