@@ -243,19 +243,25 @@ const parseStyles = (el: Node, inline = true): Data => {
243243
244244 if ( color ) data . color = standardizeColor ( color ) ;
245245
246- if ( el . tagName === "SUP" ) data . superScript = true ;
247- else if ( el . tagName === "SUB" ) data . subScript = true ;
248- else if ( [ "STRONG" , "B" ] . includes ( el . tagName ) ) data . bold = true ;
249- else if ( [ "EM" , "I" ] . includes ( el . tagName ) ) data . italics = true ;
250- else if ( [ "DEL" , "S" ] . includes ( el . tagName ) ) data . strike = true ;
251- else if ( [ "U" , "INS" ] . includes ( el . tagName ) ) data . underline = { } ;
252- else if ( el . tagName === "MARK" ) {
246+ const tagName = el . tagName ;
247+ if ( tagName === "SUP" ) data . superScript = true ;
248+ else if ( tagName === "SUB" ) data . subScript = true ;
249+ else if ( [ "STRONG" , "B" ] . includes ( tagName ) ) data . bold = true ;
250+ else if ( [ "EM" , "I" ] . includes ( tagName ) ) data . italics = true ;
251+ else if ( [ "DEL" , "S" ] . includes ( tagName ) ) data . strike = true ;
252+ else if ( [ "U" , "INS" ] . includes ( tagName ) ) data . underline = { } ;
253+ else if ( tagName === "MARK" ) {
253254 data . highlight = "yellow" ;
254255 data . emphasisMark = { } ;
255- } else if ( el . tagName === "PRE" ) {
256+ } else if ( tagName === "PRE" ) {
256257 data . pre = true ;
258+ } else if ( / ( r a d i o | c h e c k b o x ) / . test ( tagName ) ) {
259+ data . type = ( el as HTMLInputElement ) . type ;
260+ data . name = ( el as HTMLInputElement ) . name ;
261+ data . value = ( el as HTMLInputElement ) . value ;
262+ data . checked = ( el as HTMLInputElement ) . checked ?? ( el as HTMLInputElement ) . defaultChecked ;
257263 }
258-
264+ data . tag = tagName . toLowerCase ( ) as keyof HTMLElementTagNameMap ;
259265 return data ;
260266} ;
261267
@@ -278,7 +284,8 @@ const processInlineDOMNode = (el: Node, isPre = false): PhrasingContent => {
278284 . getAttributeNames ( )
279285 . reduce ( ( acc , cur ) => ( { ...acc , [ cur ] : el . getAttribute ( cur ) } ) , { } ) ;
280286
281- switch ( el . tagName ) {
287+ const tagName = el . tagName ;
288+ switch ( tagName ) {
282289 case "BR" :
283290 return { type : "break" } ;
284291 case "IMG" :
@@ -301,9 +308,9 @@ const processInlineDOMNode = (el: Node, isPre = false): PhrasingContent => {
301308 case "DEL" :
302309 case "S" :
303310 return {
304- type : DOM_TO_MDAST_MAP [ el . tagName ] ,
311+ type : DOM_TO_MDAST_MAP [ tagName ] ,
305312 children,
306- data : { ... data , tag : el . tagName . toLowerCase ( ) as keyof HTMLElementTagNameMap } ,
313+ data,
307314 } ;
308315 case "A" :
309316 return {
@@ -314,14 +321,13 @@ const processInlineDOMNode = (el: Node, isPre = false): PhrasingContent => {
314321 } ;
315322 case "INPUT" :
316323 return / ( r a d i o | c h e c k b o x ) / . test ( ( el as HTMLInputElement ) . type )
317- ? { type : "checkbox" }
324+ ? { type : "checkbox" , data }
318325 : {
319326 type : "text" ,
320327 value : `_${ ( el as HTMLInputElement ) . value || "_" . repeat ( 20 ) } _` ,
321328 data : {
322329 ...data ,
323330 border : { style : BorderStyle . OUTSET } ,
324- type : ( el as HTMLInputElement ) . type ,
325331 } ,
326332 } ;
327333 }
@@ -407,7 +413,8 @@ const defaultBorder = { left: border, right: border, top: border, bottom: border
407413 */
408414const processDOMNode = ( el : HTMLElement | SVGElement ) : BlockContent => {
409415 const data = parseStyles ( el ) ;
410- switch ( el . tagName ) {
416+ const tagName = el . tagName ;
417+ switch ( tagName ) {
411418 case "H1" :
412419 case "H2" :
413420 case "H3" :
@@ -416,9 +423,9 @@ const processDOMNode = (el: HTMLElement | SVGElement): BlockContent => {
416423 case "H6" :
417424 return {
418425 type : "heading" ,
419- depth : parseInt ( el . tagName [ 1 ] ) ,
426+ depth : parseInt ( tagName [ 1 ] ) ,
420427 children : Array . from ( el . childNodes ) . map ( cNode => processInlineDOMNode ( cNode ) ) ,
421- data : { ... data , tag : el . tagName . toLowerCase ( ) } ,
428+ data,
422429 } as Heading ;
423430 case "PRE" :
424431 case "P" :
@@ -427,19 +434,16 @@ const processDOMNode = (el: HTMLElement | SVGElement): BlockContent => {
427434 case "SUMMARY" :
428435 case "FORM" :
429436 case "LI" :
430- return createFragmentWithParentNodes ( el , {
431- ...data ,
432- tag : el . tagName . toLowerCase ( ) as keyof HTMLElementTagNameMap ,
433- } ) ;
437+ return createFragmentWithParentNodes ( el , data ) ;
434438 case "UL" :
435439 case "OL" :
436440 return {
437441 type : "list" ,
438- ordered : el . tagName === "OL" ,
442+ ordered : tagName === "OL" ,
439443 children : Array . from ( el . childNodes ) . map ( node => ( {
440444 type : "listItem" ,
441445 children : [ createFragmentWithParentNodes ( node ) ] ,
442- data : { ... data , tag : el . tagName . toLowerCase ( ) as keyof HTMLElementTagNameMap } ,
446+ data,
443447 } ) ) ,
444448 } ;
445449 case "HR" :
0 commit comments