summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-11-04 22:05:26 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-11-04 22:05:26 +0000
commit45456147deb378288757c7c619911b1a8eb8debc (patch)
tree672b1c2101c647281cf721247860b6f1815ebdb0
parent57b10af925c28969d5032c1a41a7e3535f9a5484 (diff)
downloadsubplot-45456147deb378288757c7c619911b1a8eb8debc.tar.gz
docgen: Support pikchr diagrams
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r--src/doc.rs2
-rw-r--r--src/typeset.rs19
-rw-r--r--src/visitor/typesetting.rs14
3 files changed, 33 insertions, 2 deletions
diff --git a/src/doc.rs b/src/doc.rs
index 89f626a..64f4648 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -19,7 +19,7 @@ use pandoc_ast::{MutVisitor, Pandoc};
/// The set of known (special) classes which subplot will always recognise
/// as being valid.
-static SPECIAL_CLASSES: &[&str] = &["scenario", "file", "dot", "plantuml", "roadmap"];
+static SPECIAL_CLASSES: &[&str] = &["scenario", "file", "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 40cbef6..2904b6a 100644
--- a/src/typeset.rs
+++ b/src/typeset.rs
@@ -4,7 +4,7 @@ use crate::PartialStep;
use crate::ScenarioStep;
use crate::StepKind;
use crate::SubplotError;
-use crate::{DotMarkup, GraphMarkup, PlantumlMarkup};
+use crate::{DotMarkup, GraphMarkup, PikchrMarkup, PlantumlMarkup};
use pandoc_ast::Attr;
use pandoc_ast::Block;
@@ -133,6 +133,23 @@ pub fn link_as_note(attr: Attr, text: Vec<Inline>, target: Target) -> Inline {
Inline::Span(attr, text)
}
+/// Take a pikchr graph, render it as SVG, and return an AST block element.
+///
+/// The `Block` will contain the SVG data. This allows the graph to be
+/// rendered without referencing external entities.
+///
+/// If the code block which contained the pikchr contains other classes, they
+/// can be added to the SVG for use in later typesetting etc.
+pub fn pikchr_to_block(pikchr: &str, class: Option<&str>) -> Block {
+ match PikchrMarkup::new(pikchr, class).as_svg() {
+ Ok(svg) => typeset_svg(svg),
+ Err(err) => {
+ eprintln!("pikchr render failed: {}", err);
+ error(err)
+ }
+ }
+}
+
// Take a dot graph, render it as SVG, and return an AST Block
// element. The Block will contain the SVG data. This allows the graph
// to be rendered without referending external entities.
diff --git a/src/visitor/typesetting.rs b/src/visitor/typesetting.rs
index deffcd9..f59f81d 100644
--- a/src/visitor/typesetting.rs
+++ b/src/visitor/typesetting.rs
@@ -39,6 +39,20 @@ impl<'a> MutVisitor for TypesettingVisitor<'a> {
*block = typeset::plantuml_to_block(s)
} else if is_class(attr, "roadmap") {
*block = typeset::roadmap_to_block(s)
+ } else if is_class(attr, "pikchr") {
+ let other_classes: Vec<_> = attr
+ .1
+ .iter()
+ .map(String::as_str)
+ .filter(|s| *s != "pikchr")
+ .collect();
+ let class = if other_classes.is_empty() {
+ None
+ } else {
+ Some(other_classes.join(" "))
+ };
+ let class = class.as_deref();
+ *block = typeset::pikchr_to_block(s, class)
}
}
_ => {