mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-01 22:10:23 +00:00
fix(desktop): hang on backtracing-prone regex
This commit is contained in:
parent
3aca9e5fa5
commit
aa1c560e5e
1 changed files with 12 additions and 3 deletions
|
|
@ -2,9 +2,18 @@ import { useMarked } from "../context/marked"
|
||||||
import { ComponentProps, createResource, splitProps } from "solid-js"
|
import { ComponentProps, createResource, splitProps } from "solid-js"
|
||||||
|
|
||||||
function strip(text: string): string {
|
function strip(text: string): string {
|
||||||
const wrappedRe = /^\s*<([A-Za-z]\w*)>\s*([\s\S]*?)\s*<\/\1>\s*$/
|
const trimmed = text.trim()
|
||||||
const match = text.match(wrappedRe)
|
const match = trimmed.match(/^<([A-Za-z]\w*)>/)
|
||||||
return match ? match[2] : text
|
if (!match) return text
|
||||||
|
|
||||||
|
const tagName = match[1]
|
||||||
|
const closingTag = `</${tagName}>`
|
||||||
|
if (trimmed.endsWith(closingTag)) {
|
||||||
|
const content = trimmed.slice(match[0].length, -closingTag.length)
|
||||||
|
return content.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Markdown(
|
export function Markdown(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue