Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markup: Added tokens inside DOCTYPE #2349

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions components/prism-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ Prism.languages.markup = {
'comment': /<!--[\s\S]*?-->/,
'prolog': /<\?[\s\S]+?\?>/,
'doctype': {
// https://www.w3.org/TR/xml/#NT-doctypedecl
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
greedy: true
greedy: true,
inside: {
'internal-subset': {
pattern: /(\[)[\s\S]+(?=\]>$)/,
lookbehind: true,
greedy: true,
inside: null // see below
},
'string': {
pattern: /"[^"]*"|'[^']*'/,
greedy: true
},
'punctuation': /^<!|>$|[[\]]/,
'doctype-tag': /^DOCTYPE/,
'name': /[^\s<>'"]+/
}
},
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
'tag': {
Expand Down Expand Up @@ -50,9 +66,10 @@ Prism.languages.markup = {

Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
Prism.languages.markup['entity'];
Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;

// Plugin to make entity title show the real entity, idea by Roman Komarov
Prism.hooks.add('wrap', function(env) {
Prism.hooks.add('wrap', function (env) {

if (env.type === 'entity') {
env.attributes['title'] = env.content.replace(/&amp;/, '&');
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.

21 changes: 19 additions & 2 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,24 @@ Prism.languages.markup = {
'comment': /<!--[\s\S]*?-->/,
'prolog': /<\?[\s\S]+?\?>/,
'doctype': {
// https://www.w3.org/TR/xml/#NT-doctypedecl
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
greedy: true
greedy: true,
inside: {
'internal-subset': {
pattern: /(\[)[\s\S]+(?=\]>$)/,
lookbehind: true,
greedy: true,
inside: null // see below
},
'string': {
pattern: /"[^"]*"|'[^']*'/,
greedy: true
},
'punctuation': /^<!|>$|[[\]]/,
'doctype-tag': /^DOCTYPE/,
'name': /[^\s<>'"]+/
}
},
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
'tag': {
Expand Down Expand Up @@ -786,9 +802,10 @@ Prism.languages.markup = {

Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
Prism.languages.markup['entity'];
Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;

// Plugin to make entity title show the real entity, idea by Roman Komarov
Prism.hooks.add('wrap', function(env) {
Prism.hooks.add('wrap', function (env) {

if (env.type === 'entity') {
env.attributes['title'] = env.content.replace(/&amp;/, '&');
Expand Down
97 changes: 91 additions & 6 deletions tests/languages/markup/doctype_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,97 @@
----------------------------------------------------

[
["doctype", "<!DOCTYPE html>"],
["doctype", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"],
["doctype", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\r\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"],
["doctype", "<!DOCTYPE greeting SYSTEM \"hello.dtd\">"],
["doctype", "<!DOCTYPE greeting [\r\n\t<!ELEMENT greeting (#PCDATA)>\r\n]>"],
["doctype", "<!DOCTYPE greeting [\r\n\t<!ELEMENT greeting (#PCDATA)>\r\n\t<!ELEMENT subject (#PCDATA)>\r\n\t<!-- comment ]> -->\r\n]>"]
["doctype", [
["punctuation", "<!"],
["doctype-tag", "DOCTYPE"],
["name", "html"],
["punctuation", ">"]
]],
["doctype", [
["punctuation", "<!"],
["doctype-tag", "DOCTYPE"],
["name", "HTML"],
["name", "PUBLIC"],
["string", "\"-//W3C//DTD HTML 4.01//EN\""],
["punctuation", ">"]
]],
["doctype", [
["punctuation", "<!"],
["doctype-tag", "DOCTYPE"],
["name", "html"],
["name", "PUBLIC"],
["string", "\"-//W3C//DTD XHTML 1.0 Strict//EN\""],
["string", "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""],
["punctuation", ">"]
]],
["doctype", [
["punctuation", "<!"],
["doctype-tag", "DOCTYPE"],
["name", "greeting"],
["name", "SYSTEM"],
["string", "\"hello.dtd\""],
["punctuation", ">"]
]],
["doctype", [
["punctuation", "<!"],
["doctype-tag", "DOCTYPE"],
["name", "greeting"],
["punctuation", "["],
["internal-subset", [
["tag", [
["tag", [
["punctuation", "<"],
"!ELEMENT"
]],
["attr-name", [
"greeting"
]],
["attr-name", [
"(#PCDATA)"
]],
["punctuation", ">"]
]]
]],
["punctuation", "]"],
["punctuation", ">"]
]],
["doctype", [
["punctuation", "<!"],
["doctype-tag", "DOCTYPE"],
["name", "greeting"],
["punctuation", "["],
["internal-subset", [
["tag", [
["tag", [
["punctuation", "<"],
"!ELEMENT"
]],
["attr-name", [
"greeting"
]],
["attr-name", [
"(#PCDATA)"
]],
["punctuation", ">"]
]],
["tag", [
["tag", [
["punctuation", "<"],
"!ELEMENT"
]],
["attr-name", [
"subject"
]],
["attr-name", [
"(#PCDATA)"
]],
["punctuation", ">"]
]],
["comment", "<!-- comment ]> -->"]
]],
["punctuation", "]"],
["punctuation", ">"]
]]
]

----------------------------------------------------
Expand Down