@@ -13,8 +13,41 @@ export default defineConfig({
1313 cleanUrls : true ,
1414 outDir : "../dist/docs" ,
1515 markdown : {
16- config : ( md ) => {
17- markdownItImageSize ( md , { publicDir : path . resolve ( import . meta. dirname , '../public' ) , } ) ;
16+ config ( md ) {
17+ // Fix for image width and height handling for proper scrolling
18+ const maxHeight = 500 /* px */
19+
20+ const img = md . renderer . rules . image !
21+ md . renderer . rules . image = function ( tokens , idx , options , env , self ) {
22+ const token = tokens [ idx ]
23+
24+ const widthAttr = token . attrGet ( 'width' )
25+ const heightAttr = token . attrGet ( 'height' )
26+ const existingStyle = token . attrGet ( 'style' ) || ''
27+
28+ const style : string [ ] = [ ]
29+
30+ let w = widthAttr ? Number . parseInt ( widthAttr , 10 ) : null
31+ let h = heightAttr ? Number . parseInt ( heightAttr , 10 ) : null
32+
33+ if ( w ) {
34+ if ( h && h > maxHeight ) {
35+ const scale = maxHeight / h
36+ w = Math . round ( w * scale )
37+ h = maxHeight
38+ }
39+ style . push ( `width: ${ w } px;` )
40+ }
41+
42+ if ( style . length > 0 ) {
43+ const sep = existingStyle && ! existingStyle . trim ( ) . endsWith ( ';' ) ? ';' : ''
44+ token . attrSet ( 'style' , existingStyle + sep + style . join ( ' ' ) )
45+ }
46+
47+ return img ( tokens , idx , options , env , self )
48+ }
49+
50+ markdownItImageSize ( md , { publicDir : path . resolve ( import . meta. dirname , '../public' ) } )
1851 } ,
1952 } ,
2053 themeConfig : {
0 commit comments