Skip to main content

Crate chordsketch_render_html

Crate chordsketch_render_html 

Source
Expand description

HTML renderer for ChordPro documents.

Converts a parsed ChordPro AST into either a self-contained HTML5 document (with embedded CSS) or a body-only <div class="song"> fragment suitable for embedding in a host document. Use render_song / render_songs for the full-document API and render_song_body / render_songs_body for the fragment API. Pair the latter with render_html_css to obtain the matching stylesheet.

§Security

Delegate section environments ({start_of_svg}, {start_of_abc}, {start_of_ly}, {start_of_textblock}) emit their content as raw, unescaped HTML. This is by design per the ChordPro specification, as these sections contain verbatim markup (e.g., inline SVG).

SVG sections are sanitized by default: <script> elements and event handler attributes (onload, onerror, etc.) are stripped to prevent XSS. When rendering untrusted ChordPro input, consumers should still apply Content Security Policy (CSP) headers as additional defense.

Constants§

MAX_WARNINGS
Maximum number of warnings the renderer accumulates per render pass. Re-exported from chordsketch-chordpro::render_result so callers can keep importing chordsketch_render_html::MAX_WARNINGS unchanged (issue #1874). Maximum number of warnings any renderer accumulates for a single render pass (issue #1833). Without a cap, a pathological input such as one million malformed {transpose} lines would push the warnings vector to tens of megabytes. push_warning refuses to exceed this limit and appends a single truncation marker the first time the cap is hit.

Functions§

render
Parse a ChordPro source string and render it to HTML.
render_html_css
The canonical chord-over-lyrics CSS that the full-document renderers embed inside <style>.
render_html_css_with_config
Variant of render_html_css that honours settings.wraplines from the supplied config (R6.100.0). When wraplines is false, the .line rule emits flex-wrap: nowrap so chord/lyric runs that exceed the viewport width preserve the source line structure instead of reflowing.
render_song
Render a Song AST to an HTML5 document string.
render_song_body
Render a Song AST to its body-only HTML fragment.
render_song_body_with_transpose
Render a Song AST to its body-only HTML fragment with a CLI transposition offset.
render_song_body_with_warnings
Render a Song AST to its body-only HTML fragment, returning warnings programmatically.
render_song_with_transpose
Render a Song AST to an HTML5 document with an additional CLI transposition offset.
render_song_with_warnings
Render a Song AST to an HTML5 document, returning warnings programmatically.
render_songs
Render multiple Songs into a single HTML5 document.
render_songs_body
Render multiple Songs into a single body-only HTML fragment.
render_songs_body_with_transpose
Render multiple Songs into a single body-only HTML fragment with transposition.
render_songs_body_with_warnings
Render multiple Songs into a single body-only HTML fragment, returning warnings programmatically.
render_songs_with_transpose
Render multiple Songs into a single HTML5 document with transposition.
render_songs_with_warnings
Render multiple Songs into a single HTML5 document, returning warnings programmatically.
try_render
Parse a ChordPro source string and render it to HTML.