Skip to content

Commit f2a7d3c

Browse files
fahchenclaude
andcommitted
fix(presentation): prefix every line of multi-line colset descrs with %%
Switch from collapsing whitespace to per-line `%%` prefixing so the rendered descr keeps its original line structure. This preserves the formatting `Macro.to_string` chose (helpful for large maps) while still keeping every line inside a mermaid comment. Also extend the test to use an 8-key map (which actually triggers `Macro.to_string`'s multi-line breaking heuristic) and assert each continuation line begins with `%%`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent cec6241 commit f2a7d3c

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

lib/coloured_flow/definition/presentation/presentation.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ defmodule ColouredFlow.Definition.Presentation do
5151

5252
# `Macro.to_string` may return multi-line output for composite descrs
5353
# (maps, nested tuples). Mermaid's `%%` only comments a single line, so
54-
# trailing lines escape the comment and break the parser. Collapse
55-
# whitespace runs to a single space so the colset descr fits on one line.
54+
# trailing lines would escape the comment and break the parser. Prefix
55+
# every continuation line with `%%` so the whole descr stays commented.
5656
rendered =
5757
type
5858
|> Descr.to_quoted()
5959
|> Macro.to_string()
60-
|> String.replace(~r/\s+/u, " ")
60+
|> String.replace("\n", "\n %% ")
6161

6262
"%% colset #{compose_call(name)} :: #{rendered}"
6363
end

test/coloured_flow/definition/presentation_test.exs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,30 @@ defmodule ColouredFlow.Definition.PresentationTest do
8484
)
8585
end
8686

87-
test "collapses multi-line composite types into single-line %% comments" do
88-
# `Macro.to_string` returns multi-line output for map descrs. Mermaid's
89-
# `%%` only comments a single line, so without collapsing, the parser
90-
# bails with "Expecting NEWLINE/EOF, got NODE_STRING" on the trailing
91-
# lines that escape the comment.
87+
test "prefixes every continuation line of multi-line composite descrs with %%" do
88+
# `Macro.to_string` returns multi-line output for composite descrs.
89+
# Mermaid's `%%` only comments a single line, so every continuation
90+
# line must also start with `%%`; otherwise the parser bails with
91+
# "Expecting NEWLINE/EOF, got NODE_STRING" on the lines that escape
92+
# the comment block.
93+
# Eight keys is enough for `Macro.to_string` to break the map across
94+
# lines (heuristic kicks in past a width threshold).
9295
cpnet = %ColouredPetriNet{
9396
colour_sets: [
9497
%ColourSet{
9598
name: :user,
96-
type: {:map, %{name: {:binary, []}, age: {:integer, []}}}
99+
type:
100+
{:map,
101+
%{
102+
name: {:binary, []},
103+
age: {:integer, []},
104+
email: {:binary, []},
105+
active: {:boolean, []},
106+
role: {:binary, []},
107+
dept: {:binary, []},
108+
score: {:integer, []},
109+
country: {:binary, []}
110+
}}
97111
}
98112
],
99113
places: [%Place{name: "p", colour_set: :user}],
@@ -105,10 +119,15 @@ defmodule ColouredFlow.Definition.PresentationTest do
105119
}
106120

107121
mermaid = Presentation.to_mermaid(cpnet)
108-
[colset_line] = Regex.run(~r/%% colset .+/, mermaid)
109122

110-
assert colset_line =~ "%% colset user() ::"
111-
refute String.contains?(colset_line, "\n")
123+
colset_block =
124+
mermaid
125+
|> String.split("\n")
126+
|> Enum.drop_while(&(not String.contains?(&1, "colset user")))
127+
|> Enum.take_while(&(&1 |> String.trim() |> String.starts_with?("%%")))
128+
129+
assert length(colset_block) > 1, "expected multi-line colset output"
130+
assert Enum.all?(colset_block, &(&1 |> String.trim() |> String.starts_with?("%%")))
112131
end
113132
end
114133

0 commit comments

Comments
 (0)