summaryrefslogtreecommitdiff
path: root/src/typeset.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-09-03 09:03:13 +0300
committerLars Wirzenius <liw@liw.fi>2022-09-03 09:08:20 +0300
commitba31a2ad25fa0ae3f3fd49eaa5174f9520248b90 (patch)
tree72335bc6156243c300b387a025a3a3ad96603930 /src/typeset.rs
parent404006dfb651687713b7b8aa3183ed5c2fbe8acb (diff)
downloadsubplot-ba31a2ad25fa0ae3f3fd49eaa5174f9520248b90.tar.gz
refactor: add a type for SVG images
This allows us to not use a generic byte vector, and slightly lessens the chance of mistakes. Also, it strongly encodes what we need to know about and do with SVG images. Sponsored-by: author
Diffstat (limited to 'src/typeset.rs')
-rw-r--r--src/typeset.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/typeset.rs b/src/typeset.rs
index 9522e69..f63206a 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::{DiagramMarkup, DotMarkup, PikchrMarkup, PlantumlMarkup};
+use crate::{DiagramMarkup, DotMarkup, PikchrMarkup, PlantumlMarkup, Svg};
use crate::{Warning, Warnings};
use pandoc_ast::Attr;
@@ -213,7 +213,7 @@ pub fn roadmap_to_block(yaml: &str, warnings: &mut Warnings) -> Block {
// Typeset an SVG, represented as a byte vector, as a Pandoc AST Block
// element.
-fn typeset_svg(svg: Vec<u8>) -> Block {
+fn typeset_svg(svg: Svg) -> Block {
let url = svg_as_data_url(svg);
let attr = ("".to_string(), vec![], vec![]);
let img = Inline::Image(attr, vec![], (url, "".to_string()));
@@ -223,7 +223,7 @@ fn typeset_svg(svg: Vec<u8>) -> Block {
// Convert an SVG, represented as a byte vector, into a data: URL,
// which can be inlined so the image can be rendered without
// referencing external files.
-fn svg_as_data_url(svg: Vec<u8>) -> String {
- let svg = base64::encode(&svg);
+fn svg_as_data_url(svg: Svg) -> String {
+ let svg = base64::encode(svg.data());
format!("data:image/svg+xml;base64,{}", svg)
}