diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-30 19:47:21 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-30 19:47:21 +0100 |
| commit | a98b5ea6fe8e8cc98a55e0fd793e6e8660ea31c1 (patch) | |
| tree | 542810ab5aef99150db228bb54fd58303dcb31c7 /public/prism/prism-lilypond.js | |
| parent | ab355897a12b7bda1089a44de326d41455a0f7a3 (diff) | |
chore: add prismjs for syntax highlighting
Diffstat (limited to 'public/prism/prism-lilypond.js')
| -rw-r--r-- | public/prism/prism-lilypond.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/public/prism/prism-lilypond.js b/public/prism/prism-lilypond.js new file mode 100644 index 0000000..a9ceb1e --- /dev/null +++ b/public/prism/prism-lilypond.js @@ -0,0 +1,81 @@ +(function (Prism) { + var schemeExpression = + /\((?:[^();"#\\]|\\[\s\S]|;.*(?!.)|"(?:[^"\\]|\\.)*"|#(?:\{(?:(?!#\})[\s\S])*#\}|[^{])|<expr>)*\)/ + .source; + // allow for up to pow(2, recursivenessLog2) many levels of recursive brace expressions + // For some reason, this can't be 4 + var recursivenessLog2 = 5; + for (var i = 0; i < recursivenessLog2; i++) { + schemeExpression = schemeExpression.replace(/<expr>/g, function () { + return schemeExpression; + }); + } + schemeExpression = schemeExpression.replace(/<expr>/g, /[^\s\S]/.source); + + var lilypond = (Prism.languages.lilypond = { + comment: /%(?:(?!\{).*|\{[\s\S]*?%\})/, + 'embedded-scheme': { + pattern: RegExp( + /(^|[=\s])#(?:"(?:[^"\\]|\\.)*"|[^\s()"]*(?:[^\s()]|<expr>))/.source.replace( + /<expr>/g, + function () { + return schemeExpression; + } + ), + 'm' + ), + lookbehind: true, + greedy: true, + inside: { + scheme: { + pattern: /^(#)[\s\S]+$/, + lookbehind: true, + alias: 'language-scheme', + inside: { + 'embedded-lilypond': { + pattern: /#\{[\s\S]*?#\}/, + greedy: true, + inside: { + punctuation: /^#\{|#\}$/, + lilypond: { + pattern: /[\s\S]+/, + alias: 'language-lilypond', + inside: null, // see below + }, + }, + }, + rest: Prism.languages.scheme, + }, + }, + punctuation: /#/, + }, + }, + string: { + pattern: /"(?:[^"\\]|\\.)*"/, + greedy: true, + }, + 'class-name': { + pattern: /(\\new\s+)[\w-]+/, + lookbehind: true, + }, + keyword: { + pattern: /\\[a-z][-\w]*/i, + inside: { + punctuation: /^\\/, + }, + }, + operator: /[=|]|<<|>>/, + punctuation: { + pattern: + /(^|[a-z\d])(?:'+|,+|[_^]?-[_^]?(?:[-+^!>._]|(?=\d))|[_^]\.?|[.!])|[{}()[\]<>^~]|\\[()[\]<>\\!]|--|__/, + lookbehind: true, + }, + number: /\b\d+(?:\/\d+)?\b/, + }); + + lilypond['embedded-scheme'].inside['scheme'].inside[ + 'embedded-lilypond' + ].inside['lilypond'].inside = lilypond; + + Prism.languages.ly = lilypond; +})(Prism); |
