mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 07:12:47 +03:00
refactor(core): consolidate HTML inline handling (#45649)
This commit is contained in:
committed by
GitHub
Unverified
parent
2cca1ae860
commit
6bf342a861
@@ -197,6 +197,12 @@ export function convertHTMLToMarkdown(html: string) {
|
||||
.trim()
|
||||
.replace(/([\\"])/g, "\\$1")}"`
|
||||
: ""
|
||||
const inlineMarker = (name: string) => {
|
||||
if (name === "strong" || name === "b") return "**"
|
||||
if (name === "em" || name === "i") return "*"
|
||||
if (name === "s" || name === "strike" || name === "del") return "~~"
|
||||
return undefined
|
||||
}
|
||||
const finishCode = (code: NonNullable<Frame["code"]>) => {
|
||||
if (code.inline && !code.text) return
|
||||
let backticks = 0
|
||||
@@ -321,20 +327,9 @@ export function convertHTMLToMarkdown(html: string) {
|
||||
block()
|
||||
return
|
||||
}
|
||||
if (name === "strong" || name === "b") {
|
||||
inline("**", true)
|
||||
frame.marker = { index: output.length - 1, block: blockCount, previous: activeMarker }
|
||||
activeMarker = frame.marker
|
||||
return
|
||||
}
|
||||
if (name === "em" || name === "i") {
|
||||
inline("*", true)
|
||||
frame.marker = { index: output.length - 1, block: blockCount, previous: activeMarker }
|
||||
activeMarker = frame.marker
|
||||
return
|
||||
}
|
||||
if (name === "s" || name === "strike" || name === "del") {
|
||||
inline("~~", true)
|
||||
const marker = inlineMarker(name)
|
||||
if (marker) {
|
||||
inline(marker, true)
|
||||
frame.marker = { index: output.length - 1, block: blockCount, previous: activeMarker }
|
||||
activeMarker = frame.marker
|
||||
return
|
||||
@@ -509,16 +504,8 @@ export function convertHTMLToMarkdown(html: string) {
|
||||
return
|
||||
}
|
||||
if (name === "dd") return block()
|
||||
if (
|
||||
name === "strong" ||
|
||||
name === "b" ||
|
||||
name === "em" ||
|
||||
name === "i" ||
|
||||
name === "s" ||
|
||||
name === "strike" ||
|
||||
name === "del"
|
||||
) {
|
||||
const value = name === "strong" || name === "b" ? "**" : name === "em" || name === "i" ? "*" : "~~"
|
||||
const marker = inlineMarker(name)
|
||||
if (marker) {
|
||||
const trailingSpace = pendingSpace
|
||||
pendingSpace = false
|
||||
if (frame.marker) activeMarker = frame.marker.previous
|
||||
@@ -527,15 +514,15 @@ export function convertHTMLToMarkdown(html: string) {
|
||||
pendingSpace = trailingSpace || frame.marker.leadingSpace === true
|
||||
return
|
||||
}
|
||||
inline(value)
|
||||
inline(marker)
|
||||
pendingSpace = trailingSpace || frame.marker?.leadingSpace === true
|
||||
return
|
||||
}
|
||||
if (name === "a") {
|
||||
if (frame.link && (activeLink === frame.link || !activeLink)) {
|
||||
activeLink = frame.link
|
||||
if (linkOpen) append(`](${destination(frame.link?.href ?? "")}${title(frame.link?.title)})`)
|
||||
else if (last && last !== "\n") append(`](${destination(frame.link?.href ?? "")}${title(frame.link?.title)})`)
|
||||
if (linkOpen || (last && last !== "\n"))
|
||||
append(`](${destination(frame.link.href)}${title(frame.link.title)})`)
|
||||
linkOpen = false
|
||||
activeLink = undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user