@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.
Files changed (91) hide show
  1. package/README.md +1 -7
  2. package/bun.lock +8 -3
  3. package/index.ts +4 -0
  4. package/package.json +13 -6
  5. package/src/css-selector.ts +45 -27
  6. package/src/dom-simulator.ts +162 -20
  7. package/src/encoding.ts +39 -0
  8. package/src/index.ts +9 -0
  9. package/src/parser.ts +478 -183
  10. package/src/serializer.ts +450 -0
  11. package/src/tokenizer.ts +59 -139
  12. package/tests/advanced.test.ts +119 -106
  13. package/tests/custom-elements.test.ts +172 -162
  14. package/tests/dom-extended.test.ts +12 -12
  15. package/tests/dom-manipulation.test.ts +637 -0
  16. package/tests/dom.test.ts +32 -27
  17. package/tests/helpers/tokenizer-adapter.test.ts +70 -0
  18. package/tests/helpers/tokenizer-adapter.ts +65 -0
  19. package/tests/helpers/tree-adapter.test.ts +39 -0
  20. package/tests/helpers/tree-adapter.ts +43 -0
  21. package/tests/html5lib-data/tokenizer/namedEntities.test +42422 -0
  22. package/tests/html5lib-data/tokenizer/pendingSpecChanges.test +9 -0
  23. package/tests/html5lib-data/tree-construction/adoption01.dat +354 -0
  24. package/tests/html5lib-data/tree-construction/adoption02.dat +39 -0
  25. package/tests/html5lib-data/tree-construction/domjs-unsafe.dat +0 -0
  26. package/tests/html5lib-data/tree-construction/entities02.dat +309 -0
  27. package/tests/html5lib-data/tree-construction/html5test-com.dat +301 -0
  28. package/tests/html5lib-data/tree-construction/math.dat +104 -0
  29. package/tests/html5lib-data/tree-construction/namespace-sensitivity.dat +22 -0
  30. package/tests/html5lib-data/tree-construction/noscript01.dat +237 -0
  31. package/tests/html5lib-data/tree-construction/ruby.dat +302 -0
  32. package/tests/html5lib-data/tree-construction/scriptdata01.dat +372 -0
  33. package/tests/html5lib-data/tree-construction/svg.dat +104 -0
  34. package/tests/html5lib-data/tree-construction/template.dat +1673 -0
  35. package/tests/html5lib-data/tree-construction/tests10.dat +853 -0
  36. package/tests/html5lib-data/tree-construction/tests11.dat +523 -0
  37. package/tests/html5lib-data/tree-construction/tests20.dat +842 -0
  38. package/tests/html5lib-data/tree-construction/tests21.dat +306 -0
  39. package/tests/html5lib-data/tree-construction/tests23.dat +168 -0
  40. package/tests/html5lib-data/tree-construction/tests24.dat +79 -0
  41. package/tests/html5lib-data/tree-construction/tests5.dat +210 -0
  42. package/tests/html5lib-data/tree-construction/tests6.dat +663 -0
  43. package/tests/html5lib-data/tree-construction/tests_innerHTML_1.dat +844 -0
  44. package/tests/parser.test.ts +172 -193
  45. package/tests/selectors.test.ts +64 -1
  46. package/tests/serializer-core.test.ts +16 -0
  47. package/tests/serializer-data/core.test +125 -0
  48. package/tests/serializer-data/injectmeta.test +66 -0
  49. package/tests/serializer-data/optionaltags.test +965 -0
  50. package/tests/serializer-data/options.test +60 -0
  51. package/tests/serializer-data/whitespace.test +51 -0
  52. package/tests/serializer-injectmeta.test.ts +16 -0
  53. package/tests/serializer-optionaltags.test.ts +16 -0
  54. package/tests/serializer-options.test.ts +16 -0
  55. package/tests/serializer-whitespace.test.ts +16 -0
  56. package/tests/tokenizer-namedEntities.test.ts +20 -0
  57. package/tests/tokenizer-pendingSpecChanges.test.ts +20 -0
  58. package/tests/tokenizer.test.ts +83 -0
  59. package/tests/tree-construction-adoption01.test.ts +37 -0
  60. package/tests/tree-construction-adoption02.test.ts +34 -0
  61. package/tests/tree-construction-domjs-unsafe.test.ts +24 -0
  62. package/tests/tree-construction-entities02.test.ts +33 -0
  63. package/tests/tree-construction-html5test-com.test.ts +24 -0
  64. package/tests/tree-construction-math.test.ts +18 -0
  65. package/tests/tree-construction-namespace-sensitivity.test.ts +18 -0
  66. package/tests/tree-construction-noscript01.test.ts +18 -0
  67. package/tests/tree-construction-ruby.test.ts +21 -0
  68. package/tests/tree-construction-scriptdata01.test.ts +21 -0
  69. package/tests/tree-construction-svg.test.ts +21 -0
  70. package/tests/tree-construction-template.test.ts +21 -0
  71. package/tests/tree-construction-tests10.test.ts +21 -0
  72. package/tests/tree-construction-tests11.test.ts +21 -0
  73. package/tests/tree-construction-tests20.test.ts +18 -0
  74. package/tests/tree-construction-tests21.test.ts +18 -0
  75. package/tests/tree-construction-tests23.test.ts +18 -0
  76. package/tests/tree-construction-tests24.test.ts +18 -0
  77. package/tests/tree-construction-tests5.test.ts +21 -0
  78. package/tests/tree-construction-tests6.test.ts +21 -0
  79. package/tests/tree-construction-tests_innerHTML_1.test.ts +21 -0
  80. package/tests/void-elements.test.ts +471 -0
  81. package/tests/official/README.md +0 -87
  82. package/tests/official/acid/acid-tests.test.ts +0 -309
  83. package/tests/official/final-output/final-output.test.ts +0 -361
  84. package/tests/official/html5lib/tokenizer-utils.ts +0 -192
  85. package/tests/official/html5lib/tokenizer.test.ts +0 -171
  86. package/tests/official/html5lib/tree-construction-utils.ts +0 -194
  87. package/tests/official/html5lib/tree-construction.test.ts +0 -250
  88. package/tests/official/validator/validator-tests.test.ts +0 -237
  89. package/tests/official/validator-nu/validator-nu.test.ts +0 -335
  90. package/tests/official/whatwg/whatwg-tests.test.ts +0 -205
  91. 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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
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.childNodes[0] as HTMLElement;
114
+ const div = doc.body?.firstChild as HTMLElement;
115
115
 
116
116
  setInnerHTML(div, 'New content');
117
117