From dbf4829b47d94efeb0827b31a087673be291aa3e Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp <19+brynary@users.noreply.github.com> Date: Mon, 15 Jun 2026 14:15:01 -0500 Subject: [PATCH] fix(graphviz): render comments with template braces (#509) ## Summary Fixes #508. This changes Graphviz render preparation so Fabro DOT is normalized before graph-level style defaults are injected. That keeps leading comments such as `// ... {{ goal }} ...` from being mistaken for the graph body opening brace, while continuing to reuse the existing parser/normalizer path for Fabro-specific syntax like dotted attribute keys. ## Verification - `cargo nextest run -p fabro-graphviz` - `cargo +nightly-2026-04-14 fmt --check --all` Co-authored-by: Chad Woolley --- lib/crates/fabro-graphviz/src/render.rs | 27 +++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/crates/fabro-graphviz/src/render.rs b/lib/crates/fabro-graphviz/src/render.rs index 7706f3aab..c10ca7989 100644 --- a/lib/crates/fabro-graphviz/src/render.rs +++ b/lib/crates/fabro-graphviz/src/render.rs @@ -21,7 +21,7 @@ const DARK_MODE_STYLE: &str = r##" } "##; -/// DOT graph-level defaults injected after the first `{`. +/// DOT graph-level defaults injected after the graph opening `{`. const DOT_STYLE_DEFAULTS: &str = r##" bgcolor="transparent" node [color="#357f9e", fontname="Helvetica", fontsize=12, fontcolor="#1a1a1a"] @@ -48,6 +48,11 @@ pub fn apply_direction<'a>(source: &'a str, direction: &str) -> std::borrow::Cow /// Inject DOT graph-level style defaults. #[must_use] pub fn inject_dot_style_defaults(source: &str) -> String { + let source = normalize_dot_for_graphviz(source); + inject_dot_style_defaults_raw(&source) +} + +fn inject_dot_style_defaults_raw(source: &str) -> String { let Some(pos) = source.find('{') else { return source.to_string(); }; @@ -259,10 +264,8 @@ impl<'a> RenderableDot<'a> { /// normalizing Fabro-specific syntax such as dotted attribute keys. #[must_use] pub fn from_fabro_source(source: &'a str) -> Self { - let styled_source = inject_dot_style_defaults(source); - let render_source = normalize_dot_for_graphviz(&styled_source).into_owned(); Self { - source: Cow::Owned(render_source), + source: Cow::Owned(inject_dot_style_defaults(source)), } } @@ -328,6 +331,22 @@ mod tests { assert!(String::from_utf8(svg).unwrap().contains(" a -> exit +}"#, + ) + .unwrap(); + + assert!(String::from_utf8(svg).unwrap().contains("