diff --git a/theme/index.js b/theme/index.js index bcb5f14..15808c9 100644 --- a/theme/index.js +++ b/theme/index.js @@ -96,10 +96,16 @@ module.exports = (options, ctx) => { chainMarkdown(config) { config .plugin('custom-style') - .use(require('./plugins/markdown/mdCustomStyle')); + .use(require('./plugins/markdown/mdCustomStyle')) + .end(); config .plugin('code-result') - .use(require('./plugins/markdown/mdCodeResult')); + .use(require('./plugins/markdown/mdCodeResult')) + .end(); + config + .plugin('img-alt') + .use(require('./plugins/markdown/mdAltImg')) + .end(); // plugin config.plugin('sup').use(require('markdown-it-sup')); diff --git a/theme/plugins/markdown/mdAltImg.js b/theme/plugins/markdown/mdAltImg.js new file mode 100644 index 0000000..23ce85d --- /dev/null +++ b/theme/plugins/markdown/mdAltImg.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = (md) => { + + md.renderer.rules.image = (tokens, idx, options, env, self) => { + const token = tokens[idx] + const hrefIndex = token.attrIndex('src') + if (hrefIndex >= 0) { + const alt = token.content || (token.children && token.children[0] && token.children[0].content) || ''; + token.attrSet('alt', alt); + } + return self.renderToken(tokens, idx, options) + } + +} \ No newline at end of file