diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-07-03 10:11:31 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-07-03 10:13:06 +0300 |
commit | 867fe49385d89177bf84af40cee3663b23a7aefc (patch) | |
tree | 8bc459d81facdf84016f34ce18826d0a287381b9 /subplot | |
parent | 5aa0019667e2ac64036ffb828dfd46f66a714fdf (diff) | |
download | riki-867fe49385d89177bf84af40cee3663b23a7aefc.tar.gz |
test: handle inline image elements in markdown markup
Sponsored-by: author
Diffstat (limited to 'subplot')
-rw-r--r-- | subplot/rikiwiki.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/subplot/rikiwiki.rs b/subplot/rikiwiki.rs index ac53df9..f6aea97 100644 --- a/subplot/rikiwiki.rs +++ b/subplot/rikiwiki.rs @@ -1,4 +1,4 @@ -use pandoc_ast::Pandoc; +use pandoc_ast::{Inline, MutVisitor, Pandoc}; use std::path::Path; use subplotlib::steplibrary::runcmd::Runcmd; use subplotlib::steplibrary::datadir::Datadir; @@ -59,6 +59,23 @@ fn ast<P: AsRef<Path>>(filename: P) -> Pandoc { pandoc::PandocOutput::ToBuffer(x) => x, pandoc::PandocOutput::ToBufferRaw(x) => panic!("to raw buffer: {:?}", x), }; - let json = serde_json::from_str(&json).unwrap(); + let mut json = serde_json::from_str(&json).unwrap(); + let mut fix = DropImageFigTitle {}; + fix.walk_pandoc(&mut json); json } + +// For some reason, Pandoc adds to an Inline::Image element a spurious +// "fig:" as the second half of the 'target' tuple, when parsing +// Markdown, but when parsing HTML. This makes tests fail. Avoid that. +struct DropImageFigTitle {} + +impl MutVisitor for DropImageFigTitle { + fn visit_inline(&mut self, inline: &mut Inline) { + if let Inline::Image(attr, alt, target) = inline { + if target.1 == "fig:" { + *inline = Inline::Image(attr.clone(), alt.to_vec(), (target.0.clone(), "".into())); + } + } + } +} |