Commit 577a5890144a257008962fa1e5178a2e90308301

Lea Verou 2012-11-12T05:35:39

Fixed HTML highlighting bugs

diff --git a/components/prism-markup.js b/components/prism-markup.js
index 8fbb95d..1e03283 100644
--- a/components/prism-markup.js
+++ b/components/prism-markup.js
@@ -4,7 +4,7 @@ Prism.languages.markup = {
 	'doctype': /<!DOCTYPE.+?>/,
 	'cdata': /<!\[CDATA\[[\w\W]+?]]>/i,
 	'tag': {
-		pattern: /<\/?[\w:-]+\s*[\w\W]*?>/gi,
+		pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*>/gi,
 		inside: {
 			'tag': {
 				pattern: /^<\/?[\w:-]+/i,
@@ -14,9 +14,9 @@ Prism.languages.markup = {
 				}
 			},
 			'attr-value': {
-				pattern: /=(('|")[\w\W]*?(\2)|[^\s>]+)/gi,
+				pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,
 				inside: {
-					'punctuation': /=/g
+					'punctuation': /=|>|"/g
 				}
 			},
 			'punctuation': /\/?>/g,
diff --git a/components/prism-markup.min.js b/components/prism-markup.min.js
index bee2965..f5299a5 100644
--- a/components/prism-markup.min.js
+++ b/components/prism-markup.min.js
@@ -1 +1 @@
-Prism.languages.markup={comment:/<!--[\w\W]*?--(>|>)/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]+?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*[\w\W]*?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(('|")[\w\W]*?(\2)|[^\s>]+)/gi,inside:{punctuation:/=/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(e){e.type==="entity"&&(e.attributes.title=e.content.replace(/&/,"&"))});
\ No newline at end of file
+Prism.languages.markup={comment:/<!--[\w\W]*?--(>|>)/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]+?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(e){e.type==="entity"&&(e.attributes.title=e.content.replace(/&/,"&"))});
\ No newline at end of file
diff --git a/examples.html b/examples.html
index 9094064..da51b27 100644
--- a/examples.html
+++ b/examples.html
@@ -121,6 +121,14 @@ And i'm not</code></pre>
 	
 &lt;/body>
 &lt;/html></code></pre>
+
+	<h2>Invalid HTML</h2>
+	<pre><code>&lt;l &lt;/ul></code></pre>
+	
+	<h2>Multi-line attribute values</h2>
+	<pre><code>&lt;p title="foo
+bar
+baz"></code></pre>
 </section>
 
 <section class="language-css">
diff --git a/prism.js b/prism.js
index 4e9383f..a8e3111 100644
--- a/prism.js
+++ b/prism.js
@@ -364,7 +364,7 @@ Prism.languages.markup = {
 	'doctype': /&lt;!DOCTYPE.+?&gt;/,
 	'cdata': /&lt;!\[CDATA\[[\w\W]+?]]&gt;/i,
 	'tag': {
-		pattern: /&lt;\/?[\w:-]+\s*[\w\W]*?&gt;/gi,
+		pattern: /&lt;\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*&gt;/gi,
 		inside: {
 			'tag': {
 				pattern: /^&lt;\/?[\w:-]+/i,
@@ -374,9 +374,9 @@ Prism.languages.markup = {
 				}
 			},
 			'attr-value': {
-				pattern: /=(('|")[\w\W]*?(\2)|[^\s>]+)/gi,
+				pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,
 				inside: {
-					'punctuation': /=/g
+					'punctuation': /=|&gt;|"/g
 				}
 			},
 			'punctuation': /\/?&gt;/g,