diff --git a/_config.yml b/_config.yml index 29a70e5..5fc5006 100755 --- a/_config.yml +++ b/_config.yml @@ -241,6 +241,8 @@ tag_plugins: # {% image %} image: fancybox: # true, false + replace_original: #把markdown格式的图片解析成图片标签 + enable: false # {% timeline %} timeline: max-height: 80vh diff --git a/scripts/filters/index.js b/scripts/filters/index.js index 5285154..e6da638 100644 --- a/scripts/filters/index.js +++ b/scripts/filters/index.js @@ -2,3 +2,16 @@ hexo.extend.filter.register('after_render:html', require('./lib/img_lazyload').processSite); hexo.extend.filter.register('after_render:html', require('./lib/img_onerror').processSite); + +function change_image(data){ + const cfg = this.theme.config.tag_plugins.image.replace_original; + + if (cfg.enable){ + data.content = data.content.replace(/!\[([^\]]*)]\(([^(]+)\)/g, '{% image $2 $1 %}'); + } + + return data; +} + + +hexo.extend.filter.register('before_post_render', change_image, 9); diff --git a/scripts/tags/lib/image.js b/scripts/tags/lib/image.js index f253f94..a9db6ba 100644 --- a/scripts/tags/lib/image.js +++ b/scripts/tags/lib/image.js @@ -71,7 +71,7 @@ module.exports = ctx => function(args) { if (args.download == 'true') { href = args.src } - el += '' + el += '' } el += ''