markdowm-it-image-attrs.js 592 字节
Newer Older
D
DCloud_LXH 已提交
1 2 3 4 5 6 7
module.exports = function (md, opts) {
	md.core.ruler.after('inline', 'image-attrs', function (state) {
		state.tokens.forEach(function (blockToken) {
			if (blockToken.type === 'inline' && blockToken.children) {
				blockToken.children.forEach(function (token) {
					const type = token.type;
					if (type === 'image') {
D
DCloud_LXH 已提交
8
						const src = token.attrGet('src')
D
DCloud_LXH 已提交
9
						if (
D
DCloud_LXH 已提交
10
							!token.attrGet('loading') &&
D
DCloud_LXH 已提交
11
							src &&
D
DCloud_LXH 已提交
12
							src.indexOf('qiniu-web-assets.dcloud.net.cn') > -1
D
DCloud_LXH 已提交
13
						) {
D
DCloud_LXH 已提交
14
							token.attrPush(['loading', 'lazy'])
D
DCloud_LXH 已提交
15 16 17 18 19 20 21 22
						}
					}
				});
			}
		});
		return false;
	});
};