Skip to content

Commit f8dee44

Browse files
benwindinguiolee
andauthored
Fixes "alt" tag not showing, when images option is used (#210)
* Fixes "alt" tag not showing Issue -> hexojs/hexo-renderer-markdown-it/#205 * add test code --------- Co-authored-by: uiolee <22849383+uiolee@users.noreply.github.com>
1 parent 7aecf9b commit f8dee44

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/images.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function images(md, opts) {
1313
const token = tokens[idx];
1414
const { postPath } = env;
1515

16+
token.attrSet('alt', token.content);
17+
1618
if (lazyload) {
1719
token.attrSet('loading', 'lazy');
1820
}

test/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('Hexo Renderer Markdown-it', () => {
118118
const resultInline = renderer.render({ text }, { inline: true });
119119
resultBlock.should.eql('<p>inline text</p>\n');
120120
resultInline.should.eql('inline text');
121-
})
121+
});
122122
});
123123

124124
describe('plugins', () => {
@@ -403,6 +403,15 @@ describe('Hexo Renderer Markdown-it', () => {
403403
result.should.eql('<p><img src="/blog/bar/baz.jpg" alt=""></p>\n');
404404
});
405405

406+
it('alt text', () => {
407+
hexo.config.markdown.images = { test: true };
408+
409+
const renderer = new Renderer(hexo);
410+
const result = renderer.render({ text: '![alt text](/bar/baz.jpg)' });
411+
412+
result.should.eql('<p><img src="/bar/baz.jpg" alt="alt text"></p>\n');
413+
});
414+
406415
describe('post_asset', () => {
407416
const Post = hexo.model('Post');
408417
const PostAsset = hexo.model('PostAsset');

0 commit comments

Comments
 (0)