diff --git a/src/html/parser.ts b/src/html/parser.ts index 7db37671..5d4ba6b0 100644 --- a/src/html/parser.ts +++ b/src/html/parser.ts @@ -31,7 +31,7 @@ import { } from "./util/attribute-names" import { HTML_CAN_BE_LEFT_OPEN_TAGS, - HTML_NON_FHRASING_TAGS, + HTML_NON_PHRASING_TAGS, HTML_RAWTEXT_TAGS, HTML_RCDATA_TAGS, HTML_VOID_ELEMENT_TAGS, @@ -376,7 +376,7 @@ export class Parser { return } - if (element.name === "p" && HTML_NON_FHRASING_TAGS.has(name)) { + if (element.name === "p" && HTML_NON_PHRASING_TAGS.has(name)) { this.popElementStack() } if (element.name === name && HTML_CAN_BE_LEFT_OPEN_TAGS.has(name)) { diff --git a/src/html/util/tag-names.ts b/src/html/util/tag-names.ts index 5a629f3c..ebf10b7a 100644 --- a/src/html/util/tag-names.ts +++ b/src/html/util/tag-names.ts @@ -43,13 +43,13 @@ export const HTML_CAN_BE_LEFT_OPEN_TAGS = new Set([ /** * https://github.com/vuejs/vue/blob/e4da249ab8ef32a0b8156c840c9d2b9773090f8a/src/platforms/web/compiler/util.js#L18 */ -export const HTML_NON_FHRASING_TAGS = new Set([ +export const HTML_NON_PHRASING_TAGS = new Set([ "address", "article", "aside", "base", "blockquote", "body", "caption", "col", "colgroup", "dd", "details", "dialog", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "legend", "li", "menuitem", "meta", "optgroup", "option", "param", "rp", "rt", "source", "style", - "summary", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track", + "summary", "table", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track", ]) /** diff --git a/test/fixtures/ast/auto-closing-p/ast.json b/test/fixtures/ast/auto-closing-p/ast.json index 6c02afe0..3edda9f4 100644 --- a/test/fixtures/ast/auto-closing-p/ast.json +++ b/test/fixtures/ast/auto-closing-p/ast.json @@ -24,7 +24,7 @@ "type": "VElement", "range": [ 0, - 107 + 147 ], "loc": { "start": { @@ -32,7 +32,7 @@ "column": 0 }, "end": { - "line": 7, + "line": 9, "column": 11 } }, @@ -382,7 +382,7 @@ "type": "VText", "range": [ 95, - 96 + 100 ], "loc": { "start": { @@ -391,6 +391,143 @@ }, "end": { "line": 7, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 100, + 120 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "name": "p", + "rawName": "p", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 103, + 120 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "value": "4th sentence\n " + } + ], + "endTag": null, + "variables": [] + }, + { + "type": "VElement", + "range": [ + 120, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "name": "table", + "rawName": "table", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 120, + 127 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 127, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 9, "column": 0 } }, @@ -400,16 +537,16 @@ "endTag": { "type": "VEndTag", "range": [ - 96, - 107 + 136, + 147 ], "loc": { "start": { - "line": 7, + "line": 9, "column": 0 }, "end": { - "line": 7, + "line": 9, "column": 11 } } @@ -924,7 +1061,7 @@ "type": "HTMLWhitespace", "range": [ 95, - 96 + 100 ], "loc": { "start": { @@ -933,31 +1070,67 @@ }, "end": { "line": 7, - "column": 0 + "column": 4 } }, - "value": "\n" + "value": "\n " }, { - "type": "HTMLEndTagOpen", + "type": "HTMLTagOpen", + "range": [ + 100, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "value": "p" + }, + { + "type": "HTMLTagClose", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLText", "range": [ - 96, + 103, 106 ], "loc": { "start": { "line": 7, - "column": 0 + "column": 7 }, "end": { "line": 7, "column": 10 } }, - "value": "template" + "value": "4th" }, { - "type": "HTMLTagClose", + "type": "HTMLWhitespace", "range": [ 106, 107 @@ -972,21 +1145,183 @@ "column": 11 } }, - "value": "" + "value": " " }, { - "type": "HTMLWhitespace", + "type": "HTMLText", "range": [ 107, - 108 + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "value": "sentence" + }, + { + "type": "HTMLWhitespace", + "range": [ + 115, + 120 ], "loc": { "start": { "line": 7, + "column": 19 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 120, + 126 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "table" + }, + { + "type": "HTMLTagClose", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 127, + 134 + ], + "loc": { + "start": { + "line": 8, "column": 11 }, "end": { "line": 8, + "column": 18 + } + }, + "value": "table" + }, + { + "type": "HTMLTagClose", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 136, + 146 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 10, "column": 0 } }, diff --git a/test/fixtures/ast/auto-closing-p/source.vue b/test/fixtures/ast/auto-closing-p/source.vue index f3488ded..65bcc9a2 100644 --- a/test/fixtures/ast/auto-closing-p/source.vue +++ b/test/fixtures/ast/auto-closing-p/source.vue @@ -4,4 +4,6 @@
3rd sentence
+4th sentence +
", + "4th", + " ", + "sentence", + "\n ", + "
1th sentence\n
2nd sentence\n
3rd sentence\n
\n", + "text": "\n1th sentence\n
2nd sentence\n
3rd sentence\n
\n4th sentence\n
4th sentence\n ", + "children": [ + { + "type": "VStartTag", + "text": "
", + "children": [] + }, + { + "type": "VText", + "text": "4th sentence\n ", + "children": [] + } + ] + }, + { + "type": "VElement", + "text": "