From 8ca3d65b781be0225e8e7232e4be672a0db3efe6 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Wed, 6 Mar 2019 13:53:33 +0100 Subject: [PATCH] Markdown: The 'md' alias is now recognized by hooks (#1771) The hooks markdown adds itself will now recognize the `md` alias. --- components/prism-markdown.js | 22 ++++++++++------------ components/prism-markdown.min.js | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/components/prism-markdown.js b/components/prism-markdown.js index eba1af6556..18a5154cb1 100644 --- a/components/prism-markdown.js +++ b/components/prism-markdown.js @@ -146,18 +146,16 @@ Prism.languages.insertBefore('markdown', 'prolog', { } }); -Prism.languages.markdown['bold'].inside['url'] = Prism.languages.markdown['url']; -Prism.languages.markdown['italic'].inside['url'] = Prism.languages.markdown['url']; -Prism.languages.markdown['strike'].inside['url'] = Prism.languages.markdown['url']; -Prism.languages.markdown['bold'].inside['italic'] = Prism.languages.markdown['italic']; -Prism.languages.markdown['bold'].inside['strike'] = Prism.languages.markdown['strike']; -Prism.languages.markdown['italic'].inside['bold'] = Prism.languages.markdown['bold']; -Prism.languages.markdown['italic'].inside['strike'] = Prism.languages.markdown['strike']; -Prism.languages.markdown['strike'].inside['bold'] = Prism.languages.markdown['bold']; -Prism.languages.markdown['strike'].inside['italic'] = Prism.languages.markdown['italic']; +['bold', 'italic', 'strike'].forEach(function (token) { + ['url', 'bold', 'italic', 'strike'].forEach(function (inside) { + if (token !== inside) { + Prism.languages.markdown[token].inside[inside] = Prism.languages.markdown[inside]; + } + }); +}); Prism.hooks.add('after-tokenize', function (env) { - if (env.language !== 'markdown') { + if (env.language !== 'markdown' && env.language !== 'md') { return; } @@ -207,7 +205,7 @@ Prism.hooks.add('wrap', function (env) { var codeLang = ''; for (var i = 0, l = env.classes.length; i < l; i++) { var cls = env.classes[i]; - var match = /language-(\w+)/.exec(cls); + var match = /language-(.+)/.exec(cls); if (match) { codeLang = match[1]; break; @@ -226,4 +224,4 @@ Prism.hooks.add('wrap', function (env) { env.content = Prism.highlight(code, grammar, codeLang); }); -Prism.languages.md = Prism.languages.markdown; \ No newline at end of file +Prism.languages.md = Prism.languages.markdown; diff --git a/components/prism-markdown.min.js b/components/prism-markdown.min.js index b93ac86ab8..3891541c5b 100644 --- a/components/prism-markdown.min.js +++ b/components/prism-markdown.min.js @@ -1 +1 @@ -Prism.languages.markdown=Prism.languages.extend("markup",{}),Prism.languages.insertBefore("markdown","prolog",{blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},code:[{pattern:/^(?: {4}|\t).+/m,alias:"keyword"},{pattern:/``.+?``|`[^`\n]+`/,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\r?\n|\r))[\s\S]+?(?=(?:\r?\n|\r)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\r?\n|\r)(?:==+|--+)/,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#+.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:/(^|[^\\])(\*\*|__)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,greedy:!0,inside:{punctuation:/^\*\*|^__|\*\*$|__$/}},italic:{pattern:/(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,greedy:!0,inside:{punctuation:/^[*_]|[*_]$/}},strike:{pattern:/(^|[^\\])(~~?)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,greedy:!0,inside:{punctuation:/^~~?|~~?$/}},url:{pattern:/!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[[^\]\n]*\])/,inside:{variable:{pattern:/(!?\[)[^\]]+(?=\]$)/,lookbehind:!0},string:{pattern:/"(?:\\.|[^"\\])*"(?=\)$)/}}}}),Prism.languages.markdown.bold.inside.url=Prism.languages.markdown.url,Prism.languages.markdown.italic.inside.url=Prism.languages.markdown.url,Prism.languages.markdown.strike.inside.url=Prism.languages.markdown.url,Prism.languages.markdown.bold.inside.italic=Prism.languages.markdown.italic,Prism.languages.markdown.bold.inside.strike=Prism.languages.markdown.strike,Prism.languages.markdown.italic.inside.bold=Prism.languages.markdown.bold,Prism.languages.markdown.italic.inside.strike=Prism.languages.markdown.strike,Prism.languages.markdown.strike.inside.bold=Prism.languages.markdown.bold,Prism.languages.markdown.strike.inside.italic=Prism.languages.markdown.italic,Prism.hooks.add("after-tokenize",function(a){function n(a){if(a&&"string"!=typeof a)for(var e=0,i=a.length;i>e;e++){var r=a[e];if("code"===r.type){var t=r.content[1],s=r.content[3];if(t&&s&&"code-language"===t.type&&"code-block"===s.type&&"string"==typeof t.content){var o="language-"+t.content.trim().split(/\s+/)[0].toLowerCase();s.alias?"string"==typeof s.alias?s.alias=[s.alias,o]:s.alias.push(o):s.alias=[o]}}else n(r.content)}}"markdown"===a.language&&n(a.tokens)}),Prism.hooks.add("wrap",function(a){if("code-block"===a.type){for(var n="",e=0,i=a.classes.length;i>e;e++){var r=a.classes[e],t=/language-(\w+)/.exec(r);if(t){n=t[1];break}}var s=Prism.languages[n];if(s){var o=a.content.replace(/</g,"<").replace(/&/g,"&");a.content=Prism.highlight(o,s,n)}}}),Prism.languages.md=Prism.languages.markdown; \ No newline at end of file +Prism.languages.markdown=Prism.languages.extend("markup",{}),Prism.languages.insertBefore("markdown","prolog",{blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},code:[{pattern:/^(?: {4}|\t).+/m,alias:"keyword"},{pattern:/``.+?``|`[^`\n]+`/,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\r?\n|\r))[\s\S]+?(?=(?:\r?\n|\r)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\r?\n|\r)(?:==+|--+)/,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#+.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:/(^|[^\\])(\*\*|__)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,greedy:!0,inside:{punctuation:/^\*\*|^__|\*\*$|__$/}},italic:{pattern:/(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,greedy:!0,inside:{punctuation:/^[*_]|[*_]$/}},strike:{pattern:/(^|[^\\])(~~?)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,greedy:!0,inside:{punctuation:/^~~?|~~?$/}},url:{pattern:/!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[[^\]\n]*\])/,inside:{variable:{pattern:/(!?\[)[^\]]+(?=\]$)/,lookbehind:!0},string:{pattern:/"(?:\\.|[^"\\])*"(?=\)$)/}}}}),["bold","italic","strike"].forEach(function(n){["url","bold","italic","strike"].forEach(function(a){n!==a&&(Prism.languages.markdown[n].inside[a]=Prism.languages.markdown[a])})}),Prism.hooks.add("after-tokenize",function(n){function a(n){if(n&&"string"!=typeof n)for(var t=0,e=n.length;e>t;t++){var r=n[t];if("code"===r.type){var i=r.content[1],o=r.content[3];if(i&&o&&"code-language"===i.type&&"code-block"===o.type&&"string"==typeof i.content){var s="language-"+i.content.trim().split(/\s+/)[0].toLowerCase();o.alias?"string"==typeof o.alias?o.alias=[o.alias,s]:o.alias.push(s):o.alias=[s]}}else a(r.content)}}("markdown"===n.language||"md"===n.language)&&a(n.tokens)}),Prism.hooks.add("wrap",function(n){if("code-block"===n.type){for(var a="",t=0,e=n.classes.length;e>t;t++){var r=n.classes[t],i=/language-(.+)/.exec(r);if(i){a=i[1];break}}var o=Prism.languages[a];if(o){var s=n.content.replace(/</g,"<").replace(/&/g,"&");n.content=Prism.highlight(s,o,a)}}}),Prism.languages.md=Prism.languages.markdown; \ No newline at end of file