From ff5405418009fc4ca5614cc7bbe2a508d3e03e33 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 5 Jul 2021 19:46:19 +0200 Subject: [PATCH] Fix registered language name for grammar names with dash, fixes #3263. --- src/stub.js | 2 +- test/builds/browser_build_as_commonjs.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stub.js b/src/stub.js index ee342b5e3d..b5dd0d85a0 100644 --- a/src/stub.js +++ b/src/stub.js @@ -5,7 +5,7 @@ import * as builtIns from "builtInLanguages"; const hljs = HighlightJS; for (const key of Object.keys(builtIns)) { - const languageName = key.replace("grmr_", ""); + const languageName = key.replace("grmr_", "").replace("_", "-"); hljs.registerLanguage(languageName, builtIns[key]); } // console.log(hljs.listLanguages()); diff --git a/test/builds/browser_build_as_commonjs.js b/test/builds/browser_build_as_commonjs.js index 8db2ec4e18..2bdd6e0cca 100644 --- a/test/builds/browser_build_as_commonjs.js +++ b/test/builds/browser_build_as_commonjs.js @@ -21,4 +21,13 @@ API.forEach(n => { assert(_ => keys.includes(n), `API should include ${n}`); }); +// See e.g. highlightjs/highlight.js#3263 +const langs = ["python", "python-repl"] +langs.forEach(n => { + assert(_ => { + res = hljs.getLanguage(n); + return typeof res === 'object' && res !== null + }) +}) + console.log("Pass: browser build works with Node.js just fine.")