diff --git a/src/parse.js b/src/parse.js
index 8caaf64..d141338 100644
--- a/src/parse.js
+++ b/src/parse.js
@@ -48,6 +48,14 @@ export default function parse(html, options) {
}
parent = arr[level]
parent.children.push(comment)
+
+ const text = html.slice(start, html.indexOf('<', start));
+ if (text.length > 0) {
+ parent.children.push({
+ type: 'text',
+ content: text
+ })
+ }
return result
}
diff --git a/test/parse.js b/test/parse.js
index 1ea26bf..c8ba578 100644
--- a/test/parse.js
+++ b/test/parse.js
@@ -227,6 +227,32 @@ test('parse', function (t) {
])
t.equal(html, HTML.stringify(parsed))
+ html = '
Hi Something
'
+ parsed = HTML.parse(html)
+ t.deepEqual(parsed, [
+ {
+ type: "tag",
+ name: "div",
+ voidElement: false,
+ attrs: {},
+ children: [
+ { type: "text", content: " " },
+ { type: "comment", comment: " First comment " },
+ { type: "text", content: " " },
+ {
+ type: "tag",
+ name: "span",
+ voidElement: false,
+ attrs: {},
+ children: [{ type: "text", content: "Hi" }],
+ },
+ { type: "text", content: " " },
+ { type: "comment", comment: " Another comment " },
+ { type: "text", content: " Something" },
+ ],
+ }
+ ])
+
html = 'oh hello there! How are you?
'
parsed = HTML.parse(html)
@@ -850,7 +876,7 @@ test('simple speed sanity check', function (t) {
total += stepAverage
waitCount = waitLoopSize
// forcing a bit of a pause between tests
- while (waitCount--) {}
+ while (waitCount--) { }
}
}
@@ -908,7 +934,7 @@ test('whitespace', function (t) {
children: [
{ type: 'text', content: 'Hi' }
]
- },{
+ }, {
type: 'text',
content: ' '
},
@@ -920,10 +946,10 @@ test('whitespace', function (t) {
children: [
{ type: 'text', content: 'There' }
]
- },{
+ }, {
type: 'text',
content: ' '
- },{
+ }, {
type: 'tag',
name: 'div',
attrs: {},