Skip to content

refactor(render): Modularize SVG and HTML renderers and improve CJK label width estimation#47

Merged
mhiro2 merged 4 commits into
mainfrom
fix/render-svg-html-improvements
Apr 10, 2026
Merged

refactor(render): Modularize SVG and HTML renderers and improve CJK label width estimation#47
mhiro2 merged 4 commits into
mainfrom
fix/render-svg-html-improvements

Conversation

@mhiro2

@mhiro2 mhiro2 commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace the ASCII/non-ASCII heuristic in SVG label width estimation with unicode-width for
    correct CJK and emoji rendering
  • Add regression tests verifying HTML escaping of special characters in title and heading
    elements
  • Split relune-render-svg lib.rs into node.rs and markers.rs to reduce file size and
    improve maintainability
  • Split relune-render-html html.rs into css.rs and components.rs to separate concerns

Changes

  • 3fb4475 fix(render-svg): use unicode-width for label estimation and avoid format!() in column
    loop
    • Replace the binary ASCII/non-ASCII heuristic in estimate_label_width with unicode-width's
      width_cjk() for correct widths of CJK, emoji, and other multi-cell characters
    • Eliminate per-column String allocation in the column rendering loop by writing directly
      into the output buffer with write!() instead of building an intermediate String via
      format!()
  • b6c60c3 test(render-html): add regression test for title/heading escape of special characters
    • Verify that user-supplied titles containing HTML injection payloads, ampersands, quotes, and
      apostrophes are properly escaped in both the <title> and <h1> elements
  • a647777 refactor(render-svg): split lib.rs into node.rs and markers.rs
    • Extract node rendering, column badges, label estimation, and overlay badge helpers into
      node.rs
    • Extract Crow's Foot inline marker rendering and sampling helpers into markers.rs
    • lib.rs shrinks from ~2500 to ~1900 lines, retaining the public API, defs, edge rendering,
      and tests
  • 18f24fa refactor(render-html): split html.rs into css.rs and components.rs
    • Extract the ~1460-line build_css function into css.rs and the HTML/JS component builders
      into components.rs
    • html.rs shrinks from ~2400 to ~700 lines, retaining the document assembly logic and tests

mhiro2 added 4 commits April 11, 2026 05:56
…mat!() in column loop

- Replace the ASCII/non-ASCII binary heuristic in estimate_label_width
  with unicode-width's width_cjk(), giving correct widths for CJK,
  emoji, and other multi-cell characters.
- Eliminate per-column String allocation in the column rendering loop
  by writing directly into the output buffer with write!() instead
  of building an intermediate String via format!().
…ecial characters

Verify that user-supplied titles containing HTML injection payloads,
ampersands, quotes, and apostrophes are properly escaped in both the
<title> and <h1> elements of the generated HTML document.
Extract node rendering, column badges, label estimation, and overlay
badge helpers into node.rs. Extract Crow's Foot inline marker rendering
and sampling helpers into markers.rs. lib.rs shrinks from ~2500 to
~1900 lines and retains the public API, defs, edge rendering, and tests.
Extract the ~1460-line build_css function into css.rs and the HTML/JS
component builders into components.rs. html.rs shrinks from ~2400 to
~700 lines and retains the document assembly logic and tests.
@mhiro2 mhiro2 self-assigned this Apr 10, 2026
@mhiro2 mhiro2 added bug Something isn't working refactor labels Apr 10, 2026
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (c1721cb) #47 (3baaae4) +/-
Coverage 94.1% 94.1% -0.1%
Test Execution Time 1m35s 1m39s +4s
Details
  |                     | main (c1721cb) | #47 (3baaae4) |  +/-  |
  |---------------------|----------------|---------------|-------|
- | Coverage            |          94.1% |         94.1% | -0.1% |
  |   Files             |             73 |            77 |    +4 |
  |   Lines             |          29862 |         29895 |   +33 |
+ |   Covered           |          28117 |         28148 |   +31 |
- | Test Execution Time |          1m35s |         1m39s |   +4s |

Code coverage of files in pull request scope (98.2% → 98.2%)

Files Coverage +/- Status
crates/relune-render-html/src/components.rs 100.0% +100.0% added
crates/relune-render-html/src/css.rs 100.0% +100.0% added
crates/relune-render-html/src/html.rs 99.7% -0.2% modified
crates/relune-render-html/src/lib.rs 100.0% 0.0% modified
crates/relune-render-svg/src/lib.rs 97.9% +1.7% modified
crates/relune-render-svg/src/markers.rs 84.5% +84.5% added
crates/relune-render-svg/src/node.rs 91.4% +91.4% added

Reported by octocov

@mhiro2
mhiro2 merged commit a9d8da7 into main Apr 10, 2026
3 checks passed
@mhiro2
mhiro2 deleted the fix/render-svg-html-improvements branch April 10, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant