Skip to content

Commit

Permalink
Support custom size for images in markdown (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway authored Apr 11, 2024
1 parent 5923089 commit f851ef6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
theme: 'classic',
tabComments: true,
tabHeadings: true
},
markdown: {
renderer: {
image(src, title, alt) {
// resolve src to basePath
// e.g. http://localhost:8080/docs#/user_guide/a.jpg -> docs/user_guide/a.jpg
if(!src.startsWith('http') && !src.startsWith('/')){
const url = new URL(src, window.location.href.replace(/#\//, '/')); // remove hash
src = url.pathname;
}
const [width, height] = (title && title.startsWith('=')) ? title.slice(1).split('x').map(v => v.trim()).filter(Boolean) : [];
return `<img src="${src}" alt="${alt}"${width ? ` width="${width}"` : ''}${height ? ` height="${height}"` : ''}>`;
}
}
}
};
</script>
Expand Down

0 comments on commit f851ef6

Please sign in to comment.