nsarrazin HF Staff commited on
Commit
b157e67
·
1 Parent(s): bbf8562

feat: better markdown rendering

Browse files
src/lib/components/chat/MarkdownRenderer.svelte CHANGED
@@ -48,7 +48,20 @@
48
  renderer,
49
  };
50
 
51
- $: tokens = marked.lexer(addInlineCitations(content, sources));
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  function processLatex(parsed: string) {
54
  const delimiters = [
 
48
  renderer,
49
  };
50
 
51
+ function escapeHTML(content: string) {
52
+ return content.replace(
53
+ /[<>&\n]/g,
54
+ (x) =>
55
+ ({
56
+ "<": "&lt;",
57
+ ">": "&gt;",
58
+ "&": "&amp;",
59
+ "\n": "<br />",
60
+ }[x] || x)
61
+ );
62
+ }
63
+
64
+ $: tokens = marked.lexer(addInlineCitations(escapeHTML(content), sources));
65
 
66
  function processLatex(parsed: string) {
67
  const delimiters = [