correctly parse HTML4 nested inline elements (#861)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 17 Oct 2017 21:58:48 +0000 (05:58 +0800)
committerGitHub <noreply@github.com>
Tue, 17 Oct 2017 21:58:48 +0000 (05:58 +0800)
fixes #857

src/htmlparser.js
tests/minifier.js

index 74695a0..7b54b9d 100644 (file)
@@ -270,7 +270,7 @@ function HTMLParser(html, handler) {
       parseEndTag('', lastTag);
     }
 
-    if (!handler.html5) {
+    if (!handler.html5 && !inline(tagName)) {
       while (lastTag && inline(lastTag)) {
         parseEndTag('', lastTag);
       }
index ca9b2c7..337d781 100644 (file)
@@ -1635,6 +1635,16 @@ QUnit.test('custom components', function(assert) {
   assert.equal(minify(input), output);
 });
 
+QUnit.test('HTML4: anchor with inline elements', function(assert) {
+  var input = '<a href="#"><span>Well, look at me! I\'m a span!</span></a>';
+  assert.equal(minify(input, { html5: false }), input);
+});
+
+QUnit.test('HTML5: anchor with inline elements', function(assert) {
+  var input = '<a href="#"><span>Well, look at me! I\'m a span!</span></a>';
+  assert.equal(minify(input, { html5: true }), input);
+});
+
 QUnit.test('HTML4: anchor with block elements', function(assert) {
   var input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
   var output = '<a href="#"></a><div>Well, look at me! I\'m a div!</div>';