-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateLink.html
More file actions
28 lines (22 loc) · 911 Bytes
/
Copy pathcreateLink.html
File metadata and controls
28 lines (22 loc) · 911 Bytes
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
<script>
;(function() {
var post = document.querySelector('article.post-content');
window.n = [];
(function iterate_node(node) {
if (/^(?:p|ul|h\d|table)$/i.test(node.tagName)) {
node.innerHTML = link(node.innerHTML);
} else { // Node.ELEMENT_NODE
for (var i = 0; i < node.childNodes.length; i++) {
iterate_node(node.childNodes[i]);
}
}
})(post);
function link(content) {
content = content.replace(/\\\[\[(.+?)\]\]/g, '\\[\\[$1\\]\\]');
content = content.replace(/\[\[(.+?)\]\]\{(.+?)\}/g, '<a href="../$1">$2</a>');
content = content.replace(/\[\[(.+?)\]\]/g, '<a href="../$1">$1</a>');
content = content.replace(/\\\[\\\[(.+?)\\\]\\\]/g, '[[$1]]');
return content;
}
})();
</script>