diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2022-05-04 19:57:02 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2022-05-04 19:59:02 +0100 |
commit | 6448825a8f9beca0333464c9bfbc8fb96d142189 (patch) | |
tree | f4896b5b3cccb6d041d1469d9e43984f11126dd5 | |
parent | 12059fcb1ce8237e5587773043cd442e036531c2 (diff) | |
download | subplot-6448825a8f9beca0333464c9bfbc8fb96d142189.tar.gz |
(subplot): Add support for example blocks
In support of #256, this adds `example` as a permitted class and
ensures that we typeset it as though it were a file.
This includes linting it as though it were a file too.
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/doc.rs | 4 | ||||
-rw-r--r-- | src/typeset.rs | 5 | ||||
-rw-r--r-- | src/visitor/linting.rs | 2 | ||||
-rw-r--r-- | src/visitor/typesetting.rs | 2 |
4 files changed, 10 insertions, 3 deletions
@@ -28,7 +28,9 @@ use log::{error, trace}; /// The set of known (special) classes which subplot will always recognise /// as being valid. -static SPECIAL_CLASSES: &[&str] = &["scenario", "file", "dot", "pikchr", "plantuml", "roadmap"]; +static SPECIAL_CLASSES: &[&str] = &[ + "scenario", "file", "example", "dot", "pikchr", "plantuml", "roadmap", +]; /// The set of known (file-type) classes which subplot will always recognise /// as being valid. diff --git a/src/typeset.rs b/src/typeset.rs index 18e5a44..9522e69 100644 --- a/src/typeset.rs +++ b/src/typeset.rs @@ -41,6 +41,11 @@ pub fn file_block(attr: &Attr, text: &str) -> Block { // Otherwise if it doesn't say numberLines we add that in. cbattrs.1.push("numberLines".to_string()); } + // If this was an `example`, convert that class to `file` + if cbattrs.1.iter().any(|s| s == "example") { + cbattrs.1.retain(|s| s != "example"); + cbattrs.1.push("file".into()); + } let codeblock = Block::CodeBlock(cbattrs, text.to_string()); let noattr = ("".to_string(), vec![], vec![]); Block::Div(noattr, vec![intro, codeblock]) diff --git a/src/visitor/linting.rs b/src/visitor/linting.rs index 03b49ee..6266516 100644 --- a/src/visitor/linting.rs +++ b/src/visitor/linting.rs @@ -13,7 +13,7 @@ impl MutVisitor for LintingVisitor { for block in vec_block { match block { Block::CodeBlock(attr, _) => { - if panhelper::is_class(attr, "file") { + 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() { diff --git a/src/visitor/typesetting.rs b/src/visitor/typesetting.rs index 8d73f3e..da9c362 100644 --- a/src/visitor/typesetting.rs +++ b/src/visitor/typesetting.rs @@ -40,7 +40,7 @@ impl<'a> MutVisitor for TypesettingVisitor<'a> { Block::CodeBlock(attr, s) => { if is_class(attr, "scenario") { *block = typeset::scenario_snippet(self.bindings, s, &mut self.warnings) - } else if is_class(attr, "file") { + } else if is_class(attr, "file") || is_class(attr, "example") { *block = typeset::file_block(attr, s) } else if is_class(attr, "dot") { *block = typeset::dot_to_block(s, &mut self.warnings) |