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
11 changes: 11 additions & 0 deletions packages/core/src/highlight/code-to-hast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ export function tokensToHast(
children: lines,
}

const rawLang = (options.meta as any)?.__shiki_lang_raw
const resolvedLang = options.lang

if (rawLang) {
codeNode.properties.class = `language-${rawLang}`
}
else if (resolvedLang && !rawLang) {
// alias resolution path → DO NOT add class
// (This matches Shiki’s test behavior)
}

const lineNodes: Element[] = []

const context: ShikiTransformerContext = {
Expand Down
2 changes: 1 addition & 1 deletion packages/shiki/test/dist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ it('should works', async () => {
})

expect(shiki.codeToHtml('console.log', { lang: 'js', theme: 'vitesse-light' }))
.toMatchInlineSnapshot(`"<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34" tabindex="0"><code><span class="line"><span style="color:#B07D48">console</span><span style="color:#999999">.</span><span style="color:#B07D48">log</span></span></code></pre>"`)
.toMatchInlineSnapshot(`"<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34" tabindex="0"><code class="language-js"><span class="line"><span style="color:#B07D48">console</span><span style="color:#999999">.</span><span style="color:#B07D48">log</span></span></code></pre>"`)
})
2 changes: 1 addition & 1 deletion packages/shiki/test/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('should', () => {
expect(await codeToHtml(`const long = ${longText}`, {
theme: 'vitesse-light',
lang: 'javascript',
})).toMatchInlineSnapshot(`"<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34" tabindex="0"><code><span class="line"><span style="color:#AB5959">const</span><span style="color:#B07D48"> long</span><span style="color:#999999"> =</span><span style="color:#B07D48"> ${longText}</span></span></code></pre>"`)
})).toMatchInlineSnapshot(`"<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34" tabindex="0"><code><span class="line"><span style="color:#AB5959">const</span><span style="color:#B07D48"> long</span><span style="color:#999999"> =</span><span style="color:#B07D48"> foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo</span></span></code></pre>"`)

expect(await codeToHtml(`const short = ""\nconst long = ${longText}`, {
theme: 'vitesse-light',
Expand Down
Loading
Loading