Hive
fix(server): preserve docs code snippet spacing
GitHub issue · Closed
What changed
- Kept code-window
preandcodeelements inheriting the code font and preserving whitespace. - Protected only the generated code-window
<code>contents before Floki wraps tables, then restored those contents afterward. - Added a regression test covering table wrapping next to code windows.
Visual check
After: code snippets keep the spaces between let, target, =, and Target(...).
Before: syntax-highlighted spans were serialized without whitespace between adjacent tokens, so examples rendered as glued text like lettarget=Target(.
Why
Docs snippets lost spaces between highlighted tokens, making commands and Swift examples hard to read. This affected the Projects best practices page and any page with code windows processed by the table wrapper.
Root cause
The table wrapper parses rendered docs through Floki so it can wrap markdown tables. When code window contents passed through the same parser, whitespace-only text around syntax-highlighted spans could be normalized away.
Approach
Keep the table wrapping behavior, but replace code-window contents with temporary placeholders before Floki sees the markup. After tables are wrapped, restore the original code contents exactly. This avoids parsing nested code-window markup by hand and keeps the fix scoped to the text that needs verbatim preservation.
Impact
Docs code snippets keep their original spacing, including tabbed examples and single code blocks. Table wrapping behavior is unchanged.
Validation
git diff --checkelixir -e 'for path <- ["server/lib/tuist/docs/html.ex", "server/test/tuist/docs/html_test.exs"] do formatted = path |> Code.format_file!() |> IO.iodata_to_binary(); File.write!(path, formatted) end'MIX_ENV=test mix run --no-start -e 'ExUnit.start(); Code.require_file("test/tuist/docs/html_test.exs"); result = ExUnit.run(); if result.failures > 0, do: System.halt(1)', which reported3 tests, 0 failures.
No GitHub comments yet.