summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2022-05-04 19:57:02 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2022-05-04 19:59:02 +0100
commit6448825a8f9beca0333464c9bfbc8fb96d142189 (patch)
treef4896b5b3cccb6d041d1469d9e43984f11126dd5
parent12059fcb1ce8237e5587773043cd442e036531c2 (diff)
downloadsubplot-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.rs4
-rw-r--r--src/typeset.rs5
-rw-r--r--src/visitor/linting.rs2
-rw-r--r--src/visitor/typesetting.rs2
4 files changed, 10 insertions, 3 deletions
diff --git a/src/doc.rs b/src/doc.rs
index 9c5fae8..ed88e95 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -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)