From ff5405418009fc4ca5614cc7bbe2a508d3e03e33 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 5 Jul 2021 19:46:19 +0200 Subject: [PATCH 1/3] 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.") From 984fc043c466371965abfdccf6ebe8e244919b03 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 5 Jul 2021 16:24:46 -0400 Subject: [PATCH 2/3] Update src/stub.js --- src/stub.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/stub.js b/src/stub.js index b5dd0d85a0..884add9a73 100644 --- a/src/stub.js +++ b/src/stub.js @@ -5,6 +5,10 @@ import * as builtIns from "builtInLanguages"; const hljs = HighlightJS; for (const key of Object.keys(builtIns)) { + // our builtInLanguages Rollup plugin has to use `_` to allow identifiers to be + // compatible with `export` naming conventions, so we need to convert the + // identifiers back into the more typical dash style that we use for language + // naming via the API const languageName = key.replace("grmr_", "").replace("_", "-"); hljs.registerLanguage(languageName, builtIns[key]); } From bbff5f1ed008db0db956e3f8deb5b2bdf52e432b Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 5 Jul 2021 16:26:34 -0400 Subject: [PATCH 3/3] remove trailing spaces --- src/stub.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stub.js b/src/stub.js index 884add9a73..a447266e34 100644 --- a/src/stub.js +++ b/src/stub.js @@ -5,9 +5,9 @@ import * as builtIns from "builtInLanguages"; const hljs = HighlightJS; for (const key of Object.keys(builtIns)) { - // our builtInLanguages Rollup plugin has to use `_` to allow identifiers to be - // compatible with `export` naming conventions, so we need to convert the - // identifiers back into the more typical dash style that we use for language + // our builtInLanguages Rollup plugin has to use `_` to allow identifiers to be + // compatible with `export` naming conventions, so we need to convert the + // identifiers back into the more typical dash style that we use for language // naming via the API const languageName = key.replace("grmr_", "").replace("_", "-"); hljs.registerLanguage(languageName, builtIns[key]);