From f851ef6084fb0c910b32f287ca58664b46f8dc5c Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Thu, 11 Apr 2024 13:45:27 -0700 Subject: [PATCH] Support custom size for images in markdown (#384) --- docs/index.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/index.html b/docs/index.html index 18a64a6c..9cd793e1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -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 `${alt}`; + } + } } };