From 52fd55ee6ac8cfd01bdecaa63a47554810c8b8fa Mon Sep 17 00:00:00 2001 From: Golmote Date: Fri, 12 Jun 2015 20:20:41 +0200 Subject: [PATCH] Relax markup grammar to allow non-ASCII chars in tag names and attributes. Fix #585 --- components/prism-markup.js | 10 +++++----- components/prism-markup.min.js | 2 +- examples/prism-markup.html | 7 ++++++- prism.js | 10 +++++----- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/components/prism-markup.js b/components/prism-markup.js index f4ab4f3651..febdc98171 100644 --- a/components/prism-markup.js +++ b/components/prism-markup.js @@ -4,13 +4,13 @@ Prism.languages.markup = { 'doctype': //, 'cdata': //i, 'tag': { - pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i, + pattern: /<\/?[^\s>\/]+\s*(?:\s+[^\s>\/=]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i, inside: { 'tag': { - pattern: /^<\/?[\w:-]+/i, + pattern: /^<\/?[^\s>\/]+/i, inside: { 'punctuation': /^<\/?/, - 'namespace': /^[\w-]+?:/ + 'namespace': /^[^\s>\/:]+:/ } }, 'attr-value': { @@ -21,9 +21,9 @@ Prism.languages.markup = { }, 'punctuation': /\/?>/, 'attr-name': { - pattern: /[\w:-]+/, + pattern: /[^\s>\/]+/, inside: { - 'namespace': /^[\w-]+?:/ + 'namespace': /^[^\s>\/:]+:/ } } diff --git a/components/prism-markup.min.js b/components/prism-markup.min.js index fbf30552b9..dece1fb7eb 100644 --- a/components/prism-markup.min.js +++ b/components/prism-markup.min.js @@ -1 +1 @@ -Prism.languages.markup={comment://,prolog:/<\?.+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/=|>|"/}},punctuation:/\/?>/,"attr-name":{pattern:/[\w:-]+/,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(t){"entity"===t.type&&(t.attributes.title=t.content.replace(/&/,"&"))}); \ No newline at end of file +Prism.languages.markup={comment://,prolog:/<\?.+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?[^\s>\/]+\s*(?:\s+[^\s>\/=]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/=|>|"/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(t){"entity"===t.type&&(t.attributes.title=t.content.replace(/&/,"&"))}); \ No newline at end of file diff --git a/examples/prism-markup.html b/examples/prism-markup.html index d3a333c76d..7709c025fd 100644 --- a/examples/prism-markup.html +++ b/examples/prism-markup.html @@ -72,4 +72,9 @@

Invalid HTML

Multi-line attribute values

<p title="foo
 bar
-baz">
\ No newline at end of file +baz"> + +

XML tags with non-ASCII characters

+
<Läufer>foo</Läufer>
+<tag läufer="läufer">bar</tag>
+<läufer:tag>baz</läufer:tag>
\ No newline at end of file diff --git a/prism.js b/prism.js index e74f7cd746..ace59c0437 100644 --- a/prism.js +++ b/prism.js @@ -441,13 +441,13 @@ Prism.languages.markup = { 'doctype': //, 'cdata': //i, 'tag': { - pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i, + pattern: /<\/?[^\s>\/]+\s*(?:\s+[^\s>\/=]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i, inside: { 'tag': { - pattern: /^<\/?[\w:-]+/i, + pattern: /^<\/?[^\s>\/]+/i, inside: { 'punctuation': /^<\/?/, - 'namespace': /^[\w-]+?:/ + 'namespace': /^[^\s>\/:]+:/ } }, 'attr-value': { @@ -458,9 +458,9 @@ Prism.languages.markup = { }, 'punctuation': /\/?>/, 'attr-name': { - pattern: /[\w:-]+/, + pattern: /[^\s>\/]+/, inside: { - 'namespace': /^[\w-]+?:/ + 'namespace': /^[^\s>\/:]+:/ } }