Skip to content

Commit 1cb086b

Browse files
authored
fix(build) registered language names should use - not _ (#3264)
* Fix registered language name for grammar names with dash, fixes #3263.
1 parent 55f68f7 commit 1cb086b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/stub.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import * as builtIns from "builtInLanguages";
55
const hljs = HighlightJS;
66

77
for (const key of Object.keys(builtIns)) {
8-
const languageName = key.replace("grmr_", "");
8+
// our builtInLanguages Rollup plugin has to use `_` to allow identifiers to be
9+
// compatible with `export` naming conventions, so we need to convert the
10+
// identifiers back into the more typical dash style that we use for language
11+
// naming via the API
12+
const languageName = key.replace("grmr_", "").replace("_", "-");
913
hljs.registerLanguage(languageName, builtIns[key]);
1014
}
1115
// console.log(hljs.listLanguages());

test/builds/browser_build_as_commonjs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ API.forEach(n => {
2121
assert(_ => keys.includes(n), `API should include ${n}`);
2222
});
2323

24+
// See e.g. highlightjs/highlight.js#3263
25+
const langs = ["python", "python-repl"]
26+
langs.forEach(n => {
27+
assert(_ => {
28+
res = hljs.getLanguage(n);
29+
return typeof res === 'object' && res !== null
30+
})
31+
})
32+
2433
console.log("Pass: browser build works with Node.js just fine.")

0 commit comments

Comments
 (0)