diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-11-04 22:05:26 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-11-04 22:05:26 +0000 |
commit | 45456147deb378288757c7c619911b1a8eb8debc (patch) | |
tree | 672b1c2101c647281cf721247860b6f1815ebdb0 /src/typeset.rs | |
parent | 57b10af925c28969d5032c1a41a7e3535f9a5484 (diff) | |
download | subplot-45456147deb378288757c7c619911b1a8eb8debc.tar.gz |
docgen: Support pikchr diagrams
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/typeset.rs')
-rw-r--r-- | src/typeset.rs | 19 |
1 files changed, 18 insertions, 1 deletions
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. |