-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformat.js
36 lines (30 loc) · 1.01 KB
/
format.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
function format( data, outformat ) {
if ( ! outformat )
outformat = "text";
for(var i in data) {
if (!data[i])
data[i] = "";
}
switch(outformat) {
case "text":
return data.linktext;
case "html":
return '<a href="'+data.linkurl+'">'+data.linktext+'</a>';
case "mediawiki":
if (data.linkurl == "") {
return data.linktext;
} else if (data.linktext == "") {
return data.linkurl;
} else {
return "["+data.linkurl + " " + data.linktext + "]";
}
}
// fall through; we have a custom format
var output = outformat;
output = output.replace( /%%url%%/g, data.linkurl );
output = output.replace( /%%text%%/g, data.linktext );
output = output.replace( /%%title%%/g, data.linktitle );
output = output.replace( /%%pageurl%%/g, data.pageurl );
output = output.replace( /%%pagetitle%%/g, data.pagetitle );
return output;
}