@@ -21,7 +21,6 @@ export default defineConfig({
2121 } ,
2222 markdown : {
2323 config ( md ) {
24- // Fix for image width and height handling for proper scrolling
2524 const maxHeight = 500 /* px */
2625
2726 const img = md . renderer . rules . image !
@@ -30,27 +29,22 @@ export default defineConfig({
3029
3130 const widthAttr = token . attrGet ( 'width' )
3231 const heightAttr = token . attrGet ( 'height' )
33- const existingStyle = token . attrGet ( 'style' ) || ''
34-
35- const style : string [ ] = [ ]
3632
3733 let w = widthAttr ? Number . parseInt ( widthAttr , 10 ) : null
3834 let h = heightAttr ? Number . parseInt ( heightAttr , 10 ) : null
3935
36+ let style = token . attrGet ( 'style' ) || ''
37+ if ( style && ! style . trim ( ) . endsWith ( ';' ) ) style += ';'
38+
4039 if ( w ) {
4140 if ( h && h > maxHeight ) {
42- const scale = maxHeight / h
43- w = Math . round ( w * scale )
41+ w = Math . round ( w * maxHeight / h )
4442 h = maxHeight
4543 }
46- style . push ( `width: ${ w } px;` )
47- }
48-
49- if ( style . length > 0 ) {
50- const sep = existingStyle && ! existingStyle . trim ( ) . endsWith ( ';' ) ? ';' : ''
51- token . attrSet ( 'style' , existingStyle + sep + style . join ( ' ' ) )
44+ style += `width: ${ w } px;`
5245 }
5346
47+ token . attrSet ( 'style' , style )
5448 return img ( tokens , idx , options , env , self )
5549 }
5650
0 commit comments