-
Notifications
You must be signed in to change notification settings - Fork 0
/
criticmarkup.js
39 lines (39 loc) · 1.94 KB
/
criticmarkup.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
38
39
var CriticMarkup = {
toHTML: function(markup) {
return markup.replace(/\{\-\-([\s\S]*?)\-\-[ \t]*(\[([\s\S]*?)\])?[ \t]*\}/gm, function(match, contents){
var replaceString = '';
if (contents.match(/^(\r\n|\n|\r)/) && !contents.match(/^(\r\n|\n|\r)$/)) {
replaceString = '\n\n<del> </del>\n\n';
// ???
replaceString = replaceString + '<del>' + contents.replace(/(\r\n|\n|\r)/, ' ');
replaceString = replaceString + '</del>';
} else if (contents.match(/^(\r\n|\n|\r)$/)) {
replaceString = replaceString + '\n\n<del> </del>\n\n';
} else {
replaceString = '<del>' + contents.replace(/^(\r\n|\n|\r)/, ' ') + '</del>';
}
return replaceString;
}).replace(/\{\+\+([\s\S]*?)\+\+[ \t]*(\[([\s\S]*?)\])?[ \t]*\}/gm, function(match, contents){
var replaceString = '';
if (contents.match(/^(\r\n|\n|\r)/) && !contents.match(/^(\r\n|\n|\r)$/)) {
replaceString = '\n\n<ins> </ins>\n\n';
// ???
replaceString = replaceString + '<ins>' + contents.replace(/(\r\n|\n|\r)/, ' ');
replaceString = replaceString + '</ins>';
} else if (contents.match(/^(\r\n|\n|\r)$/)) {
replaceString = replaceString + '\n\n<ins> </ins>\n\n';
} else {
replaceString = '<ins>' + contents.replace(/^(\r\n|\n|\r)/, ' ') + '</ins>';
}
return replaceString;
}).replace(/\{\=\=([\s\S]*?)\=\=\}\{\>\>([\s\S]*?)\<\<\}/gm, function(match, mark, comment) {
return '<mark>' + mark + '</mark><span class="critic comment">' + comment.replace(/(\r\n|\n|\r)/, ' ') + '</span>';
}).replace(/\{\>\>([\s\S]*?)\<\<\}/gm, function(match, comment){
return '<span class="critic comment">' + comment.replace(/^(\r\n|\n|\r)/, ' ') + '</span>';
}).replace(/\{\~\~([\s\S](?:[^\~\>]|(?:\~(?!\>)))*)\~\>([\s\S](?:[^\~\~]|(?:\~(?!\~\})))*)\~\~\}/gm, function(match, original, modified){
var delString = '<del>' + original + '</del>';
var insString = '<ins>' + modified + '</ins>'
return delString + insString;
});
}
};