rayd / html-parse-stringify2

Parses well-formed HTML (meaning all tags closed) into an AST and back. quickly.
21 stars 11 forks source link

In case "plain text + tags", text is ignored #25

Open maxsimych opened 4 years ago

maxsimych commented 4 years ago

Thank you for this helpful package!

Almost the same problem as #11 still remain: Parsing a plain text node + tags results in an list without plain text. Current behavior:

const lib = require("html-parse-stringify2");
const nodes = lib.parse("Hello, <b>world!</b>");
nodes.length === 1;

Expected behavior:

const lib = require("html-parse-stringify2");
const nodes = lib.parse("Hello, <b>world!</b>")
nodes.length === 2;
nodes[0].type === "text";
nodes[0].content === "Hello, ";
nodes[0].type === "tag";
nodes[0].name === "b";

And the same workaround works:

const parse = function(htmlAndText){
  return lib.parse("<top>" + htmlAndText + "</top>")[0].children;
};