summaryrefslogtreecommitdiff
path: root/src/visitor/typesetting.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-08-08 18:43:57 +0300
committerLars Wirzenius <liw@liw.fi>2020-08-08 20:47:22 +0300
commitd1651321ec1cd1e02fb93fe6e31ab4de115356c9 (patch)
treef5966966f0cb910659a62afa63c7f089913e9937 /src/visitor/typesetting.rs
parentc3e8c88f3294338e8ea4678fb5493c96150a4e3c (diff)
downloadsubplot-d1651321ec1cd1e02fb93fe6e31ab4de115356c9.tar.gz
refactor: split stuff from src/ast.rs into smaller modules
This only moves things around, to avoid huge source code modules. It doesn't rename functions, add unit tests, or similar. * src/datafiles.rs: DataFile, DataFiles * src/metata.rs: Metadata * src/panhelper.rs: functions for querying Pandoc Attrs * src/policy.rs: the get_basedir_from function; place for later policy functions * src/typeset.rs: functions to produce Pandoc AST nodes * srv/visitor/*: various MutVisitor implementations for traversing ASTs, and their helper functions
Diffstat (limited to 'src/visitor/typesetting.rs')
-rw-r--r--src/visitor/typesetting.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/visitor/typesetting.rs b/src/visitor/typesetting.rs
new file mode 100644
index 0000000..af6ea01
--- /dev/null
+++ b/src/visitor/typesetting.rs
@@ -0,0 +1,49 @@
+use crate::panhelper;
+use crate::typeset;
+use crate::Bindings;
+
+use pandoc_ast::{Block, MutVisitor};
+
+/// Visitor for the pandoc AST.
+///
+/// This includes rendering stuff which we find as we go
+pub struct TypesettingVisitor<'a> {
+ bindings: &'a Bindings,
+}
+
+impl<'a> TypesettingVisitor<'a> {
+ pub fn new(bindings: &'a Bindings) -> Self {
+ TypesettingVisitor { bindings }
+ }
+}
+
+// Visit interesting parts of the Pandoc abstract syntax tree. The
+// document top level is a vector of blocks and we visit that and
+// replace any fenced code block with the scenario tag with a typeset
+// paragraph. Also, replace fenced code blocks with known graph markup
+// with the rendered SVG image.
+impl<'a> MutVisitor for TypesettingVisitor<'a> {
+ fn visit_vec_block(&mut self, vec_block: &mut Vec<Block>) {
+ use panhelper::is_class;
+ for block in vec_block {
+ match block {
+ Block::CodeBlock(attr, s) => {
+ if is_class(attr, "scenario") {
+ *block = typeset::scenario_snippet(&self.bindings, s)
+ } else if is_class(attr, "file") {
+ *block = typeset::file_block(attr, s)
+ } else if is_class(attr, "dot") {
+ *block = typeset::dot_to_block(s)
+ } else if is_class(attr, "plantuml") {
+ *block = typeset::plantuml_to_block(s)
+ } else if is_class(attr, "roadmap") {
+ *block = typeset::roadmap_to_block(s)
+ }
+ }
+ _ => {
+ self.visit_block(block);
+ }
+ }
+ }
+ }
+}