hexojs / hexo-renderer-marked

Markdown renderer for Hexo
MIT License
179 stars 94 forks source link

fix: add more asset-searching locations and solve a known issue #271

Open lucienshawls opened 10 months ago

lucienshawls commented 10 months ago

This resolves #216.

Until now, if I would like to insert an image named image.jpg in a post with the filename foo.md with these configurations:

post_asset_folder: true
relative_link: false
marked:
  prependRoot: true
  postAsset: true

and the filesystem structure:

source/_posts
├── foo.md
└── foo/
    └── image.jpg

I have to use ![](image.jpg) instead of ![](foo/image.jpg) otherwise hexo would not generate a valid img src. However, if I would like to preview the markdown file while editing, I have to use the latter one. This is contradictory.

So I made a modification to allow hexo-renderer-marked to search for assets not only in current asset folder source/_posts/foo, but also in its parent folder source/_posts, so that ![](foo/image.jpg) can also be located and the src can be generated correctly.

Moreover, this change is compatible with the previous versions and developers can safely update the package to a new version without the need for changing each and every link in their blogs.

Notice: the changes have passed the tests on Linux (WSL2, Ubuntu 22.04).

I hope these changes are acceptable.

coveralls commented 10 months ago

Coverage Status

coverage: 100.0%. remained the same when pulling a32559095374115cc794a8349270b3fd8c6b7bbd on lucienshawls:master into 1b0935497529ef4dbf81b5c42abc0a3289c91b2c on hexojs:master.

DexterMorgan0417 commented 7 months ago

the check is not passed ,your idea is very good,i have the same demand

lucienshawls commented 7 months ago

I managed to resolve the lint problems. See if it helps.

bl-sun commented 6 months ago

I need this.

lich-wang commented 6 months ago

Thats a good one and will be nice to have it especially VS code now can set the Destination for past a image use the setting, "markdown.copyFiles.destination": { "**/*.md": "${documentDirName}/${documentBaseName}/${fileName}" }

DexterMorgan0417 commented 6 months ago

I expect this feature

lucienshawls commented 6 months ago

@uiolee Could you please spare some time to review this pull request?

DexterMorgan0417 commented 5 months ago

`F8UV 7O(PCU4W}TJZAC866

DexterMorgan0417 commented 5 months ago

按照你说的,确实起了作用 我习惯于使用Typora编辑md文件,我个人倾向于 -a.md -a.png 这种路径,将md和图片放在同一个文件夹下

Following your suggestions, it indeed worked. I usually use Typora to edit markdown files, and I personally prefer the following path structure: -a.md -a.png This way, the markdown file and the image are placed in the same folder.