Module: JekyllMermaidPrebuild::SvgPostProcessor
- Defined in:
- lib/jekyll-mermaid-prebuild/svg_post_processor.rb
Overview
Post-processes mmdc-generated SVGs to fix rendering issues.
Four independent fixes:
- Text centering: Mermaid's CSS
text-align: centertargets SVG<g>elements where it has no effect on HTML inside<foreignObject>. We inject a CSS rule so that foreignObject content centers correctly regardless of text measurement differences between the generating and viewing browsers. Always applied, idempotent. - Overflow protection: foreignObject defaults to overflow:hidden, which silently clips labels when the viewing browser renders text wider than the generating Chromium measured. We inject a CSS rule setting overflow:visible on all foreignObjects. Always applied, idempotent.
- Edge label padding: Widens edge-label
<foreignObject>widths in any diagram type to prevent clipping when the viewing browser renders text wider than headless Chromium measured. Opt-in viapostprocessing.edge_label_paddingconfig. - Root SVG background: mmdc always emits
background-color: whiteon the root<svg>regardless of theme. The plugin replaces that token with configurable CSS color values for light and dark variants (defaults white / black) so charts match page background in both modes.
Constant Summary collapse
- EDGE_LABEL_FOREIGN_OBJECT_RE =
Opening sequence produced by mmdc for block edge labels (deterministic minified output).
/ (<g\sclass="edgeLabel"[^>]*><g\sclass="label"[^>]*><foreignObject) (\s[^>]+) (>) /x- OVERFLOW_RULE =
"foreignObject{overflow:visible;}"- CENTERING_RULE =
"foreignObject > div{display:block !important;text-align:center;}"
Class Method Summary collapse
-
.apply(svg_string, padding:) ⇒ String
Possibly widened SVG, or the original string on no-op / error.
-
.apply_root_svg_background(svg_string, css_background) ⇒ String
Replace
background-color: whiteon the root -
.ensure_foreignobject_overflow(svg_string) ⇒ String
Injects a CSS rule into the SVG