diff --git a/lib/Parser.js b/lib/Parser.js index 4fee3f8f..5b5049b3 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -145,12 +145,13 @@ Parser.prototype.onclosetag = function(name){ while(pos--) this._cbs.onclosetag(this._stack.pop()); } else this._stack.splice(pos); - } else { + } else if (name === "p" && !this._options.xmlMode) { this.onopentagname(name); - this.onopentagend(); - this._stack.pop(); - if(this._cbs.onclosetag) this._cbs.onclosetag(name); + this.onselfclosingtag(); } + } else if ((name === 'br' || name === 'p') && !this._options.xmlMode) { + this.onopentagname(name); + this.onselfclosingtag(); } }; diff --git a/tests/Events/14-close-tag-not-in-stack.json b/tests/Events/14-close-tag-not-in-stack.json deleted file mode 100644 index 040a0a6d..00000000 --- a/tests/Events/14-close-tag-not-in-stack.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Close tags there are not in stack", - "options": { - "handler": {}, - "parser": {} - }, - "html": "
Hallo

World
", - "expected": [ - { "event": "opentagname", "data": [ "div" ] }, - { "event": "opentag", "data": [ "div", {} ] }, - { "event": "text", "data": [ "Hallo" ] }, - { "event": "opentagname", "data": [ "p" ] }, - { "event": "opentag", "data": [ "p", {} ] }, - { "event": "closetag", "data": [ "p" ] }, - { "event": "text", "data": [ "World" ] }, - { "event": "closetag", "data": [ "div" ] } - ] -} \ No newline at end of file diff --git a/tests/Events/14-implicit-open-tags.json b/tests/Events/14-implicit-open-tags.json new file mode 100644 index 00000000..096925ae --- /dev/null +++ b/tests/Events/14-implicit-open-tags.json @@ -0,0 +1,24 @@ +{ + "name": "Implicit open p and br tags", + "options": { + "handler": {}, + "parser": {} + }, + "html": "
Hallo

World

", + "expected": [ + { "event": "opentagname", "data": [ "div" ] }, + { "event": "opentag", "data": [ "div", {} ] }, + { "event": "text", "data": [ "Hallo" ] }, + { "event": "opentagname", "data": [ "p" ] }, + { "event": "opentag", "data": [ "p", {} ] }, + { "event": "closetag", "data": [ "p" ] }, + { "event": "text", "data": [ "World" ] }, + { "event": "opentagname", "data": [ "br" ] }, + { "event": "opentag", "data": [ "br", {} ] }, + { "event": "closetag", "data": [ "br" ] }, + { "event": "closetag", "data": [ "div" ] }, + { "event": "opentagname", "data": [ "p" ] }, + { "event": "opentag", "data": [ "p", {} ] }, + { "event": "closetag", "data": [ "p" ] } + ] +} \ No newline at end of file