mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-01-12 16:07:59 +00:00
option to apply, ignore or clear out posts markout
This commit is contained in:
parent
56dca3bfb7
commit
9df6ae2253
@ -136,6 +136,11 @@ function twisterOptions() {
|
||||
name: 'displayLineFeeds',
|
||||
valDefault: 'enable'
|
||||
});
|
||||
this.add({
|
||||
name: 'postsMarkout',
|
||||
selector: '#optPostsMarkout',
|
||||
valDefault: 'apply'
|
||||
});
|
||||
this.add({
|
||||
name: 'displayPreview',
|
||||
valDefault: 'disable'
|
||||
|
@ -258,6 +258,9 @@ function htmlFormatMsg(msg, mentions) {
|
||||
}
|
||||
|
||||
function markout(msg, chr, tag) {
|
||||
if ($.Options.postsMarkout.val === 'ignore')
|
||||
return msg;
|
||||
|
||||
function isWhiteSpacesBetween(i, j) {
|
||||
j++;
|
||||
for (i += 1; i < j; i++) {
|
||||
@ -375,20 +378,19 @@ function htmlFormatMsg(msg, mentions) {
|
||||
}
|
||||
|
||||
// changing the string
|
||||
if (chr === '`') {
|
||||
if (chr === '`' && $.Options.postsMarkout.val === 'apply') { // if $.Options.postsMarkout.val === 'clear' then ` does not escapes 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 = '<' + tag + '>' + Array(p[i].k).join(chr);
|
||||
t = Array(p[i].k).join(chr);
|
||||
else
|
||||
t = '<' + tag + '>';
|
||||
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) + '</' + tag + '>';
|
||||
else
|
||||
t = t + '</' + tag + '>';
|
||||
t = t + Array(p[i].k).join(chr);
|
||||
t = '<' + tag + '>' + t + '</' + tag + '>';
|
||||
msg.htmlEntities.push(t.replace(/&(?!lt;|gt;)/g, '&'));
|
||||
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);
|
||||
@ -400,18 +402,25 @@ function htmlFormatMsg(msg, mentions) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($.Options.postsMarkout.val === 'apply') {
|
||||
t = '</' + tag + '>';
|
||||
tag = '<' + tag + '>';
|
||||
} else { // $.Options.postsMarkout.val === 'clear' so we're clearing markup
|
||||
t = '';
|
||||
tag = '';
|
||||
}
|
||||
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)
|
||||
msg.htmlEntities.push('<' + tag + '>' + Array(p[i].k).join(chr));
|
||||
msg.htmlEntities.push(tag + Array(p[i].k).join(chr));
|
||||
else
|
||||
msg.htmlEntities.push('<' + tag + '>');
|
||||
msg.htmlEntities.push(tag);
|
||||
} else if (p[i].t === 1 || (p[i].t === 0 && p[i].a < i)) {
|
||||
if (p[i].k > 1)
|
||||
msg.htmlEntities.push(Array(p[i].k).join(chr) + '</' + tag + '>');
|
||||
msg.htmlEntities.push(Array(p[i].k).join(chr) + t);
|
||||
else
|
||||
msg.htmlEntities.push('</' + tag + '>');
|
||||
msg.htmlEntities.push(t);
|
||||
}
|
||||
htmlEntityEncoded = '>' + (msg.htmlEntities.length - 1).toString() + '<';
|
||||
msg.str = msg.str.slice(0, p[i].i) + htmlEntityEncoded + msg.str.slice(p[i].i + p[i].k);
|
||||
@ -477,7 +486,7 @@ function htmlFormatMsg(msg, mentions) {
|
||||
|
||||
// handling links
|
||||
for (i = 0; i < msg.str.length - 7; i++) {
|
||||
if (msg.str.slice(i, i + 2) === '](') {
|
||||
if (msg.str.slice(i, i + 2) === '](' && $.Options.postsMarkout.val !== 'ignore') {
|
||||
// FIXME there can be text with [] inside [] or links with () we need to handle it too
|
||||
j = getSubStrStart(msg.str, i - 2, '[', true, '');
|
||||
if (j < i - 1) {
|
||||
@ -505,10 +514,25 @@ function htmlFormatMsg(msg, mentions) {
|
||||
} else {
|
||||
if (getSubStrEnd(msg.str, i + 1, whiteSpacesUrl, false, '') < k) // use only first word as href target, others drop silently
|
||||
k = getSubStrEnd(msg.str, i + 1, whiteSpacesUrl, false, '');
|
||||
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
||||
newHtmlEntityLink(_htmlFormatMsgLinkTemplateExternal,
|
||||
proxyURL(msg.str.slice(i, k + 1)),
|
||||
applyHtml( // we're trying markup inside [] of []()
|
||||
if ($.Options.postsMarkout.val === 'apply') {
|
||||
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
||||
newHtmlEntityLink(_htmlFormatMsgLinkTemplateExternal,
|
||||
proxyURL(msg.str.slice(i, k + 1)),
|
||||
applyHtml( // we're trying markup inside [] of []()
|
||||
markout(markout(markout(markout(
|
||||
{str: linkName, htmlEntities: msg.htmlEntities},
|
||||
'*', 'b'), // bold
|
||||
'~', 'i'), // italic
|
||||
'_', 'u'), // underlined
|
||||
'-', 's') // striketrough
|
||||
)
|
||||
.replace(/&(?!lt;|gt;)/g, '&')
|
||||
)
|
||||
);
|
||||
} else { // $.Options.postsMarkout.val === 'clear' so we're clearing markup
|
||||
str = msg.str.slice(i, k + 1);
|
||||
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
||||
applyHtml( // we're trying to clear markup inside [] of []()
|
||||
markout(markout(markout(markout(
|
||||
{str: linkName, htmlEntities: msg.htmlEntities},
|
||||
'*', 'b'), // bold
|
||||
@ -517,8 +541,16 @@ function htmlFormatMsg(msg, mentions) {
|
||||
'-', 's') // striketrough
|
||||
)
|
||||
.replace(/&(?!lt;|gt;)/g, '&')
|
||||
)
|
||||
);
|
||||
);
|
||||
// here we put link target as plain text to handle it usual way (search http[s]:// and so on)
|
||||
i = msg.i + 1
|
||||
msg.str = msg.str.slice(0, i) + ' ' + str + msg.str.slice(i);
|
||||
/* alternatively we could set up it as link itself but I suppose you don't want it
|
||||
msg = msgAddHtmlEntity(msg, msg.i + 1, msg.i + 1,
|
||||
' ' + newHtmlEntityLink(_htmlFormatMsgLinkTemplateExternal,
|
||||
proxyURL(str), str)
|
||||
); */
|
||||
}
|
||||
}
|
||||
i = msg.i + 1;
|
||||
}
|
||||
|
10
options.html
10
options.html
@ -274,6 +274,16 @@
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container">
|
||||
<form action="">
|
||||
<p class="label">Markout</p>
|
||||
<select name="" id="optPostsMarkout" class="container">
|
||||
<option value="apply">Apply</option>
|
||||
<option value="ignore">Ignore</option>
|
||||
<option value="clear">Ignore and clear out</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container">
|
||||
<form action="" id="showPreviewOpt">
|
||||
<p class="label">Inline image preview</p>
|
||||
|
Loading…
Reference in New Issue
Block a user