Comparing version 0.0.5 to 0.1.0
# ultrahtml | ||
## 0.1.0 | ||
### Minor Changes | ||
- 517e24d: Fix edge cases with text node detection, refactor for compactness | ||
## 0.0.5 | ||
@@ -4,0 +10,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
let str = typeof input === "string" ? input : input.value; | ||
let doc, parent, prev, token, text, i, bStart, bText, bEnd, tag; | ||
let doc, parent, token, text, i, bStart, bText, bEnd, tag; | ||
const tags = []; | ||
@@ -34,16 +34,11 @@ DOM_PARSER_RE.lastIndex = 0; | ||
}; | ||
let lastIndex = 0; | ||
function commitTextNode() { | ||
if (parent && tags.length > 0) { | ||
prev = tags[tags.length - 1]; | ||
i = (prev.loc[1] || prev.loc[0]).end; | ||
if (prev.parent === parent && i && i < tag.loc[0].start) { | ||
text = str.substring(i, tag.loc[0].start); | ||
if (text) { | ||
parent.children.push({ | ||
type: TEXT_NODE, | ||
value: text, | ||
parent | ||
}); | ||
} | ||
} | ||
text = str.substring(lastIndex, DOM_PARSER_RE.lastIndex - token[0].length); | ||
if (text) { | ||
parent.children.push({ | ||
type: TEXT_NODE, | ||
value: text, | ||
parent | ||
}); | ||
} | ||
@@ -72,3 +67,2 @@ } | ||
}; | ||
commitTextNode(); | ||
tags.push(tag); | ||
@@ -93,6 +87,6 @@ tag.parent.children.push(tag); | ||
}; | ||
commitTextNode(); | ||
tags.push(tag); | ||
tag.parent.children.push(tag); | ||
} else if (token[1] !== "/") { | ||
commitTextNode(); | ||
tag = { | ||
@@ -111,3 +105,2 @@ type: ELEMENT_NODE, | ||
}; | ||
commitTextNode(); | ||
tags.push(tag); | ||
@@ -122,2 +115,3 @@ tag.parent.children.push(tag); | ||
} else { | ||
commitTextNode(); | ||
if (token[2] + "" === parent.name) { | ||
@@ -146,10 +140,10 @@ tag = parent; | ||
} | ||
lastIndex = DOM_PARSER_RE.lastIndex; | ||
} | ||
if (doc.children.length === 0) { | ||
doc.children.push({ | ||
type: TEXT_NODE, | ||
value: str, | ||
parent | ||
}); | ||
} | ||
text = str.slice(lastIndex); | ||
parent.children.push({ | ||
type: TEXT_NODE, | ||
value: text, | ||
parent | ||
}); | ||
return doc; | ||
@@ -156,0 +150,0 @@ } |
{ | ||
"name": "ultrahtml", | ||
"type": "module", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"types": "./dist/index.d.ts", | ||
@@ -41,2 +41,3 @@ "repository": { | ||
"esbuild": "^0.14.51", | ||
"markdown-it": "^13.0.1", | ||
"prettier": "^2.5.1", | ||
@@ -43,0 +44,0 @@ "typescript": "^4.7.4", |
17827
6
413