Skip to content

Commit

Permalink
Markup addInline improvements (#1798)
Browse files Browse the repository at this point in the history
This makes some minor improvements to the new `addInline` function of markup.
  • Loading branch information
RunDevelopment committed Mar 10, 2019
1 parent b2298b1 commit af67c32
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 49 deletions.
30 changes: 15 additions & 15 deletions components/prism-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
* addInlined('style', 'css');
*/
value: function addInlined(tagName, lang) {
var inside = {};
var includedCdataInside = {};
includedCdataInside['language-' + lang] = {
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
lookbehind: true,
inside: Prism.languages[lang]
};
includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;

var inside = {
'included-cdata': {
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
inside: includedCdataInside
}
};
inside['language-' + lang] = {
pattern: /[\s\S]+/,
inside: Prism.languages[lang]
Expand All @@ -74,20 +87,7 @@ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[[\s\S]*?\]\]>\s*|[\s\S])*?(?=<\/__>)/.source.replace(/__/g, tagName), 'i'),
lookbehind: true,
greedy: true,
inside: {
'included-cdata': {
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
inside: {
'content': {
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
lookbehind: true,
inside: inside
},
'cdata': /^<!\[CDATA\[|\]\]>$/i
}
},
rest: inside
}
inside: inside
};

Prism.languages.insertBefore('markup', 'cdata', def);
Expand Down
2 changes: 1 addition & 1 deletion components/prism-markup.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,20 @@ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
* addInlined('style', 'css');
*/
value: function addInlined(tagName, lang) {
var inside = {};
var includedCdataInside = {};
includedCdataInside['language-' + lang] = {
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
lookbehind: true,
inside: Prism.languages[lang]
};
includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;

var inside = {
'included-cdata': {
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
inside: includedCdataInside
}
};
inside['language-' + lang] = {
pattern: /[\s\S]+/,
inside: Prism.languages[lang]
Expand All @@ -638,20 +651,7 @@ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[[\s\S]*?\]\]>\s*|[\s\S])*?(?=<\/__>)/.source.replace(/__/g, tagName), 'i'),
lookbehind: true,
greedy: true,
inside: {
'included-cdata': {
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
inside: {
'content': {
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
lookbehind: true,
inside: inside
},
'cdata': /^<!\[CDATA\[|\]\]>$/i
}
},
rest: inside
}
inside: inside
};

Prism.languages.insertBefore('markup', 'cdata', def);
Expand Down
18 changes: 8 additions & 10 deletions tests/languages/markup!+css/css_inclusion.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ foo {
]],
["included-cdata", [
["cdata", "<![CDATA["],
["content", [
["language-css", [
["selector", "foo"],
["punctuation", "{"],
["property", "bar"],
["punctuation", ":"],
" baz",
["punctuation", ";"],
["punctuation", "}"]
]]
["language-css", [
["selector", "foo"],
["punctuation", "{"],
["property", "bar"],
["punctuation", ":"],
" baz",
["punctuation", ";"],
["punctuation", "}"]
]],
["cdata", "]]>"]
]],
Expand Down
14 changes: 6 additions & 8 deletions tests/languages/markup!+javascript/javascript_inclusion.test
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ let foo = '</script>';
]],
["included-cdata", [
["cdata", "<![CDATA["],
["content", [
["language-javascript", [
["keyword", "let"],
" foo ",
["operator", "="],
["string", "'</script>'"],
["punctuation", ";"]
]]
["language-javascript", [
["keyword", "let"],
" foo ",
["operator", "="],
["string", "'</script>'"],
["punctuation", ";"]
]],
["cdata", "]]>"]
]],
Expand Down

0 comments on commit af67c32

Please sign in to comment.