1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./katex-DvMfJMDS.css","./auto-render-YkwsO5wJ.js","./katex-CnjCUzRs.js","./mermaid.core-J5-DjKr9.js","./index-CDZuCcOm.js","./index-DYz7DaJH.css","./i18n-dpAHICcw.js","./i18n-UT_CQGRO.css","./step-TZOpqHBK.js","./dispatch-tQmgj1It.js","./select-k8gDf_61.js"])))=>i.map(i=>d[i]); 2import { R as push, y as user_effect, t as template_effect, a as append, T as pop, W as from_html, w as get, a5 as user_derived, V as child, ag as __vitePreload, N as tick, Y as reset } from './index-CDZuCcOm.js'; 3import { p as prop, d as bind_this, b as set_class } from './i18n-dpAHICcw.js'; 4import { h as html } from './html-h_YSgefI.js'; 5import { A as Amuchina, c as create_marked } from './MarkdownCode.svelte_svelte_type_style_lang-GeNUGzep.js'; 6 7const is_external_url = (link, root = location.href) => { 8 try { 9 return !!link && new URL(link).origin !== new URL(root).origin; 10 } catch (e) { 11 return false; 12 } 13}; 14function sanitize(source) { 15 const amuchina = new Amuchina(); 16 const node = new DOMParser().parseFromString(source, "text/html"); 17 walk_nodes(node.body, "A", (node2) => { 18 if (node2 instanceof HTMLElement && "target" in node2) { 19 if (is_external_url(node2.getAttribute("href"), location.href)) { 20 node2.setAttribute("target", "_blank"); 21 node2.setAttribute("rel", "noopener noreferrer"); 22 } 23 } 24 }); 25 return amuchina.sanitize(node).body.innerHTML; 26} 27function walk_nodes(node, test, callback) { 28 if (node && (node.nodeName === test || typeof test === "function")) { 29 callback(node); 30 } 31 const children = node?.childNodes || []; 32 for (let i = 0; i < children.length; i++) { 33 walk_nodes(children[i], test, callback); 34 } 35} 36 37const standardHtmlTags = [ 38 "!--", 39 "!doctype", 40 "a", 41 "abbr", 42 "acronym", 43 "address", 44 "applet", 45 "area", 46 "article", 47 "aside", 48 "audio", 49 "b", 50 "base", 51 "basefont", 52 "bdi", 53 "bdo", 54 "big", 55 "blockquote", 56 "body", 57 "br", 58 "button", 59 "canvas", 60 "caption", 61 "center", 62 "cite", 63 "code", 64 "col", 65 "colgroup", 66 "data", 67 "datalist", 68 "dd", 69 "del", 70 "details", 71 "dfn", 72 "dialog", 73 "dir", 74 "div", 75 "dl", 76 "dt", 77 "em", 78 "embed", 79 "fieldset", 80 "figcaption", 81 "figure", 82 "font", 83 "footer", 84 "form", 85 "frame", 86 "frameset", 87 "h1", 88 "h2", 89 "h3", 90 "h4", 91 "h5", 92 "h6", 93 "head", 94 "header", 95 "hgroup", 96 "hr", 97 "html", 98 "i", 99 "iframe", 100 "img", 101 "input", 102 "ins", 103 "kbd", 104 "label", 105 "legend", 106 "li", 107 "link", 108 "main", 109 "map", 110 "mark", 111 "menu", 112 "meta", 113 "meter", 114 "nav", 115 "noframes", 116 "noscript", 117 "object", 118 "ol", 119 "optgroup", 120 "option", 121 "output", 122 "p", 123 "param", 124 "picture", 125 "pre", 126 "progress", 127 "q", 128 "rp", 129 "rt", 130 "ruby", 131 "s", 132 "samp", 133 "script", 134 "search", 135 "section", 136 "select", 137 "small", 138 "source", 139 "span", 140 "strike", 141 "strong", 142 "style", 143 "sub", 144 "summary", 145 "sup", 146 "svg", 147 "table", 148 "tbody", 149 "td", 150 "template", 151 "textarea", 152 "tfoot", 153 "th", 154 "thead", 155 "time", 156 "title", 157 "tr", 158 "track", 159 "tt", 160 "u", 161 "ul", 162 "var", 163 "video", 164 "wbr" 165]; 166const svgTags = [ 167 // Base structural elements 168 "g", 169 "defs", 170 "use", 171 "symbol", 172 // Shape elements 173 "rect", 174 "circle", 175 "ellipse", 176 "line", 177 "polyline", 178 "polygon", 179 "path", 180 "image", 181 // Text elements 182 "text", 183 "tspan", 184 "textPath", 185 // Gradient and effects 186 "linearGradient", 187 "radialGradient", 188 "stop", 189 "pattern", 190 "clipPath", 191 "mask", 192 "filter", 193 // Filter effects 194 "feBlend", 195 "feColorMatrix", 196 "feComponentTransfer", 197 "feComposite", 198 "feConvolveMatrix", 199 "feDiffuseLighting", 200 "feDisplacementMap", 201 "feGaussianBlur", 202 "feMerge", 203 "feMorphology", 204 "feOffset", 205 "feSpecularLighting", 206 "feTurbulence", 207 "feMergeNode", 208 "feFuncR", 209 "feFuncG", 210 "feFuncB", 211 "feFuncA", 212 "feDistantLight", 213 "fePointLight", 214 "feSpotLight", 215 "feFlood", 216 "feTile", 217 // Animation elements 218 "animate", 219 "animateTransform", 220 "animateMotion", 221 "mpath", 222 "set", 223 // Interactive and other elements 224 "view", 225 "cursor", 226 "foreignObject", 227 "desc", 228 "title", 229 "metadata", 230 "switch" 231]; 232const standardHtmlAndSvgTags = [ 233 ...standardHtmlTags, 234 ...svgTags.filter((tag) => !standardHtmlTags.includes(tag)) 235]; 236 237var root = from_html(`<span><!></span>`); 238 239function MarkdownCode($$anchor, $$props) { 240 push($$props, true); 241 242 let chatbot = prop($$props, 'chatbot', 3, true), 243 sanitize_html = prop($$props, 'sanitize_html', 3, true), 244 latex_delimiters = prop($$props, 'latex_delimiters', 19, () => []), 245 render_markdown = prop($$props, 'render_markdown', 3, true), 246 line_breaks = prop($$props, 'line_breaks', 3, true), 247 header_links = prop($$props, 'header_links', 3, false), 248 allow_tags = prop($$props, 'allow_tags', 3, false), 249 theme_mode = prop($$props, 'theme_mode', 3, "system"); 250 251 let el; 252 253 const marked = create_marked({ 254 header_links: header_links(), 255 line_breaks: line_breaks(), 256 latex_delimiters: latex_delimiters() || [] 257 }); 258 259 let html$1 = user_derived(() => { 260 if ($$props.message && $$props.message.trim()) { 261 return process_message($$props.message); 262 } else { 263 return ""; 264 } 265 }); 266 267 let katex_loaded = false;
268 269 function has_math_syntax(text) { 270 if (!latex_delimiters() || latex_delimiters().length === 0) { 271 return false; 272 } 273 274 return latex_delimiters().some((delimiter) => text.includes(delimiter.left) && text.includes(delimiter.right)); 275 } 276 277 function escapeRegExp(string) { 278 return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); 279 } 280 281 function escapeTags(content, tagsToEscape) { 282 if (tagsToEscape === true) { 283 // https://www.w3schools.com/tags/ 284 const tagRegex = /<\/?([a-zA-Z][a-zA-Z0-9-]*)([\s>])/g; 285 286 return content.replace(tagRegex, (match, tagName, endChar) => { 287 if (!standardHtmlAndSvgTags.includes(tagName.toLowerCase())) { 288 return match.replace(/</g, "<").replace(/>/g, ">"); 289 } 290 291 return match; 292 }); 293 } 294 295 if (Array.isArray(tagsToEscape)) { 296 const tagPattern = tagsToEscape.map((tag) => ({ 297 open: new RegExp(`<(${tag})(\\s+[^>]*)?>`, "gi"), 298 close: new RegExp(`</(${tag})>`, "gi") 299 })); 300 301 let result = content; 302 303 tagPattern.forEach((pattern) => { 304 result = result.replace(pattern.open, (match) => match.replace(/</g, "<").replace(/>/g, ">")); 305 result = result.replace(pattern.close, (match) => match.replace(/</g, "<").replace(/>/g, ">")); 306 }); 307 308 return result; 309 } 310 311 return content; 312 } 313 314 function process_message(value) { 315 let parsedValue = value; 316 317 if (render_markdown()) { 318 const latexBlocks = []; 319 320 latex_delimiters().forEach((delimiter, index) => { 321 const leftDelimiter = escapeRegExp(delimiter.left); 322 const rightDelimiter = escapeRegExp(delimiter.right); 323 const regex = new RegExp(`${leftDelimiter}([\\s\\S]+?)${rightDelimiter}`, "g"); 324 325 parsedValue = parsedValue.replace(regex, (match, p1) => { 326 latexBlocks.push(match); 327 328 return `%%%LATEX_BLOCK_${latexBlocks.length - 1}%%%`; 329 }); 330 }); 331 332 parsedValue = marked.parse(parsedValue); 333 parsedValue = parsedValue.replace(/%%%LATEX_BLOCK_(\d+)%%%/g, (match, p1) => latexBlocks[parseInt(p1, 10)]); 334 } 335 336 if (allow_tags()) { 337 parsedValue = escapeTags(parsedValue, allow_tags()); 338 } 339 340 if (sanitize_html() && sanitize) { 341 parsedValue = sanitize(parsedValue); 342 } 343 344 return parsedValue; 345 } 346 347 async function render_html(value) { 348 if (latex_delimiters().length > 0 && value && has_math_syntax(value)) { 349 if (!katex_loaded) { 350 await Promise.all([ 351 __vitePreload(() => Promise.resolve({}),true ?__vite__mapDeps([0]):void 0,import.meta.url), 352 __vitePreload(() => import('./auto-render-YkwsO5wJ.js'),true ?__vite__mapDeps([1,2]):void 0,import.meta.url) 353 ]).then(([, { default: render_math_in_element }]) => { 354 katex_loaded = true; 355 render_math_in_element(el, { delimiters: latex_delimiters(), throwOnError: false }); 356 }); 357 } else { 358 const { default: render_math_in_element } = await __vitePreload(async () => { const { default: render_math_in_element } = await import('./auto-render-YkwsO5wJ.js');return { default: render_math_in_element }},true ?__vite__mapDeps([1,2]):void 0,import.meta.url); 359 360 render_math_in_element(el, { delimiters: latex_delimiters(), throwOnError: false }); 361 } 362 } 363 364 if (el) { 365 const mermaidDivs = el.querySelectorAll(".mermaid"); 366 367 if (mermaidDivs.length > 0) { 368 await tick(); 369 370 const { default: mermaid } = await __vitePreload(async () => { const { default: mermaid } = await import('./mermaid.core-J5-DjKr9.js').then(n => n.b5);return { default: mermaid }},true ?__vite__mapDeps([3,4,5,6,7,8,9,10]):void 0,import.meta.url); 371 372 mermaid.initialize({ 373 startOnLoad: false, 374 theme: theme_mode() === "dark" ? "dark" : "default", 375 securityLevel: "antiscript" 376 }); 377 378 await mermaid.run({ nodes: Array.from(mermaidDivs).map((node) => node) }); 379 } 380 } 381 } 382 383 user_effect(() => { 384 if (el && document.body.contains(el)) { 385 render_html($$props.message); 386 } else { 387 console.error("Element is not in the DOM"); 388 } 389 }); 390 391 var span = root(); 392 let classes; 393 var node_1 = child(span); 394 395 html(node_1, () => get(html$1)); 396 reset(span); 397 bind_this(span, ($$value) => el = $$value, () => el); 398 template_effect(() => classes = set_class(span, 1, 'md svelte-1hf8a14', null, classes, { chatbot: chatbot(), prose: render_markdown() })); 399 append($$anchor, span); 400 pop(); 401} 402 403export { MarkdownCode as M };
404//# sourceMappingURL=MarkdownCode-Q694H4-C.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.