forked from medialab/drive-out
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-markdown-parser.js
37 lines (29 loc) · 1.09 KB
/
custom-markdown-parser.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
var marked = require('marked'),
renderer = new marked.Renderer();
var oldLink = renderer.link;
// Helpers
function escape(s) {
return (s instanceof Array ? s : [s]).join(',').replace(/"/g, '\'');
}
// New link function
renderer.link = function(href, title, text) {
var wordlist = href.split('focus:');
// If no zoom is found, we apply standard behaviour
if (wordlist.length < 2)
return oldLink.apply(this, Array.prototype.slice.call(arguments));
var words = wordlist[1].split(',');
if (words.length > 1)
return '<span class="underline" data-click="' + escape(words) + '">' + text + '</span>';
else
return '<span class="underline" data-click="' + escape(words[0]) + '">' + text + '</span>';
};
// Exporting function
module.exports = function(string) {
return marked(string, {renderer: renderer});
};
/*
console.log(module.exports('Hello [Dany](zoom:agriculture)'));
console.log(module.exports('Hello [Dany](zoom:agriculture,system)'));
console.log(module.exports('Hello [Dany](zoom:agriculture,system,QELROs)'));
console.log(module.exports('Hello [Dany](http://localhost)'));
*/