Skip to content

Commit ad1a970

Browse files
committed
fix: match configured aliases with capitals in any case too
The lookup lowercased the language, but the aliases kept their keys as written, so `{ MyConf: 'ini' }` never matched. They're keyed in lowercase now. The test also says why Rust stands in for a bundled language registered through its own alias. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 280a8b5 commit ad1a970

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎packages/core/src/plugins/shiki/__tests__/highlighter.test.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ describe('createHighlighter', () => {
9292
});
9393
const loaded = () => highlighter.shiki.getLoadedLanguages();
9494

95+
// Rust stands for any bundled language nothing aliases: JavaScript's
96+
// aliases now lead to TypeScript
9597
assert.ok(!loaded().includes('python'));
9698
assert.ok(!loaded().includes('rust'));
9799

@@ -148,6 +150,7 @@ describe('createHighlighter', () => {
148150
pool: 'loop',
149151
oc: 'OxcConf',
150152
conf: 'INI',
153+
MyConf: 'ini',
151154
},
152155
});
153156

@@ -156,6 +159,8 @@ describe('createHighlighter', () => {
156159
assert.equal(highlighter.resolveLanguage('Python'), 'python');
157160
assert.equal(highlighter.resolveLanguage('oc'), 'OxcConf');
158161
assert.equal(highlighter.resolveLanguage('conf'), 'ini');
162+
assert.equal(highlighter.resolveLanguage('myconf'), 'ini');
163+
assert.equal(highlighter.resolveLanguage('MYCONF'), 'ini');
159164
assert.equal(
160165
highlighter.highlightToHtml('[section]', 'conf'),
161166
highlighter.highlightToHtml('[section]', 'ini')

‎packages/core/src/plugins/shiki/highlighter.mjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ const importHighlighter = async ({
222222
};
223223

224224
// Resolved here, as Shiki replaces an alias with a grammar's own as it
225-
// registers
226-
const aliases = new Map(Object.entries(langAlias));
225+
// registers. Keyed in lowercase, as they're matched in any case
226+
const aliases = new Map(
227+
Object.entries(langAlias).map(([from, to]) => [from.toLowerCase(), to])
228+
);
227229

228230
// Without themes of its own, the highlighter has a default light and dark one
229231
if (themes) {

0 commit comments

Comments
 (0)