diff options
Diffstat (limited to 'src/typeset.rs')
-rw-r--r-- | src/typeset.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/typeset.rs b/src/typeset.rs index c6301e4..bc86ef8 100644 --- a/src/typeset.rs +++ b/src/typeset.rs @@ -5,6 +5,7 @@ use crate::ScenarioStep; use crate::StepKind; use crate::SubplotError; use crate::{DotMarkup, GraphMarkup, PikchrMarkup, PlantumlMarkup}; +use crate::{Warning, Warnings}; use pandoc_ast::Attr; use pandoc_ast::Block; @@ -53,13 +54,13 @@ pub fn file_block(attr: &Attr, text: &str) -> Block { /// /// The snippet is given as a text string, which is parsed. It need /// not be a complete scenario, but it should consist of complete steps. -pub fn scenario_snippet(bindings: &Bindings, snippet: &str) -> Block { +pub fn scenario_snippet(bindings: &Bindings, snippet: &str, warnings: &mut Warnings) -> Block { let lines = parse_scenario_snippet(snippet); let mut steps = vec![]; let mut prevkind: Option<StepKind> = None; for line in lines { - let (this, thiskind) = step(bindings, line, prevkind); + let (this, thiskind) = step(bindings, line, prevkind, warnings); steps.push(this); prevkind = thiskind; } @@ -71,6 +72,7 @@ fn step( bindings: &Bindings, text: &str, prevkind: Option<StepKind>, + warnings: &mut Warnings, ) -> (Vec<Inline>, Option<StepKind>) { let step = ScenarioStep::new_from_str(text, prevkind); if step.is_err() { @@ -84,11 +86,9 @@ fn step( let m = match bindings.find("", &step) { Ok(m) => m, Err(e) => { - eprintln!("Could not select binding: {:?}", e); - return ( - error_msg(&format!("Could not select binding for: {}", text)), - prevkind, - ); + let w = Warning::UnknownBinding(format!("{}", e)); + warnings.push(w.clone()); + return (error_msg(&format!("{}", w)), prevkind); } }; @@ -154,11 +154,11 @@ pub fn link_as_note(attr: Attr, text: Vec<Inline>, 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())]), } } |