diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-17 08:43:02 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-17 08:45:11 +0200 |
commit | 034140273c9c2c310c8231991819a9a5107ba27a (patch) | |
tree | eabd4ee06504dc8be8d2a2c186195a0ef6ac88d9 | |
parent | 55dd0dcdf1432bbca35cbfc3be63f88d1fa0b0e6 (diff) | |
download | subplot-034140273c9c2c310c8231991819a9a5107ba27a.tar.gz |
refactor: make Style have methods for querying, setting fields
This seems clearer to me, and as a side effect silences a warning
about changing a field outside the constructor, for a struct that
implements the Default traig.
-rw-r--r-- | src/bin/sp-docgen.rs | 4 | ||||
-rw-r--r-- | src/style.rs | 16 | ||||
-rw-r--r-- | src/visitor/typesetting.rs | 2 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/bin/sp-docgen.rs b/src/bin/sp-docgen.rs index 113defc..61522ce 100644 --- a/src/bin/sp-docgen.rs +++ b/src/bin/sp-docgen.rs @@ -38,7 +38,9 @@ fn main() -> Result<()> { let first_file = &opt.filenames[0]; let mut style = Style::default(); - style.links_as_notes = opt.output.extension() == Some(&OsString::from("pdf")); + if opt.output.extension() == Some(&OsString::from("pdf")) { + style.typeset_links_as_notes(); + } let basedir = get_basedir_from(first_file)?; let mut doc = Document::from_file(&basedir, &first_file, style)?; diff --git a/src/style.rs b/src/style.rs index de8adab..95f1109 100644 --- a/src/style.rs +++ b/src/style.rs @@ -4,10 +4,24 @@ /// syntax tree is modified during typesetting. #[derive(Clone, Debug, Default)] pub struct Style { + links_as_notes: bool, +} + +impl Style { /// Should hyperlinks in the document be rendered as footnotes or endnotes? /// /// A link is like the HTML `<a>` element. The choice of footnote /// versus endnote is made by the typesetting backend. HTML uses /// endnotes, PDF uses footnotes. - pub links_as_notes: bool, + pub fn links_as_notes(&self) -> bool { + self.links_as_notes + } + + /// Make links be typeset as notes. + /// + /// Default is that they are typeset as links. This can't be + /// unset. + pub fn typeset_links_as_notes(&mut self) { + self.links_as_notes = true + } } diff --git a/src/visitor/typesetting.rs b/src/visitor/typesetting.rs index f59f81d..e98d66a 100644 --- a/src/visitor/typesetting.rs +++ b/src/visitor/typesetting.rs @@ -64,7 +64,7 @@ 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::Link(attr, vec, target) if self.style.links_as_notes() => { *inline = typeset::link_as_note(attr.clone(), vec.to_vec(), target.clone()); } _ => { |