-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathtoMediaWiki.html
41 lines (39 loc) · 1 KB
/
toMediaWiki.html
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
38
39
40
41
---
layout: Default
---
<textarea id="input"></textarea>
<button id="convert">convert</button>
<textarea id="output"></textarea>
<script>
document.getElementById('convert').onclick = ()=>{
let txt = document.getElementById('input').value;
txt = txt.replace(/####[^\n]*\n/g,x=>`== ${x.substring(4,x.length-1)} ==\n`);
txt = txt.replace(/###[^\n]*\n/g,x=>`== ${x.substring(3,x.length-1)} ==\n`);
txt = txt.replace(/##[^\n]*\n/g,x=>`== ${x.substring(2,x.length-1)} ==\n`);
txt = txt.replace(/```C\+\+/g,'<source lang = "c++" >');
txt = txt.replace(/```/g,'</source>');
txt = txt.replace(/\[[^[]*\]\([^(]*\)/g,s=>{
s = s.split('](');
s[0] = s[0].replace('[','');
s[1] = s[1].replace(')','');
return `[${s[1]} ${s[0]}]`;
});
let ans = "";
let isStart = 1;
for (let i=0;i<txt.length;i++) {
if (txt[i] == '$') {
if (isStart) {
ans += '<math>';
}
else {
ans += '</math>';
}
isStart ^= 1;
}
else {
ans += txt[i];
}
}
document.getElementById('output').value = ans;
}
</script>