als-document 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,12 +3,9 @@ class Document extends Node {
3
3
  super('ROOT',{},null);
4
4
  this.isSingle = false
5
5
  this.URL = url
6
- if(html instanceof Document) {
7
- this.childNodes = [...buildFromCache(cacheDoc(html)).childNodes]
8
- // this.innerHTML = html.innerHTML
9
- }
6
+ if(html instanceof Document) this.childNodes = [...buildFromCache(cacheDoc(html)).childNodes]
10
7
  else if(typeof html === 'string') this.innerHTML = html
11
- else this.body // create innerHTML
8
+ else this.html // create innerHTML
12
9
  }
13
10
 
14
11
  get documentElement() {return this.html}
@@ -25,26 +22,26 @@ class Document extends Node {
25
22
  set innerHTML(html) {return super.innerHTML = html}
26
23
 
27
24
  get head() {
28
- const head = this.$('head')
25
+ const head = this.html.$('head')
29
26
  if(head === null) this.html.insert(1,'<head></head>')
30
27
  return this.$('head')
31
28
  }
32
29
 
33
30
  get body() {
34
- const body = this.$('body')
31
+ const body = this.html.$('body')
35
32
  if(body === null) this.head.insert(3,'<body></body>')
36
33
  return this.$('body')
37
34
  }
38
35
 
39
36
  get title() {
40
- const title = this.$('title')
37
+ const title = this.head.$('title')
41
38
  if(title === null) this.head.insert(1,'<title></title>')
42
39
  return this.$('title').innerText
43
40
  }
44
41
 
45
42
  get charset() {return this.$('meta[charset]')}
46
43
 
47
- set title(title) {return this.$('title').innerText = title}
44
+ set title(title) {return this.head.$('title').innerText = title}
48
45
 
49
46
  get clone() {return new Document(this)}
50
47
  }
@@ -26,6 +26,7 @@ function parseHTML(html) {
26
26
 
27
27
  function parseSpecial(startStr, endStr, n1, n2, tag) {
28
28
  if (!html.startsWith(startStr, i)) return false
29
+ if(currentText.length) stack[stack.length - 1].childNodes.push(new TextNode(currentText)); // new!
29
30
  const end = html.indexOf(endStr, i + n1);
30
31
  const strNode = new Node(tag, {}, stack[stack.length - 1]);
31
32
  strNode.childNodes.push(html.substring(i + n1, end));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-document",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "A powerful HTML parser & DOM manipulation library for both backend and frontend.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",