@tkeron/html-parser 0.1.5 → 1.0.0
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.
- package/README.md +1 -7
- package/bun.lock +8 -3
- package/index.ts +4 -0
- package/package.json +13 -6
- package/src/css-selector.ts +45 -27
- package/src/dom-simulator.ts +162 -20
- package/src/encoding.ts +39 -0
- package/src/index.ts +9 -0
- package/src/parser.ts +478 -183
- package/src/serializer.ts +450 -0
- package/src/tokenizer.ts +59 -139
- package/tests/advanced.test.ts +119 -106
- package/tests/custom-elements.test.ts +172 -162
- package/tests/dom-extended.test.ts +12 -12
- package/tests/dom-manipulation.test.ts +637 -0
- package/tests/dom.test.ts +32 -27
- package/tests/helpers/tokenizer-adapter.test.ts +70 -0
- package/tests/helpers/tokenizer-adapter.ts +65 -0
- package/tests/helpers/tree-adapter.test.ts +39 -0
- package/tests/helpers/tree-adapter.ts +43 -0
- package/tests/html5lib-data/tokenizer/namedEntities.test +42422 -0
- package/tests/html5lib-data/tokenizer/pendingSpecChanges.test +9 -0
- package/tests/html5lib-data/tree-construction/adoption01.dat +354 -0
- package/tests/html5lib-data/tree-construction/adoption02.dat +39 -0
- package/tests/html5lib-data/tree-construction/domjs-unsafe.dat +0 -0
- package/tests/html5lib-data/tree-construction/entities02.dat +309 -0
- package/tests/html5lib-data/tree-construction/html5test-com.dat +301 -0
- package/tests/html5lib-data/tree-construction/math.dat +104 -0
- package/tests/html5lib-data/tree-construction/namespace-sensitivity.dat +22 -0
- package/tests/html5lib-data/tree-construction/noscript01.dat +237 -0
- package/tests/html5lib-data/tree-construction/ruby.dat +302 -0
- package/tests/html5lib-data/tree-construction/scriptdata01.dat +372 -0
- package/tests/html5lib-data/tree-construction/svg.dat +104 -0
- package/tests/html5lib-data/tree-construction/template.dat +1673 -0
- package/tests/html5lib-data/tree-construction/tests10.dat +853 -0
- package/tests/html5lib-data/tree-construction/tests11.dat +523 -0
- package/tests/html5lib-data/tree-construction/tests20.dat +842 -0
- package/tests/html5lib-data/tree-construction/tests21.dat +306 -0
- package/tests/html5lib-data/tree-construction/tests23.dat +168 -0
- package/tests/html5lib-data/tree-construction/tests24.dat +79 -0
- package/tests/html5lib-data/tree-construction/tests5.dat +210 -0
- package/tests/html5lib-data/tree-construction/tests6.dat +663 -0
- package/tests/html5lib-data/tree-construction/tests_innerHTML_1.dat +844 -0
- package/tests/parser.test.ts +172 -193
- package/tests/selectors.test.ts +64 -1
- package/tests/serializer-core.test.ts +16 -0
- package/tests/serializer-data/core.test +125 -0
- package/tests/serializer-data/injectmeta.test +66 -0
- package/tests/serializer-data/optionaltags.test +965 -0
- package/tests/serializer-data/options.test +60 -0
- package/tests/serializer-data/whitespace.test +51 -0
- package/tests/serializer-injectmeta.test.ts +16 -0
- package/tests/serializer-optionaltags.test.ts +16 -0
- package/tests/serializer-options.test.ts +16 -0
- package/tests/serializer-whitespace.test.ts +16 -0
- package/tests/tokenizer-namedEntities.test.ts +20 -0
- package/tests/tokenizer-pendingSpecChanges.test.ts +20 -0
- package/tests/tokenizer.test.ts +83 -0
- package/tests/tree-construction-adoption01.test.ts +37 -0
- package/tests/tree-construction-adoption02.test.ts +34 -0
- package/tests/tree-construction-domjs-unsafe.test.ts +24 -0
- package/tests/tree-construction-entities02.test.ts +33 -0
- package/tests/tree-construction-html5test-com.test.ts +24 -0
- package/tests/tree-construction-math.test.ts +18 -0
- package/tests/tree-construction-namespace-sensitivity.test.ts +18 -0
- package/tests/tree-construction-noscript01.test.ts +18 -0
- package/tests/tree-construction-ruby.test.ts +21 -0
- package/tests/tree-construction-scriptdata01.test.ts +21 -0
- package/tests/tree-construction-svg.test.ts +21 -0
- package/tests/tree-construction-template.test.ts +21 -0
- package/tests/tree-construction-tests10.test.ts +21 -0
- package/tests/tree-construction-tests11.test.ts +21 -0
- package/tests/tree-construction-tests20.test.ts +18 -0
- package/tests/tree-construction-tests21.test.ts +18 -0
- package/tests/tree-construction-tests23.test.ts +18 -0
- package/tests/tree-construction-tests24.test.ts +18 -0
- package/tests/tree-construction-tests5.test.ts +21 -0
- package/tests/tree-construction-tests6.test.ts +21 -0
- package/tests/tree-construction-tests_innerHTML_1.test.ts +21 -0
- package/tests/void-elements.test.ts +471 -0
- package/tests/official/README.md +0 -87
- package/tests/official/acid/acid-tests.test.ts +0 -309
- package/tests/official/final-output/final-output.test.ts +0 -361
- package/tests/official/html5lib/tokenizer-utils.ts +0 -192
- package/tests/official/html5lib/tokenizer.test.ts +0 -171
- package/tests/official/html5lib/tree-construction-utils.ts +0 -194
- package/tests/official/html5lib/tree-construction.test.ts +0 -250
- package/tests/official/validator/validator-tests.test.ts +0 -237
- package/tests/official/validator-nu/validator-nu.test.ts +0 -335
- package/tests/official/whatwg/whatwg-tests.test.ts +0 -205
- package/tests/official/wpt/wpt-tests.test.ts +0 -409
|
@@ -8,28 +8,28 @@ describe('DOM Extended Functionality', () => {
|
|
|
8
8
|
describe('innerHTML and outerHTML', () => {
|
|
9
9
|
it('should generate correct innerHTML for simple elements', () => {
|
|
10
10
|
const doc = parseHTML('<div>Hello World</div>') as Document;
|
|
11
|
-
const div = doc.
|
|
11
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
12
12
|
|
|
13
13
|
expect(div.innerHTML).toBe('Hello World');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it('should generate correct innerHTML for nested elements', () => {
|
|
17
17
|
const doc = parseHTML('<div><p>Hello</p><span>World</span></div>') as Document;
|
|
18
|
-
const div = doc.
|
|
18
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
19
19
|
|
|
20
20
|
expect(div.innerHTML).toBe('<p>Hello</p><span>World</span>');
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it('should generate correct outerHTML for elements', () => {
|
|
24
24
|
const doc = parseHTML('<div class="test">Hello</div>') as Document;
|
|
25
|
-
const div = doc.
|
|
25
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
26
26
|
|
|
27
27
|
expect(div.outerHTML).toBe('<div class="test">Hello</div>');
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
it('should generate correct outerHTML for elements with multiple attributes', () => {
|
|
31
31
|
const doc = parseHTML('<input type="text" name="username" value="test">') as Document;
|
|
32
|
-
const input = doc.
|
|
32
|
+
const input = doc.body?.firstChild as HTMLElement;
|
|
33
33
|
|
|
34
34
|
expect(input.outerHTML).toContain('type="text"');
|
|
35
35
|
expect(input.outerHTML).toContain('name="username"');
|
|
@@ -38,7 +38,7 @@ describe('DOM Extended Functionality', () => {
|
|
|
38
38
|
|
|
39
39
|
it('should handle comments in innerHTML', () => {
|
|
40
40
|
const doc = parseHTML('<div><!-- comment -->text</div>') as Document;
|
|
41
|
-
const div = doc.
|
|
41
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
42
42
|
|
|
43
43
|
expect(div.innerHTML).toBe('<!-- comment -->text');
|
|
44
44
|
});
|
|
@@ -47,21 +47,21 @@ describe('DOM Extended Functionality', () => {
|
|
|
47
47
|
describe('textContent property', () => {
|
|
48
48
|
it('should provide textContent on elements', () => {
|
|
49
49
|
const doc = parseHTML('<div>Hello <span>World</span></div>') as Document;
|
|
50
|
-
const div = doc.
|
|
50
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
51
51
|
|
|
52
52
|
expect(div.textContent).toBe('Hello World');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it('should provide textContent for deeply nested elements', () => {
|
|
56
56
|
const doc = parseHTML('<div><p><em>Hello</em> <strong>Beautiful</strong></p> <span>World</span></div>') as Document;
|
|
57
|
-
const div = doc.
|
|
57
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
58
58
|
|
|
59
59
|
expect(div.textContent).toBe('Hello Beautiful World');
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
it('should ignore comments in textContent', () => {
|
|
63
63
|
const doc = parseHTML('<div>Hello <!-- comment --> World</div>') as Document;
|
|
64
|
-
const div = doc.
|
|
64
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
65
65
|
|
|
66
66
|
expect(div.textContent).toBe('Hello World');
|
|
67
67
|
});
|
|
@@ -70,7 +70,7 @@ describe('DOM Extended Functionality', () => {
|
|
|
70
70
|
describe('element navigation properties', () => {
|
|
71
71
|
it('should provide parentElement property', () => {
|
|
72
72
|
const doc = parseHTML('<div><p>Hello</p></div>') as Document;
|
|
73
|
-
const div = doc.
|
|
73
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
74
74
|
const p = div.children[0];
|
|
75
75
|
|
|
76
76
|
expect(p).toBeDefined();
|
|
@@ -79,7 +79,7 @@ describe('DOM Extended Functionality', () => {
|
|
|
79
79
|
|
|
80
80
|
it('should provide firstElementChild and lastElementChild', () => {
|
|
81
81
|
const doc = parseHTML('<div><span>First</span><p>Second</p><em>Last</em></div>') as Document;
|
|
82
|
-
const div = doc.
|
|
82
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
83
83
|
|
|
84
84
|
expect(div.firstElementChild?.tagName).toBe('SPAN');
|
|
85
85
|
expect(div.lastElementChild?.tagName).toBe('EM');
|
|
@@ -87,7 +87,7 @@ describe('DOM Extended Functionality', () => {
|
|
|
87
87
|
|
|
88
88
|
it('should provide nextElementSibling and previousElementSibling', () => {
|
|
89
89
|
const doc = parseHTML('<div><span>First</span><p>Second</p><em>Last</em></div>') as Document;
|
|
90
|
-
const div = doc.
|
|
90
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
91
91
|
const span = div.children[0];
|
|
92
92
|
const p = div.children[1];
|
|
93
93
|
const em = div.children[2];
|
|
@@ -111,7 +111,7 @@ describe('DOM Extended Functionality', () => {
|
|
|
111
111
|
describe('setInnerHTML functionality', () => {
|
|
112
112
|
it('should clear existing content when setting innerHTML', () => {
|
|
113
113
|
const doc = parseHTML('<div><p>Old content</p></div>') as Document;
|
|
114
|
-
const div = doc.
|
|
114
|
+
const div = doc.body?.firstChild as HTMLElement;
|
|
115
115
|
|
|
116
116
|
setInnerHTML(div, 'New content');
|
|
117
117
|
|