summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-docker.js
blob: 2468db170e17e18142d4ea2affb8e4389839b79b (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(function (Prism) {
  // Many of the following regexes will contain negated lookaheads like `[ \t]+(?![ \t])`. This is a trick to ensure
  // that quantifiers behave *atomically*. Atomic quantifiers are necessary to prevent exponential backtracking.

  var spaceAfterBackSlash =
    /\\[\r\n](?:\s|\\[\r\n]|#.*(?!.))*(?![\s#]|\\[\r\n])/.source;
  // At least one space, comment, or line break
  var space = /(?:[ \t]+(?![ \t])(?:<SP_BS>)?|<SP_BS>)/.source.replace(
    /<SP_BS>/g,
    function () {
      return spaceAfterBackSlash;
    }
  );

  var string =
    /"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*"|'(?:[^'\\\r\n]|\\(?:\r\n|[\s\S]))*'/
      .source;
  var option = /--[\w-]+=(?:<STR>|(?!["'])(?:[^\s\\]|\\.)+)/.source.replace(
    /<STR>/g,
    function () {
      return string;
    }
  );

  var stringRule = {
    pattern: RegExp(string),
    greedy: true,
  };
  var commentRule = {
    pattern: /(^[ \t]*)#.*/m,
    lookbehind: true,
    greedy: true,
  };

  /**
   * @param {string} source
   * @param {string} flags
   * @returns {RegExp}
   */
  function re(source, flags) {
    source = source
      .replace(/<OPT>/g, function () {
        return option;
      })
      .replace(/<SP>/g, function () {
        return space;
      });

    return RegExp(source, flags);
  }

  Prism.languages.docker = {
    instruction: {
      pattern:
        /(^[ \t]*)(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|ONBUILD|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)(?=\s)(?:\\.|[^\r\n\\])*(?:\\$(?:\s|#.*$)*(?![\s#])(?:\\.|[^\r\n\\])*)*/im,
      lookbehind: true,
      greedy: true,
      inside: {
        options: {
          pattern: re(
            /(^(?:ONBUILD<SP>)?\w+<SP>)<OPT>(?:<SP><OPT>)*/.source,
            'i'
          ),
          lookbehind: true,
          greedy: true,
          inside: {
            property: {
              pattern: /(^|\s)--[\w-]+/,
              lookbehind: true,
            },
            string: [
              stringRule,
              {
                pattern: /(=)(?!["'])(?:[^\s\\]|\\.)+/,
                lookbehind: true,
              },
            ],
            operator: /\\$/m,
            punctuation: /=/,
          },
        },
        keyword: [
          {
            // https://docs.docker.com/engine/reference/builder/#healthcheck
            pattern: re(
              /(^(?:ONBUILD<SP>)?HEALTHCHECK<SP>(?:<OPT><SP>)*)(?:CMD|NONE)\b/
                .source,
              'i'
            ),
            lookbehind: true,
            greedy: true,
          },
          {
            // https://docs.docker.com/engine/reference/builder/#from
            pattern: re(
              /(^(?:ONBUILD<SP>)?FROM<SP>(?:<OPT><SP>)*(?!--)[^ \t\\]+<SP>)AS/
                .source,
              'i'
            ),
            lookbehind: true,
            greedy: true,
          },
          {
            // https://docs.docker.com/engine/reference/builder/#onbuild
            pattern: re(/(^ONBUILD<SP>)\w+/.source, 'i'),
            lookbehind: true,
            greedy: true,
          },
          {
            pattern: /^\w+/,
            greedy: true,
          },
        ],
        comment: commentRule,
        string: stringRule,
        variable: /\$(?:\w+|\{[^{}"'\\]*\})/,
        operator: /\\$/m,
      },
    },
    comment: commentRule,
  };

  Prism.languages.dockerfile = Prism.languages.docker;
})(Prism);
n class="s1">'prolog', { 'front-matter-block': { pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/, lookbehind: true, greedy: true, inside: { punctuation: /^---|---$/, 'front-matter': { pattern: /\S+(?:\s+\S+)*/, alias: ['yaml', 'language-yaml'], inside: Prism.languages.yaml, }, }, }, blockquote: { // > ... pattern: /^>(?:[\t ]*>)*/m, alias: 'punctuation', }, table: { pattern: RegExp( '^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm' ), inside: { 'table-data-rows': { pattern: RegExp( '^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$' ), lookbehind: true, inside: { 'table-data': { pattern: RegExp(tableCell), inside: Prism.languages.markdown, }, punctuation: /\|/, }, }, 'table-line': { pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'), lookbehind: true, inside: { punctuation: /\||:?-{3,}:?/, }, }, 'table-header-row': { pattern: RegExp('^' + tableRow + '$'), inside: { 'table-header': { pattern: RegExp(tableCell), alias: 'important', inside: Prism.languages.markdown, }, punctuation: /\|/, }, }, }, }, code: [ { // Prefixed by 4 spaces or 1 tab and preceded by an empty line pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/, lookbehind: true, alias: 'keyword', }, { // ```optional language // code block // ``` pattern: /^```[\s\S]*?^```$/m, greedy: true, inside: { 'code-block': { pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m, lookbehind: true, }, 'code-language': { pattern: /^(```).+/, lookbehind: true, }, punctuation: /```/, }, }, ], title: [ { // title 1 // ======= // title 2 // ------- pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m, alias: 'important', inside: { punctuation: /==+$|--+$/, }, }, { // # title 1 // ###### title 6 pattern: /(^\s*)#.+/m, lookbehind: true, alias: 'important', inside: { punctuation: /^#+|#+$/, }, }, ], hr: { // *** // --- // * * * // ----------- pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m, lookbehind: true, alias: 'punctuation', }, list: { // * item // + item // - item // 1. item pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m, lookbehind: true, alias: 'punctuation', }, 'url-reference': { // [id]: http://example.com "Optional title" // [id]: http://example.com 'Optional title' // [id]: http://example.com (Optional title) // [id]: <http://example.com> "Optional title" pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/, inside: { variable: { pattern: /^(!?\[)[^\]]+/, lookbehind: true, }, string: /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/, punctuation: /^[\[\]!:]|[<>]/, }, alias: 'url', }, bold: { // **strong** // __strong__ // allow one nested instance of italic text using the same delimiter pattern: createInline( /\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/ .source ), lookbehind: true, greedy: true, inside: { content: { pattern: /(^..)[\s\S]+(?=..$)/, lookbehind: true, inside: {}, // see below }, punctuation: /\*\*|__/, }, }, italic: { // *em* // _em_ // allow one nested instance of bold text using the same delimiter pattern: createInline( /\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/ .source ), lookbehind: true, greedy: true, inside: { content: { pattern: /(^.)[\s\S]+(?=.$)/, lookbehind: true, inside: {}, // see below }, punctuation: /[*_]/, }, }, strike: { // ~~strike through~~ // ~strike~ // eslint-disable-next-line regexp/strict pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source), lookbehind: true, greedy: true, inside: { content: { pattern: /(^~~?)[\s\S]+(?=\1$)/, lookbehind: true, inside: {}, // see below }, punctuation: /~~?/, }, }, 'code-snippet': { // `code` // ``code`` pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/, lookbehind: true, greedy: true, alias: ['code', 'keyword'], }, url: { // [example](http://example.com "Optional title") // [example][id] // [example] [id] pattern: createInline( /!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/ .source ), lookbehind: true, greedy: true, inside: { operator: /^!/, content: { pattern: /(^\[)[^\]]+(?=\])/, lookbehind: true, inside: {}, // see below }, variable: { pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/, lookbehind: true, }, url: { pattern: /(^\]\()[^\s)]+/, lookbehind: true, }, string: { pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/, lookbehind: true, }, }, }, }); ['url', 'bold', 'italic', 'strike'].forEach(function (token) { ['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function ( inside ) { if (token !== inside) { Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside]; } }); }); Prism.hooks.add('after-tokenize', function (env) { if (env.language !== 'markdown' && env.language !== 'md') { return; } function walkTokens(tokens) { if (!tokens || typeof tokens === 'string') { return; } for (var i = 0, l = tokens.length; i < l; i++) { var token = tokens[i]; if (token.type !== 'code') { walkTokens(token.content); continue; } /* * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token * is optional. But the grammar is defined so that there is only one case we have to handle: * * token.content = [ * <span class="punctuation">```</span>, * <span class="code-language">xxxx</span>, * '\n', // exactly one new lines (\r or \n or \r\n) * <span class="code-block">...</span>, * '\n', // exactly one new lines again * <span class="punctuation">```</span> * ]; */ var codeLang = token.content[1]; var codeBlock = token.content[3]; if ( codeLang && codeBlock && codeLang.type === 'code-language' && codeBlock.type === 'code-block' && typeof codeLang.content === 'string' ) { // this might be a language that Prism does not support // do some replacements to support C++, C#, and F# var lang = codeLang.content .replace(/\b#/g, 'sharp') .replace(/\b\+\+/g, 'pp'); // only use the first word lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase(); var alias = 'language-' + lang; // add alias if (!codeBlock.alias) { codeBlock.alias = [alias]; } else if (typeof codeBlock.alias === 'string') { codeBlock.alias = [codeBlock.alias, alias]; } else { codeBlock.alias.push(alias); } } } } walkTokens(env.tokens); }); Prism.hooks.add('wrap', function (env) { if (env.type !== 'code-block') { return; } var codeLang = ''; for (var i = 0, l = env.classes.length; i < l; i++) { var cls = env.classes[i]; var match = /language-(.+)/.exec(cls); if (match) { codeLang = match[1]; break; } } var grammar = Prism.languages[codeLang]; if (!grammar) { if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) { var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16); env.attributes['id'] = id; Prism.plugins.autoloader.loadLanguages(codeLang, function () { var ele = document.getElementById(id); if (ele) { ele.innerHTML = Prism.highlight( ele.textContent, Prism.languages[codeLang], codeLang ); } }); } } else { env.content = Prism.highlight( textContent(env.content), grammar, codeLang ); } }); var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, 'gi'); /** * A list of known entity names. * * This will always be incomplete to save space. The current list is the one used by lowdash's unescape function. * * @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2} */ var KNOWN_ENTITY_NAMES = { amp: '&', lt: '<', gt: '>', quot: '"', }; // IE 11 doesn't support `String.fromCodePoint` var fromCodePoint = String.fromCodePoint || String.fromCharCode; /** * Returns the text content of a given HTML source code string. * * @param {string} html * @returns {string} */ function textContent(html) { // remove all tags var text = html.replace(tagPattern, ''); // decode known entities text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (m, code) { code = code.toLowerCase(); if (code[0] === '#') { var value; if (code[1] === 'x') { value = parseInt(code.slice(2), 16); } else { value = Number(code.slice(1)); } return fromCodePoint(value); } else { var known = KNOWN_ENTITY_NAMES[code]; if (known) { return known; } // unable to decode return m; } }); return text; } Prism.languages.md = Prism.languages.markdown; })(Prism);