File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export const marked = {
2+ parse ( markdown = '' ) {
3+ const lines = markdown . split ( '\n' ) ;
4+ let html = '' ;
5+ let inCode = false ;
6+ let codeLines = [ ] ;
7+ for ( let i = 0 ; i < lines . length ; i ++ ) {
8+ const line = lines [ i ] ;
9+ if ( line . startsWith ( '```' ) ) {
10+ if ( inCode ) {
11+ html += `<pre><code>${ escapeHtml ( codeLines . join ( '\n' ) ) } </code></pre>` ;
12+ inCode = false ;
13+ codeLines = [ ] ;
14+ } else {
15+ inCode = true ;
16+ }
17+ continue ;
18+ }
19+ if ( inCode ) {
20+ codeLines . push ( line ) ;
21+ continue ;
22+ }
23+ if ( line . trim ( ) === '---' ) {
24+ html += '<hr>' ;
25+ } else if ( line . trim ( ) ) {
26+ html += `<p>${ escapeHtml ( line . trim ( ) ) } </p>` ;
27+ }
28+ }
29+ if ( inCode ) {
30+ html += `<pre><code>${ escapeHtml ( codeLines . join ( '\n' ) ) } </code></pre>` ;
31+ }
32+ return html ;
33+ }
34+ } ;
35+
36+ function escapeHtml ( str ) {
37+ return str . replace ( / [ & < > " ' ] / g, ch => {
38+ switch ( ch ) {
39+ case '&' : return '&' ;
40+ case '<' : return '<' ;
41+ case '>' : return '>' ;
42+ case '"' : return '"' ;
43+ case "'" : return ''' ;
44+ default : return ch ;
45+ }
46+ } ) ;
47+ }
48+
Original file line number Diff line number Diff line change 11import { strict as assert } from 'node:assert' ;
2- import { marked } from 'marked' ;
2+ import { marked } from '../js/ marked.js ' ;
33import { sanitizeMarkdown } from '../js/chat/markdown-sanitizer.js' ;
44import { PolliClientWeb } from '../js/polliLib/src/client.js' ;
55import { generateImageUrl } from '../js/polliLib/src/mcp.js' ;
Original file line number Diff line number Diff line change 11import { strict as assert } from 'node:assert' ;
2- import { marked } from 'marked' ;
2+ import { marked } from '../js/ marked.js ' ;
33import { sanitizeMarkdown } from '../js/chat/markdown-sanitizer.js' ;
44
55const input = [
You can’t perform that action at this time.
0 commit comments