Hi Marijn,
I’m building a language list inside a CM based editor:
To link the module name to the language I’ve added a module field to language-data. See the code below.
Would you be interested in adding something like this? Happy to provide as PR. Or should I fork instead?
function ofLegacy(spec) {
let ld: LanguageDescription
if (!spec.load) {
if (spec.loadName) {
const name: string = spec.loadName.toLowerCase()
spec.load = () => import("@codemirror/legacy-modes/mode/" + name).then(m => legacy(m[spec.loadName]))
}
else {
const name: string = spec.name.toLowerCase()
spec.load = () => import("@codemirror/legacy-modes/mode/" + name).then(m => legacy(m[name]))
}
}
ld = LanguageDescription.of(spec)
ld.module = "@codemirror/legacy-modes"
return ld
}
function of(spec) {
let ld: LanguageDescription
const module: string = spec.module || ("@codemirror/lang-" + spec.name.toLowerCase())
if (!spec.load) {
if (spec.loadName)
spec.load = () => import(module).then(m => m[spec.loadName]())
else
spec.load = () => import(module).then(m => m[spec.name.toLowerCase()]())
}
ld = LanguageDescription.of(spec)
ld.module = module
return ld
}
/// An array of language descriptions for known language packages.
export const languages = [
// New-style language modes
of({
name: "C",
extensions: ["c","h","ino"],
module: "@codemirror/lang-cpp",
loadName: "cpp"
}),
//...
ofLegacy({
name: "APL",
extensions: ["dyalog","apl"],
}),
ofLegacy({
name: "PGP",
alias: ["asciiarmor"],
extensions: ["asc","pgp","sig"],
loadName: "asciiArmor"
}),
// etc