Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions ui-tui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions ui-tui/src/__tests__/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,66 @@ describe('stripInlineMarkup', () => {
expect(stripInlineMarkup('Yay ~! nice work ~!')).toBe('Yay ~! nice work ~!')
expect(stripInlineMarkup('H~2~O and CO~2~')).toBe('H_2O and CO_2')
})

it('strips inline math delimiters but keeps the formula text', () => {
expect(stripInlineMarkup('$\\mathbb{Z}$ is a ring')).toBe('\\mathbb{Z} is a ring')
expect(stripInlineMarkup('see \\(a + b\\) ok')).toBe('see a + b ok')
})
})

describe('INLINE_RE inline math', () => {
it('matches single-dollar math and beats emphasis at the same start', () => {
// Without math handling, `*b*` would have matched as italics and
// corrupted the formula. With math added to INLINE_RE, the leftmost
// match at column 0 (`$P=a*b*c$`) wins.
expect(matches('$P=a*b*c$')).toEqual(['$P=a*b*c$'])
expect(matches('see $\\mathbb{Z}$ here')).toEqual(['$\\mathbb{Z}$'])
})

it('does not match currency-style prose', () => {
expect(matches('it costs $5 and $10')).toEqual([])
expect(matches('paid $5')).toEqual([])
})

it('does not let inline math swallow a $$ display fence', () => {
// `$$x$$` is a display block, not two abutting inline-math spans.
expect(matches('$$x$$')).toEqual([])
})

it('matches \\(...\\) inline math', () => {
expect(matches('foo \\(x + y\\) bar')).toEqual(['\\(x + y\\)'])
})

it('does not corrupt subscripts/superscripts inside math', () => {
// `_n` and `^r` are markdown emphasis/superscript markers in prose, but
// inside a `$...$` span the entire formula is captured as a single
// inline-math token so the inner regexes never see those characters.
expect(matches('$P=a_n x^n + a_0$')).toEqual(['$P=a_n x^n + a_0$'])
expect(matches('$\\beta_1,\\dots,\\beta_r$')).toEqual(['$\\beta_1,\\dots,\\beta_r$'])
})

it('places math content in the correct capture group (regression: m[16] is bare URL)', () => {
// When `m[16]` was the bare URL group AND the inline-math `$...$`
// group simultaneously (because the bare URL pattern lacked its own
// capturing parens), MdInline rendered `$\\mathbb{R}$` as an
// underlined autolink instead of italic amber math. Lock down the
// numbering: math goes in m[17] / m[18], URLs go in m[16].
const url = [...'see https://example.com here'.matchAll(INLINE_RE)][0]!
const dollarMath = [...'$\\mathbb{R}$'.matchAll(INLINE_RE)][0]!
const parenMath = [...'\\(\\pi\\)'.matchAll(INLINE_RE)][0]!

expect(url[16]).toBe('https://example.com')
expect(url[17]).toBeUndefined()
expect(url[18]).toBeUndefined()

expect(dollarMath[16]).toBeUndefined()
expect(dollarMath[17]).toBe('\\mathbb{R}')
expect(dollarMath[18]).toBeUndefined()

expect(parenMath[16]).toBeUndefined()
expect(parenMath[17]).toBeUndefined()
expect(parenMath[18]).toBe('\\pi')
})
})

describe('protocol sentinels', () => {
Expand Down
Loading
Loading