Skip to content
Closed
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
4 changes: 2 additions & 2 deletions server/utils/docs/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ async function renderJsDocTags(tags: JsDocTag[], symbolLookup: SymbolLookup): Pr
: null
const examplePromises = examples.map(async example => {
if (!example.doc) return ''
const langMatch = example.doc.match(/```(\w+)?/)
const langMatch = example.doc.match(/```([\w-]+)?/)
const lang = langMatch?.[1] || 'typescript'
const code = example.doc.replace(/```\w*\n?/g, '').trim()
const code = example.doc.replace(/```[\w-]*\n?/g, '').trim()
return highlightCodeBlock(code, lang)
})

Expand Down
2 changes: 1 addition & 1 deletion server/utils/docs/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function renderMarkdown(text: string, symbolLookup: SymbolLookup):
// - \r\n, \n, or \r line endings
const codeBlockData: Array<{ lang: string; code: string }> = []
let result = text.replace(
/```[ \t]*(\w*)[ \t]*(?:\r\n|\r|\n)([\s\S]*?)(?:\r\n|\r|\n)?```/g,
/```[ \t]*([\w-]*)[ \t]*(?:\r\n|\r|\n)([\s\S]*?)(?:\r\n|\r|\n)?```/g,
(_, lang, code) => {
const index = codeBlockData.length
codeBlockData.push({ lang: lang || 'text', code: code.trim() })
Expand Down
11 changes: 11 additions & 0 deletions test/unit/server/utils/docs/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ describe('renderMarkdown', () => {
expect(result).not.toContain('```')
})

it('should handle fenced code blocks with hyphenated language (e.g. glimmer-ts)', async () => {
// Regression test for #2437: regex used \w which dropped the `-ts` suffix,
// leaving it at the start of the code body and breaking highlighting.
const input = '```glimmer-ts\nconst x = 1;\n```'
const result = await renderMarkdown(input, emptyLookup)
// Code must not leak the truncated language suffix into the body
expect(result).not.toContain('-ts')
expect(result).toContain('const')
expect(result).not.toContain('```')
})

it('should escape HTML inside fenced code blocks', async () => {
const input = '```ts\nconst arr: Array<string> = [];\n```'
const result = await renderMarkdown(input, emptyLookup)
Expand Down
Loading