Skip to content

Commit

Permalink
fix non-ascii src atrtibute.
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceroad committed Oct 17, 2022
1 parent 7c3e822 commit 3d285a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ module.exports = function renderer_image_plugin(md, option) {
}
}
}
img += path.sep + imgSrc
img += path.sep + imgSrc;
img = decodeURI(img);
return img;
}

Expand All @@ -92,7 +93,7 @@ module.exports = function renderer_image_plugin(md, option) {
let imgAlt = md.utils.escapeHtml(token.content);
let imgSrc = md.utils.escapeHtml(token.attrGet('src'));
let imgTitle = md.utils.escapeHtml(token.attrGet('title'));
let imgCont = '<img src="' + imgSrc + '"' + endTagCont;
let imgCont = '<img src="' + decodeURI(imgSrc) + '"' + endTagCont;
imgCont = imgCont.replace(/( src=".*?")/, '$1 alt="' + imgAlt + '"');
if (imgTitle) {
imgCont = imgCont.replace(/( *?\/)?>$/, ' title="' + imgTitle + '"$1>');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@peaceroad/markdown-it-renderer-image",
"version": "0.1.8",
"version": "0.1.9",
"description": "A markdown-it plugin. This add width and height attributes to img elements.",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions test/examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@
![Figure](https://raw.githubusercontent.com/peaceroad/p7d-markdown-it-renderer-image/main/test/dog.jpg)
[HTML]
<p><img src="https://raw.githubusercontent.com/peaceroad/p7d-markdown-it-renderer-image/main/test/dog.jpg" alt="Figure"></p>

[Markdown]
![Figure](猫.jpg)
[HTML]
<p><img src="猫.jpg" alt="Figure" width="400" height="300"></p>

0 comments on commit 3d285a0

Please sign in to comment.