Skip to content
Open
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
3 changes: 2 additions & 1 deletion server/utils/mdKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export async function createCodeHighlighter(): Promise<RendererApi['code']> {

// Syntax highlighting for code blocks (uses shared highlighter)
return ({ text, lang }: Tokens.Code) => {
const html = highlightCodeSync(shiki, text, lang || 'text')
const language = (lang || '').match(/^\S+/)?.[0] || 'text'
const html = highlightCodeSync(shiki, text, language)
// Add copy button
return `<div class="readme-code-block" >
<button type="button" class="readme-copy-button" aria-label="Copy code" check-icon="i-lucide:check" copy-icon="i-lucide:copy" data-copy>
Expand Down
7 changes: 7 additions & 0 deletions test/unit/server/utils/readme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,13 @@ describe('HTML output', () => {
expect(result.html).not.toContain('rel="bookmark"')
expect(result.html).not.toContain('target="_self"')
})

it('only uses the first word of a fenced code info string as its language', async () => {
const markdown = '```ts second-word\nconst value = 1\n```'
const result = await renderReadmeHtml(markdown, 'test-pkg')

expect(result.html).toContain('<code class="language-ts">')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})
})

/**
Expand Down
Loading