From ef679ad71769ba62178abd26c5e05131303bd7a0 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 10 Sep 2018 23:48:46 +0200 Subject: [PATCH 1/4] Fixed markdown headers --- components/prism-markdown.js | 4 ++-- components/prism-markdown.min.js | 2 +- tests/languages/markdown/hr_feature.test | 4 +++- tests/languages/markdown/title_feature.test | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/prism-markdown.js b/components/prism-markdown.js index 8b63780406..4ec4593ecd 100644 --- a/components/prism-markdown.js +++ b/components/prism-markdown.js @@ -25,7 +25,7 @@ Prism.languages.insertBefore('markdown', 'prolog', { // title 2 // ------- - pattern: /\w+.*(?:\r?\n|\r)(?:==+|--+)/, + pattern: /\S.*(?:\r?\n|\r)(?:==+|--+)/, alias: 'important', inside: { punctuation: /==+$|--+$/ @@ -117,4 +117,4 @@ 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['bold'].inside['italic'] = Prism.languages.markdown['italic']; -Prism.languages.markdown['italic'].inside['bold'] = Prism.languages.markdown['bold']; \ No newline at end of file +Prism.languages.markdown['italic'].inside['bold'] = Prism.languages.markdown['bold']; diff --git a/components/prism-markdown.min.js b/components/prism-markdown.min.js index 012565b4a6..8a62c4408f 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"}],title:[{pattern:/\w+.*(?:\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,inside:{punctuation:/^\*\*|^__|\*\*$|__$/}},italic:{pattern:/(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!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.bold.inside.italic=Prism.languages.markdown.italic,Prism.languages.markdown.italic.inside.bold=Prism.languages.markdown.bold; \ 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"}],title:[{pattern:/[^-=\r\n].*(?:\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,inside:{punctuation:/^\*\*|^__|\*\*$|__$/}},italic:{pattern:/(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!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.bold.inside.italic=Prism.languages.markdown.italic,Prism.languages.markdown.italic.inside.bold=Prism.languages.markdown.bold; \ No newline at end of file diff --git a/tests/languages/markdown/hr_feature.test b/tests/languages/markdown/hr_feature.test index 412022652e..bba290d4ac 100644 --- a/tests/languages/markdown/hr_feature.test +++ b/tests/languages/markdown/hr_feature.test @@ -1,5 +1,7 @@ *** + --- + * * * ---------------------------------------------------- @@ -12,4 +14,4 @@ ---------------------------------------------------- -Checks for hr. \ No newline at end of file +Checks for hr. diff --git a/tests/languages/markdown/title_feature.test b/tests/languages/markdown/title_feature.test index e02e86fb7b..58f52d65d0 100644 --- a/tests/languages/markdown/title_feature.test +++ b/tests/languages/markdown/title_feature.test @@ -4,6 +4,9 @@ title 1 foobar ====== +Überschrift +=========== + title 2 -- @@ -19,6 +22,7 @@ title 2 [ ["title", ["title 1\r\n", ["punctuation", "=="]]], ["title", ["foobar\r\n", ["punctuation", "======"]]], + ["title", ["Überschrift\r\n", ["punctuation", "==========="]]], ["title", ["title 2\r\n", ["punctuation", "--"]]], ["title", [["punctuation", "#"], " title 1"]], @@ -31,4 +35,4 @@ title 2 ---------------------------------------------------- -Checks for titles. \ No newline at end of file +Checks for titles. From 2d622f17e4f6d746e8f4fa211c7f6b7ccb3f27b4 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 12 Nov 2018 20:12:44 +0100 Subject: [PATCH 2/4] Show invisibles inside tokens --- .../show-invisibles/prism-show-invisibles.css | 4 +- .../show-invisibles/prism-show-invisibles.js | 99 +++++++++++++++---- .../prism-show-invisibles.min.js | 2 +- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/plugins/show-invisibles/prism-show-invisibles.css b/plugins/show-invisibles/prism-show-invisibles.css index c57be58812..16583b31d9 100644 --- a/plugins/show-invisibles/prism-show-invisibles.css +++ b/plugins/show-invisibles/prism-show-invisibles.css @@ -9,8 +9,8 @@ .token.cr:before, .token.lf:before, .token.space:before { - color: inherit; - opacity: 0.4; + color: #888; + opacity: 0.6; position: absolute; } diff --git a/plugins/show-invisibles/prism-show-invisibles.js b/plugins/show-invisibles/prism-show-invisibles.js index f3d120a9e8..3b67c7782b 100644 --- a/plugins/show-invisibles/prism-show-invisibles.js +++ b/plugins/show-invisibles/prism-show-invisibles.js @@ -1,21 +1,80 @@ -(function(){ - -if ( - typeof self !== 'undefined' && !self.Prism || - typeof global !== 'undefined' && !global.Prism -) { - return; -} - -Prism.hooks.add('before-highlight', function(env) { - var tokens = env.grammar; - - if (!tokens) return; - - tokens.tab = /\t/g; - tokens.crlf = /\r\n/g; - tokens.lf = /\n/g; - tokens.cr = /\r/g; - tokens.space = / /g; -}); +(function () { + + if ( + typeof self !== 'undefined' && !self.Prism || + typeof global !== 'undefined' && !global.Prism + ) { + return; + } + + + var invisibles = { + 'tab': /\t/, + 'crlf': /\r\n/, + 'lf': /\n/, + 'cr': /\r/, + 'space': / / + }; + + + /** + * Handles the recursive calling of `addInvisibles` for one token. + * + * @param {Object|Array} tokens The grammar or array which contains the token. + * @param {string|number} name The name or index of the token in `tokens`. + */ + function handleToken(tokens, name) { + var value = tokens[name]; + + var type = Prism.util.type(value); + switch (type) { + case 'RegExp': + var inside = {}; + tokens[name] = { + pattern: value, + inside: inside + }; + addInvisibles(inside); + break; + + case 'Array': + for (var i = 0, l = value.length; i < l; i++) + handleToken(value, i); + break; + + default: // 'Object' + var inside = value.inside || (value.inside = {}); + addInvisibles(inside); + break; + } + } + + /** + * Recursively adds patterns to match invisible characters to the given grammar (if not added already). + * + * @param {Object} grammar + */ + function addInvisibles(grammar) { + if (!grammar || grammar['tab']) + return; + + // assign invisibles here to "mark" the grammar in case of self references + for (var name in invisibles) { + if (invisibles.hasOwnProperty(name)) + grammar[name] = invisibles[name]; + } + + for (var name in grammar) { + if (grammar.hasOwnProperty(name) && !invisibles[name]) { + if (name === 'rest') + addInvisibles(grammar['rest']); + else + handleToken(grammar, name); + } + } + } + + Prism.hooks.add('before-highlight', function (env) { + addInvisibles(env.grammar); + }); })(); diff --git a/plugins/show-invisibles/prism-show-invisibles.min.js b/plugins/show-invisibles/prism-show-invisibles.min.js index 9df7258c89..32de8f2b8f 100644 --- a/plugins/show-invisibles/prism-show-invisibles.min.js +++ b/plugins/show-invisibles/prism-show-invisibles.min.js @@ -1 +1 @@ -!function(){"undefined"!=typeof self&&!self.Prism||"undefined"!=typeof global&&!global.Prism||Prism.hooks.add("before-highlight",function(e){var f=e.grammar;f&&(f.tab=/\t/g,f.crlf=/\r\n/g,f.lf=/\n/g,f.cr=/\r/g,f.space=/ /g)})}(); \ No newline at end of file +!function(){function r(a,i){var n=a[i],t=Prism.util.type(n);switch(t){case"RegExp":var f={};a[i]={pattern:n,inside:f},e(f);break;case"Array":for(var s=0,o=n.length;o>s;s++)r(n,s);break;default:var f=n.inside||(n.inside={});e(f)}}function e(i){if(i&&!i.tab){for(var n in a)a.hasOwnProperty(n)&&(i[n]=a[n]);for(var n in i)i.hasOwnProperty(n)&&!a[n]&&("rest"===n?e(i.rest):r(i,n))}}if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var a={tab:/\t/,crlf:/\r\n/,lf:/\n/,cr:/\r/,space:/ /};Prism.hooks.add("before-highlight",function(r){e(r.grammar)})}}(); \ No newline at end of file From 7a2d153b9be3edd7b54be37cdf47b06276fa2861 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 12 Nov 2018 20:14:19 +0100 Subject: [PATCH 3/4] Revert "Show invisibles inside tokens" This reverts commit 2d622f17e4f6d746e8f4fa211c7f6b7ccb3f27b4. --- .../show-invisibles/prism-show-invisibles.css | 4 +- .../show-invisibles/prism-show-invisibles.js | 99 ++++--------------- .../prism-show-invisibles.min.js | 2 +- 3 files changed, 23 insertions(+), 82 deletions(-) diff --git a/plugins/show-invisibles/prism-show-invisibles.css b/plugins/show-invisibles/prism-show-invisibles.css index 16583b31d9..c57be58812 100644 --- a/plugins/show-invisibles/prism-show-invisibles.css +++ b/plugins/show-invisibles/prism-show-invisibles.css @@ -9,8 +9,8 @@ .token.cr:before, .token.lf:before, .token.space:before { - color: #888; - opacity: 0.6; + color: inherit; + opacity: 0.4; position: absolute; } diff --git a/plugins/show-invisibles/prism-show-invisibles.js b/plugins/show-invisibles/prism-show-invisibles.js index 3b67c7782b..f3d120a9e8 100644 --- a/plugins/show-invisibles/prism-show-invisibles.js +++ b/plugins/show-invisibles/prism-show-invisibles.js @@ -1,80 +1,21 @@ -(function () { - - if ( - typeof self !== 'undefined' && !self.Prism || - typeof global !== 'undefined' && !global.Prism - ) { - return; - } - - - var invisibles = { - 'tab': /\t/, - 'crlf': /\r\n/, - 'lf': /\n/, - 'cr': /\r/, - 'space': / / - }; - - - /** - * Handles the recursive calling of `addInvisibles` for one token. - * - * @param {Object|Array} tokens The grammar or array which contains the token. - * @param {string|number} name The name or index of the token in `tokens`. - */ - function handleToken(tokens, name) { - var value = tokens[name]; - - var type = Prism.util.type(value); - switch (type) { - case 'RegExp': - var inside = {}; - tokens[name] = { - pattern: value, - inside: inside - }; - addInvisibles(inside); - break; - - case 'Array': - for (var i = 0, l = value.length; i < l; i++) - handleToken(value, i); - break; - - default: // 'Object' - var inside = value.inside || (value.inside = {}); - addInvisibles(inside); - break; - } - } - - /** - * Recursively adds patterns to match invisible characters to the given grammar (if not added already). - * - * @param {Object} grammar - */ - function addInvisibles(grammar) { - if (!grammar || grammar['tab']) - return; - - // assign invisibles here to "mark" the grammar in case of self references - for (var name in invisibles) { - if (invisibles.hasOwnProperty(name)) - grammar[name] = invisibles[name]; - } - - for (var name in grammar) { - if (grammar.hasOwnProperty(name) && !invisibles[name]) { - if (name === 'rest') - addInvisibles(grammar['rest']); - else - handleToken(grammar, name); - } - } - } - - Prism.hooks.add('before-highlight', function (env) { - addInvisibles(env.grammar); - }); +(function(){ + +if ( + typeof self !== 'undefined' && !self.Prism || + typeof global !== 'undefined' && !global.Prism +) { + return; +} + +Prism.hooks.add('before-highlight', function(env) { + var tokens = env.grammar; + + if (!tokens) return; + + tokens.tab = /\t/g; + tokens.crlf = /\r\n/g; + tokens.lf = /\n/g; + tokens.cr = /\r/g; + tokens.space = / /g; +}); })(); diff --git a/plugins/show-invisibles/prism-show-invisibles.min.js b/plugins/show-invisibles/prism-show-invisibles.min.js index 32de8f2b8f..9df7258c89 100644 --- a/plugins/show-invisibles/prism-show-invisibles.min.js +++ b/plugins/show-invisibles/prism-show-invisibles.min.js @@ -1 +1 @@ -!function(){function r(a,i){var n=a[i],t=Prism.util.type(n);switch(t){case"RegExp":var f={};a[i]={pattern:n,inside:f},e(f);break;case"Array":for(var s=0,o=n.length;o>s;s++)r(n,s);break;default:var f=n.inside||(n.inside={});e(f)}}function e(i){if(i&&!i.tab){for(var n in a)a.hasOwnProperty(n)&&(i[n]=a[n]);for(var n in i)i.hasOwnProperty(n)&&!a[n]&&("rest"===n?e(i.rest):r(i,n))}}if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var a={tab:/\t/,crlf:/\r\n/,lf:/\n/,cr:/\r/,space:/ /};Prism.hooks.add("before-highlight",function(r){e(r.grammar)})}}(); \ No newline at end of file +!function(){"undefined"!=typeof self&&!self.Prism||"undefined"!=typeof global&&!global.Prism||Prism.hooks.add("before-highlight",function(e){var f=e.grammar;f&&(f.tab=/\t/g,f.crlf=/\r\n/g,f.lf=/\n/g,f.cr=/\r/g,f.space=/ /g)})}(); \ No newline at end of file From 1e1e3bb3ba35d42ea7d6e1ccca3411cc27d22c20 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Wed, 28 Nov 2018 14:53:56 +0100 Subject: [PATCH 4/4] Adjusted title test --- tests/languages/markdown/title_feature.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/languages/markdown/title_feature.test b/tests/languages/markdown/title_feature.test index 58f52d65d0..a06f332636 100644 --- a/tests/languages/markdown/title_feature.test +++ b/tests/languages/markdown/title_feature.test @@ -7,6 +7,9 @@ foobar Überschrift =========== +Überschrift +-- + title 2 -- @@ -23,6 +26,7 @@ title 2 ["title", ["title 1\r\n", ["punctuation", "=="]]], ["title", ["foobar\r\n", ["punctuation", "======"]]], ["title", ["Überschrift\r\n", ["punctuation", "==========="]]], + ["title", ["Überschrift\r\n", ["punctuation", "--"]]], ["title", ["title 2\r\n", ["punctuation", "--"]]], ["title", [["punctuation", "#"], " title 1"]],