I had previously created a custom mode for syntax highlighting for the ChordPro (https://www.chordpro.org/) syntax - I found the legacy-modes directory and I wonder if there’s any guidance you’d share for how to quickly? easily? migrate a CM5 mode file to CM6?
I’d love to contribute and continue to improve this for the public OSS modes.
Here was my mode file before:
require("codemirror/addon/mode/simple");
const chordBases = ["A", "B", "C", "D", "E", "F", "G"];
const chordStartMatches = chordBases.map(chord => ({
regex: new RegExp(`\\[${chord}`, "i"),
push: chord,
token: `chord-${chord}`,
}));
let chordStates = {};
chordBases.map(chord => {
chordStates[chord] = [
{ regex: /\]/, pop: true, token: `chord-${chord}` },
{ regex: /[^\]]+/, token: `chord-${chord}` },
];
});
//console.debug("chordStartMatches", chordStartMatches, chordStates);
codemirror.defineSimpleMode("chordpro", {
start: [
...chordStartMatches,
{ regex: /\[/, push: "chord", token: "chord" },
{ regex: /\{/, push: "directive", token: "directive" },
],
chord: [
{ regex: /\]/, pop: true, token: "chord" },
{ regex: /\w+/, token: "chord" },
],
...chordStates,
directive: [
{ regex: /\}/, pop: true, token: "directive" },
{ regex: /[\w\s:]+/, token: "directive" },
],
comment: [],
meta: {},
});