summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--subplot.md57
5 files changed, 67 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)
diff --git a/subplot.md b/subplot.md
index 3d4fb91..d7a6c29 100644
--- a/subplot.md
+++ b/subplot.md
@@ -2779,6 +2779,63 @@ This is the embedded file.
```
~~~~
+## Example blocks
+
+Similar to embedded files, Subplot permits you to mark blocks as examples.
+Example blocks are formatted just like file blocks, but they may not be
+used by scenarios and their names are separated from files, and are not
+subject to the same naming constraints (caseless uniqueness).
+
+### Examples may be unused
+
+~~~scenario
+given file unusedexample.md
+and an installed subplot
+when I try to run subplot docgen --merciful unusedexample.md -o unusedexample.html
+then command is successful
+and file unusedexample.html exists
+and stderr doesn't contain "thisisnotused.txt"
+~~~
+
+~~~{#unusedexample.md .file .markdown .numberLines}
+---
+title: Example is not an embedded file
+...
+
+```{#thisisnotused.txt .example}
+This is the embedded example.
+```
+~~~
+
+### Examples are not files
+
+~~~scenario
+given file examplesnotfiles.md
+and an installed subplot
+when I try to run subplot codegen examplesnotfiles.md -t python -o examplesnotfiles.html
+then command fails
+and file examplesnotfiles.html does not exist
+and stderr contains "thisisanexample.txt"
+~~~
+
+~~~{#examplesnotfiles.md .file .markdown .numberLines}
+---
+title: Examples are not files
+impls:
+ python: []
+...
+
+# Try and use an example as a file
+
+```scenario
+given file thisisanexample.txt
+```
+
+```{#thisisanexample.txt .example}
+This is an embedded example
+```
+
+~~~
## Steps must match bindings