Skip to content

fix(render): escape speaker notes for JS and HTML-attribute contexts#3

Open
ntheanh201 wants to merge 1 commit into
slidr-cli:masterfrom
ntheanh201:fix/escape-slide-notes
Open

fix(render): escape speaker notes for JS and HTML-attribute contexts#3
ntheanh201 wants to merge 1 commit into
slidr-cli:masterfrom
ntheanh201:fix/escape-slide-notes

Conversation

@ntheanh201

Copy link
Copy Markdown
Contributor

Problem

Slide notes (<!-- ... --> comments) are emitted into two different contexts, each without the correct escaping:

  • slidr.js builds a JS string array with "{{ slide.notes|e }}". The |e filter HTML-escapes but does not JS-escape. A multi-line note therefore places a raw newline inside a JS string literal — a syntax error that breaks the entire script. Navigation stops working and the deck renders as a blank page.
  • shell.html writes data-notes="{{ slide.notes }}" with no escaping at all, so a " inside a note truncates the attribute (the presenter view then shows a cut-off note).

Single-line, quote-free notes happen to work, which is why this stays hidden until someone writes a richer note.

Fix

File Before After Why
slidr.js "{{ slide.notes|e }}" {{ slide.notes|tojson }} JSON string literal — escapes newlines/quotes/backslashes and supplies its own quotes
shell.html data-notes="{{ slide.notes }}" data-notes="{{ slide.notes|e }}" HTML-attribute escaping for embedded quotes

Test

Adds test_slide_notes_are_js_and_attribute_safe, which renders a slide with a multi-line, quote-containing note and asserts the JS array is JSON-encoded (newline escaped, no raw newline in the literal) and the data-notes attribute escapes the quote. All 3 tests in test_html.py pass.

Signed-off-by via DCO.

ntheanh201 added a commit to ntheanh201/talks that referenced this pull request Jul 24, 2026
Add condensed teleprompter notes (time cue, key numbers, the land line,
stage directions) as HTML comments on each Part 3 slide - shown in the
presenter view, hidden from the audience.

Bump slidr to the notes-escaping fix (slidr-cli/slidr#3) so multi-line
notes render instead of blanking the deck.

Signed-off-by: The Anh Nguyen <ntheanh201@gmail.com>
Slide notes are emitted into two contexts without correct escaping:

- slidr.js builds a JS string array with `{{ slide.notes|e }}`, which
  HTML-escapes but does not JS-escape. A multi-line note then places a
  raw newline inside a JS string literal - a syntax error that breaks
  the whole script, so navigation dies and the deck renders blank.
- shell.html writes `data-notes="{{ slide.notes }}"` with no escaping,
  so a double-quote in a note truncates the attribute.

Use `|tojson` for the JS array (a proper JSON string literal - newlines,
quotes and backslashes escaped, surrounding quotes included) and `|e`
for the HTML attribute. Add a test covering both contexts with a
multi-line, quote-containing note.

Signed-off-by: The Anh Nguyen <ntheanh201@gmail.com>
@ntheanh201
ntheanh201 force-pushed the fix/escape-slide-notes branch from 7f42054 to e13e0e9 Compare July 24, 2026 10:52
ntheanh201 added a commit to ntheanh201/talks that referenced this pull request Jul 24, 2026
slidr-cli master had advanced to the --dist flag while the notes-escape
fix branched from an older commit. Rebased the fix onto current master
so the submodule carries both, making the bump a clean forward move
(slidr-cli/slidr#3).

Signed-off-by: The Anh Nguyen <ntheanh201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant