mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-29 01:31:41 +00:00
fix(tui): don't italicize intraword underscores in markdown
The inline markdown regex matched `_..._` / `__...__` anywhere, so file paths like `browser_screenshot_ecc1c3feab.png` got mid-path italics. Require non-word flanking (`(?<!\w)` / `(?!\w)`) on underscore emphasis so snake_case identifiers and paths render literally, matching the CommonMark intraword rule. `*` / `**` keep intraword semantics.
This commit is contained in:
parent
36e8435d3e
commit
b17eb94907
2 changed files with 39 additions and 5 deletions
34
ui-tui/src/__tests__/markdown.test.ts
Normal file
34
ui-tui/src/__tests__/markdown.test.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { INLINE_RE, stripInlineMarkup } from '../components/markdown.js'
|
||||
|
||||
const matches = (text: string) => [...text.matchAll(INLINE_RE)].map(m => m[0])
|
||||
|
||||
describe('INLINE_RE emphasis', () => {
|
||||
it('matches word-boundary italic/bold', () => {
|
||||
expect(matches('say _hi_ there')).toEqual(['_hi_'])
|
||||
expect(matches('very __bold__ move')).toEqual(['__bold__'])
|
||||
expect(matches('(_paren_) and [_bracket_]')).toEqual(['_paren_', '_bracket_'])
|
||||
})
|
||||
|
||||
it('keeps intraword underscores literal', () => {
|
||||
const path = '/home/me/.hermes/cache/screenshots/browser_screenshot_ecc1c3feab.png'
|
||||
|
||||
expect(matches(path)).toEqual([])
|
||||
expect(matches('snake_case_var and MY_CONST')).toEqual([])
|
||||
expect(matches('foo__bar__baz')).toEqual([])
|
||||
})
|
||||
|
||||
it('still matches asterisk emphasis intraword', () => {
|
||||
expect(matches('a*b*c')).toEqual(['*b*'])
|
||||
expect(matches('a**bold**c')).toEqual(['**bold**'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('stripInlineMarkup', () => {
|
||||
it('strips word-boundary emphasis only', () => {
|
||||
expect(stripInlineMarkup('say _hi_ there')).toBe('say hi there')
|
||||
expect(stripInlineMarkup('browser_screenshot_ecc.png')).toBe('browser_screenshot_ecc.png')
|
||||
expect(stripInlineMarkup('__bold__ and foo__bar__')).toBe('bold and foo__bar__')
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue