-
Notifications
You must be signed in to change notification settings - Fork 3
/
findTransclusions.js
31 lines (24 loc) · 1007 Bytes
/
findTransclusions.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
module.exports = {
md: function findMdTransclusions(text) {
// General +[]() transclusion link
//var mdLinks = text.match(/\+ \[ [^\[\]]* \] \( [^\)]+ \) /g)
//var mdLinks = text.match(/\+\[[^\[\]]*\]\([^\)]+\)/g)
// Specific +[](.md) transclusion link
//var mdLinks = text.match(/\+ \[ [^\[\]]* \] \( [^\)]+\.md\) /g)
var mdLinks = text.match(/\+\[[^\[\]]*\]\([^\)]+\.md\)/g)
if (mdLinks == null) return []
return mdLinks.map( seperateLabelAndLink )
},
image: function findImageTransclusions(text) {
//var link_pattern_matches = text.match(/\! \[ [^\[\]]* \] \( ^\)]+ \) /g)
var imageLinks = text.match(/\!\[[^\[\]]*\]\([^\)]+\)/g)
if (imageLinks == null) return []
return imageLinks.map( seperateLabelAndLink )
},
}
function seperateLabelAndLink(string) {
return {
label: string.replace(/^\+\[/, '').replace(/\].*$/, ''),
url: string.replace(/^.*\(/, '').replace(/\).*$/, '')
}
}