-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathtext.js
More file actions
50 lines (45 loc) · 1.23 KB
/
text.js
File metadata and controls
50 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const {TEXT_NODE} = require('../shared/constants.js');
const {VALUE, MIME} = require('../shared/symbols.js');
const {escape} = require('../shared/text-escaper.js');
const {CharacterData} = require('./character-data.js');
/**
* @implements globalThis.Text
*/
class Text extends CharacterData {
constructor(ownerDocument, data = '') {
super(ownerDocument, '#text', TEXT_NODE, data);
}
get wholeText() {
const text = [];
let {previousSibling, nextSibling} = this;
while (previousSibling) {
if (previousSibling.nodeType === TEXT_NODE)
text.unshift(previousSibling[VALUE]);
else
break;
previousSibling = previousSibling.previousSibling;
}
text.push(this[VALUE]);
while (nextSibling) {
if (nextSibling.nodeType === TEXT_NODE)
text.push(nextSibling[VALUE]);
else
break;
nextSibling = nextSibling.nextSibling;
}
return text.join('');
}
cloneNode() {
const {ownerDocument, [VALUE]: data} = this;
return new Text(ownerDocument, data);
}
toString() {
const {ownerDocument} = this;
if (ownerDocument[MIME].escapeHtmlEntities) {
return escape(this[VALUE]);
}
return this[VALUE];
}
}
exports.Text = Text