11import type { MdreamProcessingState , NodeEvent } from '../../src/types.js'
22import { describe , expect , it } from 'vitest'
3- import { NodeEventEnter } from '../../src/const.js'
3+ import { MAX_TAG_ID , NodeEventEnter } from '../../src/const.js'
44import { syncHtmlToMarkdown } from '../../src/index.js'
55import { parseHTML } from '../../src/parser.js'
66
@@ -10,7 +10,7 @@ describe('hTML walking', () => {
1010 const depthLog : { tagName : string , depth : number , event : string } [ ] = [ ]
1111
1212 const state : Partial < MdreamProcessingState > = {
13- depthMap : { } ,
13+ depthMap : new Uint8Array ( MAX_TAG_ID ) ,
1414 depth : 0 ,
1515 currentElementNode : null ,
1616 }
@@ -45,7 +45,7 @@ describe('hTML walking', () => {
4545 const depthLog : { tagName : string , depth : number , event : string } [ ] = [ ]
4646
4747 const state : Partial < MdreamProcessingState > = {
48- depthMap : { } ,
48+ depthMap : new Uint8Array ( MAX_TAG_ID ) ,
4949 depth : 0 ,
5050 currentElementNode : null ,
5151 }
@@ -79,10 +79,10 @@ describe('hTML walking', () => {
7979
8080 it ( 'tracks depthMap correctly for multiple levels of nested elements' , ( ) => {
8181 const html = '<div><ul><li><a href="#">Link <strong>with bold</strong> text</a></li></ul></div>'
82- const depthMapLog : { tagName : string , depthMap : Record < number , number > } [ ] = [ ]
82+ const depthMapLog : { tagName : string , depthMap : Uint8Array } [ ] = [ ]
8383
8484 const state : Partial < MdreamProcessingState > = {
85- depthMap : { } ,
85+ depthMap : new Uint8Array ( MAX_TAG_ID ) ,
8686 depth : 0 ,
8787 currentElementNode : null ,
8888 }
@@ -93,7 +93,7 @@ describe('hTML walking', () => {
9393 if ( event . type === NodeEventEnter && node . type === 1 ) { // ELEMENT_NODE enter
9494 depthMapLog . push ( {
9595 tagName : node . name || '' ,
96- depthMap : { ... node . depthMap } , // Copy to avoid reference issues in test
96+ depthMap : new Uint8Array ( node . depthMap ) , // Copy to avoid reference issues in test
9797 } )
9898 }
9999 }
@@ -109,11 +109,21 @@ describe('hTML walking', () => {
109109 expect ( depthMapLog [ 4 ] . tagName ) . toBe ( 'strong' )
110110
111111 // Each node should have a depthMap that includes itself and its ancestors
112- expect ( depthMapLog [ 4 ] . depthMap ) . toMatchObject ( {
113- // The exact tag IDs will depend on the TAG_MAP constants
114- // but the strong element should have entries for div, ul, li, a, and strong
115- // with counts >= 1
116- } )
112+ // Check that the values in the Uint8Array for the corresponding tag IDs
113+ // are all greater than 0 for the expected elements
114+ const depthMap = depthMapLog [ 4 ] . depthMap
115+ // Import these constants in a real implementation
116+ const divId = 36 // TAG_DIV
117+ const ulId = 24 // TAG_UL
118+ const liId = 25 // TAG_LI
119+ const aId = 26 // TAG_A
120+ const strongId = 14 // TAG_STRONG
121+
122+ expect ( depthMap [ divId ] ) . toBeGreaterThan ( 0 )
123+ expect ( depthMap [ ulId ] ) . toBeGreaterThan ( 0 )
124+ expect ( depthMap [ liId ] ) . toBeGreaterThan ( 0 )
125+ expect ( depthMap [ aId ] ) . toBeGreaterThan ( 0 )
126+ expect ( depthMap [ strongId ] ) . toBeGreaterThan ( 0 )
117127 } )
118128
119129 it ( 'handles complex nested elements with text nodes' , ( ) => {
0 commit comments