summaryrefslogtreecommitdiff
path: root/src/visitor/typesetting.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-08-31 09:59:04 +0300
committerLars Wirzenius <liw@liw.fi>2020-09-01 09:24:59 +0300
commite265cfdc9f6afef7f969283df7f63148d91b857f (patch)
tree973041ff38944c41f10276f36dd9f197e78d7dc3 /src/visitor/typesetting.rs
parentb384358ac0ddcf6e8baae1c280f4d7d9930754ad (diff)
downloadsubplot-e265cfdc9f6afef7f969283df7f63148d91b857f.tar.gz
feat(docgen): typeset links as footnotes in PDF
When reading a PDF printed on paper or on a reMarkable tablet, it's not possible to see that there even is a link in a PDF. Make this more visible by typesetting the link URL as a footnote. This is not done on HTML output as web pages are read on browsers that make links easy to see. This is the first time the AST is transformed by docgen differently based on the output format. The decision of what should be done is a policy decision, best done at the topmost level: in the main function of docgen. The result of that decidion (turn links into footnotes or not) is communicated from docgen main into the ast.rs module via a new Style struct. This mechanism can later be extended for other typesetting style decisions (e.g., what fonts to use).
Diffstat (limited to 'src/visitor/typesetting.rs')
-rw-r--r--src/visitor/typesetting.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/visitor/typesetting.rs b/src/visitor/typesetting.rs
index af6ea01..deffcd9 100644
--- a/src/visitor/typesetting.rs
+++ b/src/visitor/typesetting.rs
@@ -1,19 +1,20 @@
use crate::panhelper;
use crate::typeset;
-use crate::Bindings;
+use crate::{Bindings, Style};
-use pandoc_ast::{Block, MutVisitor};
+use pandoc_ast::{Block, Inline, MutVisitor};
/// Visitor for the pandoc AST.
///
/// This includes rendering stuff which we find as we go
pub struct TypesettingVisitor<'a> {
+ style: Style,
bindings: &'a Bindings,
}
impl<'a> TypesettingVisitor<'a> {
- pub fn new(bindings: &'a Bindings) -> Self {
- TypesettingVisitor { bindings }
+ pub fn new(style: Style, bindings: &'a Bindings) -> Self {
+ TypesettingVisitor { style, bindings }
}
}
@@ -46,4 +47,16 @@ impl<'a> MutVisitor for TypesettingVisitor<'a> {
}
}
}
+ fn visit_vec_inline(&mut self, vec_inline: &mut Vec<Inline>) {
+ for inline in vec_inline {
+ match inline {
+ Inline::Link(attr, vec, target) if self.style.links_as_notes => {
+ *inline = typeset::link_as_note(attr.clone(), vec.to_vec(), target.clone());
+ }
+ _ => {
+ self.visit_inline(inline);
+ }
+ }
+ }
+ }
}