summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-lilypond.js
blob: a9ceb1e8f496d112b521b5b853a8aaca97bd418b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant *
(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 = 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);