From 7db158701e781175ead38ca1e63f6115ce527cef Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 2 Apr 2022 12:45:18 +0300 Subject: feat: report markup problems during typesetting as a warning Sponsored-by: author --- src/error.rs | 12 ++++++++++++ src/typeset.rs | 16 ++++++++-------- src/visitor/typesetting.rs | 8 ++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/error.rs b/src/error.rs index 13d6a6c..c93141e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -361,6 +361,18 @@ pub enum Warning { /// Unknown binding when typesetting a scenario. #[error("Unknown binding: {0}")] UnknownBinding(String), + + /// Pikchr failed during typesetting. + #[error("Markup using pikchr failed: {0}")] + Pikchr(String), + + /// Dot failed during typesetting. + #[error("Markup using dot failed: {0}")] + Dot(String), + + /// Plantuml failed during typesetting. + #[error("Markup using plantuml failed: {0}")] + Plantuml(String), } /// A list of warnings. diff --git a/src/typeset.rs b/src/typeset.rs index 49b8aed..bc86ef8 100644 --- a/src/typeset.rs +++ b/src/typeset.rs @@ -154,11 +154,11 @@ pub fn link_as_note(attr: Attr, text: Vec, target: Target) -> Inline { /// /// If the code block which contained the pikchr contains other classes, they /// can be added to the SVG for use in later typesetting etc. -pub fn pikchr_to_block(pikchr: &str, class: Option<&str>) -> Block { +pub fn pikchr_to_block(pikchr: &str, class: Option<&str>, warnings: &mut Warnings) -> Block { match PikchrMarkup::new(pikchr, class).as_svg() { Ok(svg) => typeset_svg(svg), Err(err) => { - eprintln!("pikchr render failed: {}", err); + warnings.push(Warning::Pikchr(format!("{}", err))); error(err) } } @@ -167,11 +167,11 @@ pub fn pikchr_to_block(pikchr: &str, class: Option<&str>) -> Block { // Take a dot graph, render it as SVG, and return an AST Block // element. The Block will contain the SVG data. This allows the graph // to be rendered without referending external entities. -pub fn dot_to_block(dot: &str) -> Block { +pub fn dot_to_block(dot: &str, warnings: &mut Warnings) -> Block { match DotMarkup::new(dot).as_svg() { Ok(svg) => typeset_svg(svg), Err(err) => { - eprintln!("dot failed: {}", err); + warnings.push(Warning::Dot(format!("{}", err))); error(err) } } @@ -180,11 +180,11 @@ pub fn dot_to_block(dot: &str) -> Block { // Take a PlantUML graph, render it as SVG, and return an AST Block // element. The Block will contain the SVG data. This allows the graph // to be rendered without referending external entities. -pub fn plantuml_to_block(markup: &str) -> Block { +pub fn plantuml_to_block(markup: &str, warnings: &mut Warnings) -> Block { match PlantumlMarkup::new(markup).as_svg() { Ok(svg) => typeset_svg(svg), Err(err) => { - eprintln!("plantuml failed: {}", err); + warnings.push(Warning::Plantuml(format!("{}", err))); error(err) } } @@ -192,13 +192,13 @@ pub fn plantuml_to_block(markup: &str) -> Block { /// Typeset a project roadmap expressed as textual YAML, and render it /// as an SVG image. -pub fn roadmap_to_block(yaml: &str) -> Block { +pub fn roadmap_to_block(yaml: &str, warnings: &mut Warnings) -> Block { match roadmap::from_yaml(yaml) { Ok(ref mut roadmap) => { roadmap.set_missing_statuses(); let width = 50; match roadmap.format_as_dot(width) { - Ok(dot) => dot_to_block(&dot), + Ok(dot) => dot_to_block(&dot, warnings), Err(e) => Block::Para(vec![inlinestr(&e.to_string())]), } } diff --git a/src/visitor/typesetting.rs b/src/visitor/typesetting.rs index f2f435e..6f82c24 100644 --- a/src/visitor/typesetting.rs +++ b/src/visitor/typesetting.rs @@ -43,11 +43,11 @@ impl<'a> MutVisitor for TypesettingVisitor<'a> { } else if is_class(attr, "file") { *block = typeset::file_block(attr, s) } else if is_class(attr, "dot") { - *block = typeset::dot_to_block(s) + *block = typeset::dot_to_block(s, &mut self.warnings) } else if is_class(attr, "plantuml") { - *block = typeset::plantuml_to_block(s) + *block = typeset::plantuml_to_block(s, &mut self.warnings) } else if is_class(attr, "roadmap") { - *block = typeset::roadmap_to_block(s) + *block = typeset::roadmap_to_block(s, &mut self.warnings) } else if is_class(attr, "pikchr") { let other_classes: Vec<_> = attr .1 @@ -61,7 +61,7 @@ impl<'a> MutVisitor for TypesettingVisitor<'a> { Some(other_classes.join(" ")) }; let class = class.as_deref(); - *block = typeset::pikchr_to_block(s, class) + *block = typeset::pikchr_to_block(s, class, &mut self.warnings) } } _ => { -- cgit v1.2.1