From 0a3932fe614c95eecc7dbccb39ccd489a5c6b0b2 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Wed, 30 Dec 2020 17:43:57 +0100 Subject: [PATCH] C-like: Made all comments greedy (#2680) --- components/prism-clike.js | 3 ++- components/prism-clike.min.js | 2 +- components/prism-coffeescript.js | 8 ++++++-- components/prism-coffeescript.min.js | 2 +- prism.js | 3 ++- .../coffeescript/inline-javascript_feature.test | 16 ++++++++++------ 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/components/prism-clike.js b/components/prism-clike.js index c9354061cb..f1d9b90aec 100644 --- a/components/prism-clike.js +++ b/components/prism-clike.js @@ -2,7 +2,8 @@ Prism.languages.clike = { 'comment': [ { pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, - lookbehind: true + lookbehind: true, + greedy: true }, { pattern: /(^|[^\\:])\/\/.*/, diff --git a/components/prism-clike.min.js b/components/prism-clike.min.js index 21f61bb455..72c5e2ebff 100644 --- a/components/prism-clike.min.js +++ b/components/prism-clike.min.js @@ -1 +1 @@ -Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,boolean:/\b(?:true|false)\b/,function:/\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}; \ No newline at end of file +Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,boolean:/\b(?:true|false)\b/,function:/\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}; \ No newline at end of file diff --git a/components/prism-coffeescript.js b/components/prism-coffeescript.js index db6ad7ba03..f1d52fb369 100644 --- a/components/prism-coffeescript.js +++ b/components/prism-coffeescript.js @@ -58,7 +58,11 @@ Prism.languages.insertBefore('coffeescript', 'string', { pattern: /^`|`$/, alias: 'punctuation' }, - rest: Prism.languages.javascript + 'script': { + pattern: /[\s\S]+/, + alias: 'language-javascript', + inside: Prism.languages.javascript + } } }, @@ -89,4 +93,4 @@ Prism.languages.insertBefore('coffeescript', 'keyword', { delete Prism.languages.coffeescript['template-string']; Prism.languages.coffee = Prism.languages.coffeescript; -}(Prism)); \ No newline at end of file +}(Prism)); diff --git a/components/prism-coffeescript.min.js b/components/prism-coffeescript.min.js index 95daa2a04d..e2fd36e8ce 100644 --- a/components/prism-coffeescript.min.js +++ b/components/prism-coffeescript.min.js @@ -1 +1 @@ -!function(e){var t=/#(?!\{).+/,n={pattern:/#\{[^}]+\}/,alias:"variable"};e.languages.coffeescript=e.languages.extend("javascript",{comment:t,string:[{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,inside:{interpolation:n}}],keyword:/\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,"class-member":{pattern:/@(?!\d)\w+/,alias:"variable"}}),e.languages.insertBefore("coffeescript","comment",{"multiline-comment":{pattern:/###[\s\S]+?###/,alias:"comment"},"block-regex":{pattern:/\/{3}[\s\S]*?\/{3}/,alias:"regex",inside:{comment:t,interpolation:n}}}),e.languages.insertBefore("coffeescript","string",{"inline-javascript":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,inside:{delimiter:{pattern:/^`|`$/,alias:"punctuation"},rest:e.languages.javascript}},"multiline-string":[{pattern:/'''[\s\S]*?'''/,greedy:!0,alias:"string"},{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string",inside:{interpolation:n}}]}),e.languages.insertBefore("coffeescript","keyword",{property:/(?!\d)\w+(?=\s*:(?!:))/}),delete e.languages.coffeescript["template-string"],e.languages.coffee=e.languages.coffeescript}(Prism); \ No newline at end of file +!function(e){var t=/#(?!\{).+/,n={pattern:/#\{[^}]+\}/,alias:"variable"};e.languages.coffeescript=e.languages.extend("javascript",{comment:t,string:[{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,inside:{interpolation:n}}],keyword:/\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,"class-member":{pattern:/@(?!\d)\w+/,alias:"variable"}}),e.languages.insertBefore("coffeescript","comment",{"multiline-comment":{pattern:/###[\s\S]+?###/,alias:"comment"},"block-regex":{pattern:/\/{3}[\s\S]*?\/{3}/,alias:"regex",inside:{comment:t,interpolation:n}}}),e.languages.insertBefore("coffeescript","string",{"inline-javascript":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,inside:{delimiter:{pattern:/^`|`$/,alias:"punctuation"},script:{pattern:/[\s\S]+/,alias:"language-javascript",inside:e.languages.javascript}}},"multiline-string":[{pattern:/'''[\s\S]*?'''/,greedy:!0,alias:"string"},{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string",inside:{interpolation:n}}]}),e.languages.insertBefore("coffeescript","keyword",{property:/(?!\d)\w+(?=\s*:(?!:))/}),delete e.languages.coffeescript["template-string"],e.languages.coffee=e.languages.coffeescript}(Prism); \ No newline at end of file diff --git a/prism.js b/prism.js index a302eda0a4..03688507c1 100644 --- a/prism.js +++ b/prism.js @@ -1432,7 +1432,8 @@ Prism.languages.clike = { 'comment': [ { pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, - lookbehind: true + lookbehind: true, + greedy: true }, { pattern: /(^|[^\\:])\/\/.*/, diff --git a/tests/languages/coffeescript/inline-javascript_feature.test b/tests/languages/coffeescript/inline-javascript_feature.test index cf15e26c0a..c6fbd2fcc3 100644 --- a/tests/languages/coffeescript/inline-javascript_feature.test +++ b/tests/languages/coffeescript/inline-javascript_feature.test @@ -7,16 +7,20 @@ JS here */` [ ["inline-javascript", [ ["delimiter", "`"], - ["comment", "/* JS here */"], + ["script", [ + ["comment", "/* JS here */"] + ]], ["delimiter", "`"] ]], ["inline-javascript", [ - ["delimiter", "`"], - ["comment", "/*\r\nJS here */"], - ["delimiter", "`"] - ]] + ["delimiter", "`"], + ["script", [ + ["comment", "/*\r\nJS here */"] + ]], + ["delimiter", "`"] + ]] ] ---------------------------------------------------- -Checks for inline JavaScript. \ No newline at end of file +Checks for inline JavaScript.