Skip to content

Commit

Permalink
fix: markdown escaping for good
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Jan 20, 2025
1 parent 49cd134 commit b0d6663
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/components/chat/MarkdownRenderer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@
const marked = new Marked({
hooks: {
preprocess: (md) => escapeHTML(md),
postprocess: (html) => DOMPurify.sanitize(addInlineCitations(html, sources)),
},
extensions: [katexBlockExtension, katexInlineExtension],
renderer: {
link: (href, title, text) =>
`<a href="${href?.replace(/>$/, "")}" target="_blank" rel="noreferrer">${text}</a>`,
html: (html) => escapeHTML(html),
},
gfm: true,
});
Expand Down

2 comments on commit b0d6663

@nsarrazin
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calycekr this should hopefully fix things, sorry there's a lot of edge cases with markdown formatting, code blocks and also our own html injection for websearch sources 😅 will be adding tests to cover this in the future to avoid regressions

@calycekr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nsarrazin I agree. Markdown processing is too complicated to properly adapt to the different cases that LLM can generate. I've been trying to think of the best way to handle it, but I've given up. I think it's something we'll need to work on as new features are added in the future.

Please sign in to comment.