-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
37 lines (36 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @Author: HuaChao Chen <chc>
* @Date: 2017-06-12T21:06:58+08:00
* @Email: [email protected]
* @Filename: index.js
* @Last modified by: chc
* @Last modified time: 2017-06-12T21:18:15+08:00
* @License: MIT
* @Copyright: 2017
*/
module.exports = function(md, config){
md.image_add = function(src, data){
if(!(md.__image instanceof Object))
md.__image = {}
md.__image[src] = data;
}
md.image_del = function(src){
if(!(md.__image instanceof Object))
md.__image = {}
delete md.__image[src];
}
var imagedefault = md.renderer.rules.image;
md.renderer.rules.image = function(tokens, idx, options, env, slf){
var _attrs = tokens[idx].attrs;
if(md.__image instanceof Object){
for(var i = 0;i < _attrs.length;i++){
if(_attrs[i][0] == 'src' && md.__image.hasOwnProperty(tokens[idx].attrs[i][1])){
_attrs.push(['rel', _attrs[i][1]]);
_attrs[i][1] = md.__image[tokens[idx].attrs[i][1]]
break;
}
}
}
return imagedefault(tokens, idx, options, env, slf);
}
}