Skip to content

Render literal HTML in message text as text, not live markup - #107

Open
dchaudhari7177 wants to merge 1 commit into
simonw:mainfrom
dchaudhari7177:fix/escape-html-in-message-text
Open

Render literal HTML in message text as text, not live markup#107
dchaudhari7177 wants to merge 1 commit into
simonw:mainfrom
dchaudhari7177:fix/escape-html-in-message-text

Conversation

@dchaudhari7177

Copy link
Copy Markdown

Fixes #105.

render_markdown_text() passed message text straight through markdown.markdown(), which by design lets raw HTML through. So literal HTML in a prompt became live markup — an unclosed <style>/<head> in an instruction silently swallowed the rest of the rendered transcript (content present in the file, never displayed), and <script> would execute on open.

Following the issue's suggested fix, render_markdown_text now builds a markdown.Markdown instance and deregisters the html_block preprocessor and html inline pattern, so tags render as escaped, visible text. Deregistering (rather than escaping the input first) keeps fenced code blocks intact — fenced_code stashes their content in a preprocessor that runs before html_block, so nothing gets double-escaped.

Verified: <head>/<style> now render as &lt;head&gt;/&lt;style&gt; (no live tags); a ```html fenced block is preserved as escaped code; bold/code/lists/tables still render. Added test_render_markdown_text_escapes_literal_html and test_render_markdown_text_keeps_fenced_html; the full test suite (124 passed, existing snapshots unchanged) stays green.

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.

Raw HTML in message text is rendered as live markup, silently truncating the transcript

1 participant