Browse Source

markout: improve `` escaping

readme-update
Simon Grim 8 years ago
parent
commit
a2619a3bff
  1. 37
      js/twister_formatpost.js

37
js/twister_formatpost.js

@ -496,30 +496,6 @@ function htmlFormatMsg(msg, opt) {
} }
// changing the string // changing the string
if (chr === '`' && markoutOpt === 'apply') { // if markoutOpt === 'clear' then ` does not escape anythyng so it needs to be handled like other tags
for (i = 0; i < p.length; i++) {
if (p[i].a > -1) {
if (p[i].t === -1 || (p[i].t === 0 && p[i].a > i)) {
if (p[i].k > 1)
t = Array(p[i].k).join(chr);
else
t = '';
j = p[i].a;
t = t + msg.str.slice(p[i].i + p[i].k, p[j].i);
if (p[j].k > 1)
t = t + Array(p[i].k).join(chr);
t = '<' + tag + '>' + t + '</' + tag + '>';
msg.htmlEntities.push(t.replace(/&(?!lt;|gt;)/g, '&amp;'));
htmlEntityEncoded = '>' + (msg.htmlEntities.length - 1).toString() + '<';
msg.str = msg.str.slice(0, p[i].i) + htmlEntityEncoded + msg.str.slice(p[j].i + p[j].k);
l = htmlEntityEncoded.length - p[j].i - p[j].k + p[i].i;
i = j;
for (j += 1; j < p.length; j++)
p[j].i += l;
}
}
}
} else {
if (markoutOpt === 'apply') { if (markoutOpt === 'apply') {
t = '</' + tag + '>'; t = '</' + tag + '>';
tag = '<' + tag + '>'; tag = '<' + tag + '>';
@ -547,7 +523,6 @@ function htmlFormatMsg(msg, opt) {
p[j].i += l; p[j].i += l;
} }
} }
}
return msg; return msg;
} }
@ -610,7 +585,17 @@ function htmlFormatMsg(msg, opt) {
msg = {str: escapeHtmlEntities(msg), htmlEntities: []}; msg = {str: escapeHtmlEntities(msg), htmlEntities: []};
msg = markout(msg, markoutOpt, '`', 'samp'); // <samp> tag is kind of monospace, here sequence of chars inside it will be escaped from markup // markout is not applied for chars inside of ``; to escape ` use backslash
if (markoutOpt === 'apply')
msg.str = msg.str.replace(/`(?:[^`\\]|\\.)*`/g, function (s) {
msg.htmlEntities.push('<samp>' + s.slice(1, -1).replace(/\\`/g, '`')
.replace(/&(?!lt;|gt;)/g, '&amp;') + '</samp>');
return '>' + (msg.htmlEntities.length - 1).toString() + '<';
});
else if (markoutOpt === 'clear')
msg.str = msg.str.replace(/`((?:[^`\\]|\\.)*)`/g, function (s) {
return s.slice(1, -1).replace(/\\`/g, '`');
});
// handling links // handling links
for (i = 0; i < msg.str.length - 7; i++) { for (i = 0; i < msg.str.length - 7; i++) {

Loading…
Cancel
Save