diff --git a/README.md b/README.md index 6de9440..0ddb553 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,10 @@ let g:mkdp_page_title = '「${name}」' " use a custom location for images let g:mkdp_images_path = /home/user/.markdown_images +" resolve absolute image paths against the custom location for images, +" instead of the root of the system (default to 0) +let g:mkdp_images_path_as_root = 1 + " recognized filetypes " these filetypes will have MarkdownPreview... commands let g:mkdp_filetypes = ['markdown'] diff --git a/app/routes.js b/app/routes.js index 63d3a9a..f099aca 100644 --- a/app/routes.js +++ b/app/routes.js @@ -93,7 +93,7 @@ use(async (req, res, next) => { let imgPath = decodeURIComponent(decodeURIComponent(req.asPath.replace(reg, ''))) imgPath = imgPath.replace(/\\ /g, ' ') - if (imgPath[0] !== '/' && imgPath[0] !== '\\') { + if (req.custImgPathAsRoot || imgPath[0] !== '/' && imgPath[0] !== '\\') { imgPath = path.join(fileDir, imgPath) } else if (!fs.existsSync(imgPath)) { let tmpDirPath = fileDir diff --git a/app/server.js b/app/server.js index 979cb2f..d7be261 100644 --- a/app/server.js +++ b/app/server.js @@ -44,6 +44,7 @@ exports.run = function () { req.mkcss = await plugin.nvim.getVar('mkdp_markdown_css') req.hicss = await plugin.nvim.getVar('mkdp_highlight_css') req.custImgPath = await plugin.nvim.getVar('mkdp_images_path') + req.custImgPathAsRoot = await plugin.nvim.getVar('mkdp_images_path_as_root') // routes routes(req, res) }) diff --git a/plugin/mkdp.vim b/plugin/mkdp.vim index 9b28307..a4a043d 100644 --- a/plugin/mkdp.vim +++ b/plugin/mkdp.vim @@ -105,6 +105,12 @@ if !exists('g:mkdp_images_path') let g:mkdp_images_path = '' endif +" if 1, absolute image paths are resolved against the images custom +" path instead of the system root +if !exists('g:mkdp_images_path_as_root') + let g:mkdp_images_path_as_root = 0 +endif + " combine preview window if !exists('g:mkdp_combine_preview') let g:mkdp_combine_preview = 0