Skip to content

Commit 54a8042

Browse files
committed
fix(core): link labels across conceal highlights
1 parent 7fc7678 commit 54a8042

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/core/src/lib/detect-links.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,18 @@ describe("detectLinks", () => {
133133

134134
expect(result.find((c) => c.text === "OpenTUI")!.link).toEqual({ url: "https://opentui.com" })
135135
})
136+
137+
test("should associate markdown label when conceal highlights separate it from the destination", () => {
138+
const content = "[OpenTUI](https://opentui.com)"
139+
const highlights: SimpleHighlight[] = [
140+
[1, 8, "markup.link.label"],
141+
[8, 10, "conceal", { conceal: "" }],
142+
[10, 29, "markup.link.url"],
143+
]
144+
const chunks = [chunk("OpenTUI")]
145+
146+
const result = detectLinks(chunks, { content, highlights })
147+
148+
expect(result[0].link).toEqual({ url: "https://opentui.com" })
149+
})
136150
})

packages/core/src/lib/detect-links.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function detectLinks(
3131
ranges.push({ start: labelStart, end: labelEnd, url })
3232
break
3333
}
34+
if (prev === "conceal") continue
3435
if (!prev.startsWith("markup.link")) break
3536
}
3637
}

0 commit comments

Comments
 (0)