feat: better hyperlink formatting
This commit is contained in:
@@ -3,6 +3,10 @@ import type { ReactNode } from 'react'
|
|||||||
|
|
||||||
import type { Theme } from '../theme.js'
|
import type { Theme } from '../theme.js'
|
||||||
|
|
||||||
|
/** OSC 8 hyperlink — wrap-ansi / Ink keep the link active across soft line wraps. */
|
||||||
|
const osc8 = (url: string) => '\x1b]8;;' + url + '\x1b\\'
|
||||||
|
const OSC8_END = '\x1b]8;;\x1b\\'
|
||||||
|
|
||||||
function MdInline({ t, text }: { t: Theme; text: string }) {
|
function MdInline({ t, text }: { t: Theme; text: string }) {
|
||||||
const parts: ReactNode[] = []
|
const parts: ReactNode[] = []
|
||||||
const re = /(\[(.+?)\]\((https?:\/\/[^\s)]+)\)|\*\*(.+?)\*\*|`([^`]+)`|\*(.+?)\*|(https?:\/\/[^\s]+))/g
|
const re = /(\[(.+?)\]\((https?:\/\/[^\s)]+)\)|\*\*(.+?)\*\*|`([^`]+)`|\*(.+?)\*|(https?:\/\/[^\s]+))/g
|
||||||
@@ -18,8 +22,12 @@ function MdInline({ t, text }: { t: Theme; text: string }) {
|
|||||||
|
|
||||||
if (m[2] && m[3]) {
|
if (m[2] && m[3]) {
|
||||||
parts.push(
|
parts.push(
|
||||||
<Text color={t.color.amber} key={parts.length} underline>
|
<Text key={parts.length}>
|
||||||
{m[2]}
|
{osc8(m[3])}
|
||||||
|
<Text color={t.color.amber} underline>
|
||||||
|
{m[2]}
|
||||||
|
</Text>
|
||||||
|
{OSC8_END}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
} else if (m[4]) {
|
} else if (m[4]) {
|
||||||
@@ -41,9 +49,14 @@ function MdInline({ t, text }: { t: Theme; text: string }) {
|
|||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
} else if (m[7]) {
|
} else if (m[7]) {
|
||||||
|
const u = m[7]
|
||||||
parts.push(
|
parts.push(
|
||||||
<Text color={t.color.amber} key={parts.length} underline>
|
<Text key={parts.length}>
|
||||||
{m[7]}
|
{osc8(u)}
|
||||||
|
<Text color={t.color.amber} underline>
|
||||||
|
{u}
|
||||||
|
</Text>
|
||||||
|
{OSC8_END}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const ANSI_RE = /\x1b\[[0-9;]*m/g
|
|||||||
|
|
||||||
export const stripAnsi = (s: string) => s.replace(ANSI_RE, '')
|
export const stripAnsi = (s: string) => s.replace(ANSI_RE, '')
|
||||||
|
|
||||||
export const hasAnsi = (s: string) => s.includes('\x1b[')
|
export const hasAnsi = (s: string) => s.includes('\x1b[') || s.includes('\x1b]')
|
||||||
|
|
||||||
const renderEstimateLine = (line: string) => {
|
const renderEstimateLine = (line: string) => {
|
||||||
const trimmed = line.trim()
|
const trimmed = line.trim()
|
||||||
|
|||||||
Reference in New Issue
Block a user