hexojs / hexojs/hexo-renderer-marked

md img render part improvement of hexo-render-marked

Open
#216 8 comments 8 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
183
Forks
93
PR merge metrics
No merged PRs in 30d

Description

## Background
u know when we use other md editor write a post, the img with relative path is like this `![makabaka](postname/1.jpg)`, but here in hexo-render-marked i must use `![makabaka](1.jpg)` 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 = `

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in lib/render.js, specifically the image() renderer and its handling of postAsset, prependRoot, postPath, and relative_link. Reproduce the relative-image case described in the issue, then determine how the requested configuration choice should control resolving paths such as postname/1.jpg; done means both editor-style and Hexo-style relative asset paths render correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.