import{a as e,i as t,n,o as r}from"./Bcb1m8Xc2.js";var i=/^<\/?(?:p|div|h[1-6]|li|ul|ol|blockquote|br|hr|pre|table|thead|tbody|tr|td|th|figure|figcaption|section|article|header|footer|main|aside)\b/i,a=/[\p{Emoji_Presentation}\p{Extended_Pictographic}]\uFE0F?/gu,o=/^\|[\s:|-]+\|$/,s=/^[ ]{0,3}([-*_])\s*(\1\s*){2,}$/,c=/<!--\s*followups:\s*\[.*?\]\s*-->\s*$/s,l=t;function u(e){let r=!1,a=``;return e.replace(/(<[^>]+>)|([^<]+)/g,(e,o,s)=>{if(o)return/<code/i.test(o)&&(r=!0),/<\/code/i.test(o)&&(r=!1),i.test(o)&&(a=``),o;if(!s)return s??``;if(r)return a=s[s.length-1]??a,s;let c=s.replace(/&quot;/g,`"`).replace(/&#39;/g,`'`),l=t(c,a);return a=c[c.length-1]??a,n(l)})}function d(e,t){let n=e.replace(c,``);return t?.streaming&&(n=n.replace(/<!--(?:(?!-->)[\s\S])*$/,``).replace(/<!-{0,2}$/,``)),n.trimEnd().replace(a,``).replace(/^ {2,}/gm,(e,t,n)=>{let r=n.slice(t+e.length);return/^([-*+]|\d+[.)])\s/.test(r)?e:` `}).split(`
`).map(e=>o.test(e)||s.test(e)?e:e.replace(/--/g,`—`)).join(`
`)}function f(e){return e.replace(/<a\s+href="([^"]*)"/gi,(e,t)=>/^(https?:)?\/\//i.test(t)||/^(mailto|tel):/i.test(t)?`<a href="${t}" target="_blank" rel="noopener noreferrer"`:e)}function p(e){return e.replace(/<a\s+([^>]*)>([\s\S]*?)<\/a>/gi,(e,t,n)=>{let r=/href="([^"]*)"/i.exec(t)?.[1]??``;return/^(https?:)?\/\//i.test(r)||/^(mailto|tel):/i.test(r)?e:n})}function m(t){let n=t=>t.replace(/\[\[([^\]]+)\]\]/g,(t,n)=>{let i=r(n);return i?`[${i.title}](${i.url})`:`[${e(n)}](#)`});return t.split(/(`{1,3}[^`]*?`{1,3})/g).map((e,t)=>t%2==1?e:n(e)).join(``)}export{l as a,u as i,f as n,p as o,m as r,d as t};