Skip to content

Commit 14d73da

Browse files
committed
site(gordon): escape HTML in markdown text to preserve angle brackets
Configure marked.js to escape HTML entities in text tokens while preserving code blocks. This allows angle brackets like <target-name> to display correctly in regular text without being interpreted as HTML tags, while keeping code examples intact. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent eb4bb34 commit 14d73da

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

assets/js/src/alpine.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ hljs.registerLanguage('py', python)
3535
hljs.registerLanguage('go', go)
3636
hljs.registerLanguage('golang', go)
3737

38+
// Configure marked to escape HTML in text tokens only (not code blocks)
39+
marked.use({
40+
walkTokens(token) {
41+
// Escape HTML in text and HTML tokens, preserve code blocks
42+
if (token.type === 'text' || token.type === 'html') {
43+
const text = token.text || token.raw
44+
const escaped = text
45+
.replace(/&/g, '&amp;')
46+
.replace(/</g, '&lt;')
47+
.replace(/>/g, '&gt;')
48+
if (token.text) token.text = escaped
49+
if (token.raw) token.raw = escaped
50+
}
51+
}
52+
})
53+
3854
// Add $markdown magic for rendering markdown with syntax highlighting
3955
Alpine.magic('markdown', () => {
4056
return (content) => {

0 commit comments

Comments
 (0)