-
-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
Background
u know when we use other md editor write a post, the img with relative path is like this 
, but here in hexo-render-marked i must use 
if the config like this:
post_asset_folder: true
marked:
prependRoot: true
postAsset: true
it means there must be one side between md editor & hexo can't see the pic.
My solution
i opened node_modules -> hexo-render-marked -> lib -> render.js
and change the image part (between the *** lines):
// Prepend root to image path
image(href, title, text) {
const { hexo, options } = this;
const { relative_link } = hexo.config;
const { lazyload, prependRoot, postPath } = options;
if (!/^(#|\/\/|http(s)?:)/.test(href) && !relative_link && prependRoot) {
if (!href.startsWith('/') && !href.startsWith('\\') && postPath) {
const PostAsset = hexo.model('PostAsset');
// findById requires forward slash
// ************************************************************
const pp = require('path');
const ppp = pp.join(postPath, '../');
// const asset = PostAsset.findById(join(postPath, href.replace(/\\/g, '/')));
const asset = PostAsset.findById(join(ppp, href.replace(/\\/g, '/')));
// ************************************************************
// asset.path is backward slash in Windows
if (asset) href = asset.path.replace(/\\/g, '/');
}
href = url_for.call(hexo, href);
}
let out = `<img src="${encodeURL(href)}"`;
if (text) out += ` alt="${text}"`;
if (title) out += ` title="${title}"`;
if (lazyload) out += ' loading="lazy"';
out += '>';
return out;
}
}
it works. so the following is my suggests about this product experience
Feature Request
- provide a better implement cuz im not good at this language
- provide a config choice 4 this problem
tks a lot!
Kevincible, glm1024, Jack-InGitHub, zhaomoran, Druadach and 3 more
Metadata
Metadata
Assignees
Labels
No labels