Last active
August 29, 2015 14:21
-
-
Save tyage/e412fe9346265549b11e to your computer and use it in GitHub Desktop.
slackのフォーマット変更部分 source: https://slack.global.ssl.fastly.net/2e12/js/rollup-secondary_required.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
TS.registerModule("format", { | |
testing_with_generic_tokens: false, | |
theme_rx: /((?:#[A-Fa-f0-9]{6} {0,1}, {0,1}){7})(#[A-Fa-f0-9]{6})(\b)/g, | |
onStart: function() { | |
if (TS.boot_data.feature_at_here) { | |
b.push("here") | |
} | |
}, | |
cleanMsg: function(e) { | |
if (!e) { | |
return "" | |
} | |
e = e.replace(/\&/g, "&"); | |
e = e.replace(/</g, "<"); | |
e = e.replace(/>/g, ">"); | |
e = e.replace(/(^|\s|\(|>|\*|_)(@[\w|.|-]+)/g, function(h, k, j) { | |
var i = ""; | |
var f = j.toLowerCase(); | |
var g; | |
if (/^@everyone[\.|\-|_]*$/.test(f)) { | |
g = "<!everyone>"; | |
i = f.substr("!everyone".length) | |
} else { | |
if (/^@here[\.|\-|_]*$/.test(f) && TS.boot_data.feature_at_here) { | |
g = "<!here|@here>"; | |
i = f.substr("!here".length) | |
} else { | |
if (/^@channel[\.|\-|_]*$/.test(f)) { | |
g = "<!channel>"; | |
i = f.substr("!channel".length) | |
} else { | |
if (/^@group[\.|\-|_]*$/.test(f)) { | |
g = "<!group>"; | |
i = f.substr("!group".length) | |
} | |
} | |
} | |
} | |
if (g) { | |
return k + g + i | |
} | |
h = TS.members.getMemberByName(j); | |
var o = [".", "..", "...", "....", "-", "--", "_"]; | |
var l; | |
var p = 0; | |
while (!h && p < o.length) { | |
l = o[p]; | |
if (j && j.substr(j.length - l.length, l.length) == l) { | |
var n = j.substr(0, j.length - l.length); | |
i = l; | |
h = TS.members.getMemberByName(n) | |
} | |
p++ | |
} | |
if (h) { | |
return k + "<@" + h.id + ">" + i | |
} | |
return k + j | |
}); | |
e = e.replace(/(^|\s|\(|>|\*|_)(#[a-zA-Z0-9\-_]+)/g, function(f, i, h) { | |
var l = TS.channels.getChannelByName(h); | |
var g = ""; | |
var n = ["-", "--", "_"]; | |
var j; | |
var o = 0; | |
while (!l && o < n.length) { | |
j = n[o]; | |
if (h && h.substr(h.length - j.length, j.length) == j) { | |
var k = h.substr(0, h.length - j.length); | |
g = j; | |
l = TS.channels.getChannelByName(k); | |
if (l) { | |
g = j | |
} | |
} | |
o++ | |
} | |
if (l) { | |
return i + "<#" + l.id + ">" + g | |
} | |
return i + h | |
}); | |
if (TS.model.prefs.convert_emoticons && TS.model.prefs.emoji_mode != "as_text") { | |
e = TS.format.doEmoticonConversion(e) | |
} | |
return e | |
}, | |
emoticon_conversion_token_map: [], | |
emoticonConversionTokenReplacer: function(e) { | |
return TS.format.tokenizeStr(TS.format.emoticon_conversion_token_map, e) | |
}, | |
doEmoticonConversion: function(e) { | |
TS.format.emoticon_conversion_token_map.length = 0; | |
e = e.replace(TS.format.special_pre_rx, TS.format.emoticonConversionTokenReplacer); | |
e = e.replace(TS.format.special_code_rx, TS.format.emoticonConversionTokenReplacer); | |
e = e.replace(TS.format.special_quote_rx, TS.format.emoticonConversionTokenReplacer); | |
e = emoji.replace_emoticons_with_colons(e); | |
e = TS.format.deTokenizeStr(TS.format.emoticon_conversion_token_map, e); | |
return e | |
}, | |
token_cnt: 0, | |
token_base: "~^$-+—!?][{}~^$-+—!?][{}~^$-+—!?][{}~^$-+—!?][{}~^$-+—!?][{}~^$-+—!?][{}~^$-+—!?][{}".split("").sort(function() { | |
return 0.5 - Math.random() | |
}).join(""), | |
tokenizeStr: function(g, h, i) { | |
if (!h) { | |
return "" | |
} | |
i = i || ""; | |
var e = (h.indexOf("\n") === 0) ? "\n" : ""; | |
var f = TS.format.encodeSpecialFormattingCharsAndColon(e + TS.format.token_base + (TS.format.token_cnt++) + TS.utility.date.getTimeStamp()); | |
f = i + f + i; | |
g.push({ | |
str: h, | |
token: f | |
}); | |
return f | |
}, | |
deTokenizeStr: function(f, h) { | |
var g; | |
var e = f.length - 1; | |
for (e; e > -1; e--) { | |
g = f[e]; | |
h = h.replace(g.token, g.str.replace(/\$/g, "$$$$")) | |
} | |
return h | |
}, | |
unFormatMsg: function(e, f) { | |
if (!e) { | |
return "" | |
} | |
return TS.format.formatWithOptions(e, f, { | |
for_edit: true | |
}) | |
}, | |
formatJustText: function(e) { | |
return TS.format.formatWithOptions(e) | |
}, | |
formatDefault: function(e, f) { | |
return TS.format.formatWithOptions(e, f) | |
}, | |
formatNotification: function(e, f) { | |
return TS.format.formatWithOptions(e, f, { | |
for_growl: true | |
}) | |
}, | |
formatWithOptions: function(s, n, r) { | |
var l = (r && !!r.do_inline_imgs) || undefined; | |
var x = (r && !!r.for_growl) || undefined; | |
var q = (r && !!r.for_edit) || undefined; | |
var g = (r && !!r.no_highlights) || undefined; | |
var z = (r && !!r.no_specials) || undefined; | |
var w = (r && !!r.enable_slack_action_links) || undefined; | |
var h = (r && !!r.force_tsf_despite_mismatch) || undefined; | |
g = (n && ("no_highlights" in n)) ? !!n.no_highlights : !!g; | |
if (z === true || z === false) { | |
z = z | |
} else { | |
if (n && ("mrkdwn" in n)) { | |
z = (n.mrkdwn === false) | |
} else { | |
z = false | |
} | |
} | |
if (q) { | |
z = true | |
} | |
var t = (n && n.no_emoji); | |
var v = !(l && (!n || n.subtype != "bot_message")); | |
var e = (!v && TS.client && TS.model.team && TS.model.team.domain == "tinyspeck"); | |
if (!s) { | |
return "" | |
} | |
var y = $.trim(s); | |
if (!y) { | |
return "" | |
} | |
var o; | |
var f; | |
if (window.TSF) { | |
try { | |
f = "NORMAL"; | |
if (z) { | |
f = "NOMRKDWN" | |
} | |
if (x) { | |
f = "GROWL" | |
} | |
if (q) { | |
f = "EDIT" | |
} | |
o = c(s, n, f, z, g, t, v, l, w, e) | |
} catch (m) { | |
TS.error("error testing TSF:" + m); | |
TS.info("txt was:" + s) | |
} | |
} | |
var k = []; | |
var j = []; | |
var u = function(V, C, G, U) { | |
var Y; | |
var S; | |
var N; | |
var aa; | |
if (C.substr(0, 1) == "#") { | |
var M = C.substr(1); | |
N = M.split("|"); | |
S = N[0]; | |
Y = TS.channels.getChannelById(S); | |
if (!Y) { | |
Y = TS.channels.getChannelByName(S) | |
} | |
if (Y) { | |
if (x || q) { | |
return TS.format.tokenizeStr(k, "#" + Y.name) | |
} | |
aa = TS.utility.shouldLinksHaveTargets() ? 'target="/archives/' + Y.name + '"' : ""; | |
if (TS.format.testing_with_generic_tokens) { | |
return TS.format.tokenizeStr(k, TS.format.generic_link_open + "#" + Y.name + TS.format.link_close) | |
} | |
return TS.format.tokenizeStr(k, '<a href="/archives/' + Y.name + '" ' + aa + ' data-channel-name="' + Y.name + '" data-channel-id="' + Y.id + '" class="internal_channel_link">#' + Y.name + TS.format.link_close) | |
} else { | |
if (N.length > 1 && N[1]) { | |
return TS.format.tokenizeStr(k, "#" + N[1]) | |
} else { | |
if (TS.model.user.is_restricted) { | |
return TS.format.tokenizeStr(k, "#unknown-channel") | |
} else { | |
return TS.format.tokenizeStr(k, "#deleted-channel") | |
} | |
} | |
} | |
} | |
if (C.substr(0, 1) == "@") { | |
V = TS.utility.msgs.getMemberFromMemberMarkup(C); | |
if (V) { | |
if (x || q) { | |
return TS.format.tokenizeStr(k, "@" + V.name) | |
} | |
aa = TS.utility.shouldLinksHaveTargets() ? 'target="/team/' + V.name + '" ' : ""; | |
var ab = (g) ? "@" + V.name : TS.format.doHighlighting("@" + V.name); | |
if (TS.format.testing_with_generic_tokens) { | |
return TS.format.tokenizeStr(k, TS.format.generic_link_open + ab + TS.format.link_close) | |
} | |
return TS.format.tokenizeStr(k, '<a href="/team/' + V.name + '" ' + aa + 'data-member-name="' + V.name + '" class="internal_member_link">' + ab + TS.format.link_close) | |
} else { | |
return TS.format.tokenizeStr(k, C) | |
} | |
} | |
if (C.substr(0, 1) == "!") { | |
var W = C.substr(1); | |
var R = (W || "").split("|"); | |
W = R[0]; | |
var P = (R[1]) ? R[1] : W; | |
if (TS.utility.inArray(b, W)) { | |
if (x || q) { | |
return TS.format.tokenizeStr(k, "@" + W) | |
} | |
return TS.format.tokenizeStr(k, '<b class="mention">@' + W + "</b>") | |
} else { | |
if (W.indexOf("^") !== -1) { | |
var J = W.split("^"); | |
W = J[0]; | |
if (W === "date" && J.length >= 3 && TS.boot_data.feature_client_date_formatting) { | |
var T = J[1]; | |
var ac = J[2]; | |
var O = (J.length > 3) ? J[3] : ""; | |
var E = (O === "" || x || q) ? "" : "<a " + TS.utility.makeRefererSafeLink(O) + ' target="_blank">'; | |
var A = (O === "" || x || q) ? "" : TS.format.link_close; | |
return TS.format.tokenizeStr(k, E + TS.utility.date.formatDate(ac, T, P) + A) | |
} else { | |
return TS.format.tokenizeStr(k, P) | |
} | |
} | |
} | |
if (x || q) { | |
return TS.format.tokenizeStr(k, "<" + P + ">") | |
} else { | |
return TS.format.tokenizeStr(k, "<" + P + ">") | |
} | |
} | |
var Z = C.split("|"); | |
var D = Z.shift(); | |
D = D.replace(/\"/g, """); | |
var I = Z.join("|") || D; | |
I = $.trim(I); | |
if (D.indexOf("<") === 0) { | |
return TS.format.tokenizeStr(k, "<" + C.replace(/</g, "<").replace(/>/g, ">") + ">") | |
} | |
I = I.replace(/</g, "<"); | |
I = I.replace(/>/g, ">"); | |
if (x) { | |
if (I == D) { | |
var K = (D.indexOf("//") > -1) ? D.split("//")[1] : D; | |
K = jQuery.trim(K).substring(0, 30).trim(this) + "..."; | |
return "" + K + "" | |
} | |
return "<" + I + ">" | |
} else { | |
if (q) { | |
return I | |
} | |
} | |
if (!z && I != D) { | |
I = TS.format.doSpecials(I, n && n._special_debug) | |
} | |
if (!t && I != D) { | |
I = TS.utility.emojiReplace(I, j) | |
} | |
if (!g) { | |
I = TS.format.doHighlighting(I) | |
} | |
var H; | |
if (D.indexOf(TS.utility.msgs.api_url_prefix + "chat.help") === 0) { | |
if (w) { | |
H = TS.utility.htmlEntities(TS.utility.jsString(D)); | |
return TS.format.tokenizeStr(k, '<a onclick="TS.utility.msgs.doApiUrl(' + H + ')" class="api_url">' + I + TS.format.link_close) | |
} else { | |
return TS.format.tokenizeStr(k, '<a class="api_url muted">(Disabled) ' + I + TS.format.link_close) | |
} | |
} else { | |
if (D.indexOf(TS.utility.msgs.new_api_url_prefix) === 0) { | |
if (w) { | |
H = TS.utility.htmlEntities(TS.utility.jsString(D)); | |
return TS.format.tokenizeStr(k, '<a onclick="TS.utility.msgs.doNewApiUrl(' + H + ')" class="api_url">' + I + TS.format.link_close) | |
} else { | |
return TS.format.tokenizeStr(k, '<a class="api_url muted">(Disabled) ' + I + TS.format.link_close) | |
} | |
} else { | |
if (D.indexOf("javascript:") == 0) { | |
return TS.format.tokenizeStr(k, '<a onclick="' + D.replace("javascript:", "") + '">' + I + TS.format.link_close) | |
} else { | |
if (TS.client && TS.client.core_url && D.indexOf(TS.client.core_url) === 0) { | |
if (TS.format.testing_with_generic_tokens) { | |
return TS.format.tokenizeStr(k, TS.format.generic_link_open + I + TS.format.link_close) | |
} | |
return TS.format.tokenizeStr(k, '<a target="_self" href="' + D + '">' + I + TS.format.link_close) | |
} else { | |
var X = ""; | |
var L; | |
if (n && n.ts && l) { | |
L = TS.inline_attachments.getAttachmentByFromUrl(n.attachments, D); | |
if (L) { | |
if (TS.boot_data.feature_attachments_inline || TS.templates.builders.shouldDoSimpleAttachment(L, n)) { | |
X = TS.templates.builders.buildAttachmentHTML({ | |
attachment: L, | |
url: D, | |
msg: n, | |
show_initial_caret: true | |
}).replace(/\n/g, "").replace(/\t/g, "").replace(/ /g, " ") | |
} | |
} | |
} | |
if (X) { | |
X = X.replace(/\n/g, "").replace(/\t/g, "").replace(/ +/g, " ") | |
} | |
if (TS.format.testing_with_generic_tokens) { | |
return TS.format.tokenizeStr(k, TS.format.generic_link_open + I + TS.format.link_close + X) | |
} | |
var B = TS.utility.getFileIDFromURL(D); | |
var F = (B) ? ' class="file_preview_link"' : ""; | |
var Q = (B) ? ' data-file-id="' + B + '"' : ""; | |
return TS.format.tokenizeStr(k, "<a " + TS.utility.makeRefererSafeLink(D) + ' target="_blank"' + F + Q + ">" + I + TS.format.link_close + X) | |
} | |
} | |
} | |
} | |
}; | |
y = y.replace(/<(.*?)>/g, u); | |
y = y.replace(/\</g, "<"); | |
y = y.replace(/\>/g, ">"); | |
if (q) { | |
y = TS.utility.unHtmlEntities(y) | |
} else { | |
if (x) { | |
if (TS.utility.platformSupportsHtmlNotifications()) { | |
if (TS.utility.platformSupportsImgEmojiInHtmlNotifications()) { | |
y = TS.utility.emojiReplace(y, null, true) | |
} | |
} else { | |
y = TS.utility.unHtmlEntities(y); | |
if (emoji.replace_mode == "unified") { | |
y = emoji.replace_colons_with_unified(y) | |
} | |
} | |
} else { | |
TS.format.special_token_map = []; | |
if (!z) { | |
y = TS.format.doSpecials(y, n && n._special_debug) | |
} | |
if (!v) { | |
if (e) { | |
y = y.replace(TS.format.theme_rx, function(B, A, C) { | |
return A + "<nobr>" + C + " " + TS.format.tokenizeStr(TS.format.special_token_map, a(B) + "</nobr>") | |
}) | |
} | |
y = y.replace(TS.format.hex_rx, TS.format.hexReplace) | |
} | |
if (!t) { | |
y = TS.utility.emojiReplace(y, j) | |
} | |
y = TS.format.deTokenizeStr(TS.format.special_token_map, y); | |
TS.format.special_token_map = null; | |
if (!g) { | |
y = TS.format.doHighlighting(y) | |
} | |
y = y.replace(/<\/div>\n/g, "</div>"); | |
y = y.replace(/<\/pre>\n/g, "</pre>"); | |
y = y.replace(/codecopyonly> /g, "codecopyonly> "); | |
y = y.replace(/ <span class="codecopyonly/g, ' <span class="codecopyonly'); | |
y = y.replace(/ /g, " "); | |
y = y.replace(/\n\r\n\r/g, TS.format.para_break); | |
y = y.replace(/\n\r\n/g, TS.format.para_break); | |
y = y.replace(/\n\n/g, TS.format.para_break); | |
y = y.replace(/\n/g, TS.format.line_break); | |
y = y.replace(/\t/g, " "); | |
y = y.replace(/ /g, " "); | |
y = y.replace(/^ /g, " ") | |
} | |
} | |
y = TS.format.deTokenizeStr(k, y); | |
y = TS.format.deTokenizeStr(j, y); | |
j = null; | |
if (window.TSF && o) { | |
if (o != y) { | |
TS.error("======================================================================== " + f + " " + (o == y)); | |
TS.info("txt :" + s); | |
TS.info("new_txt :" + y); | |
TS.info("tsf_str :" + o); | |
if (TS.model.user.id == "U024BE7LM" || TS.model.user.id == "U032VEM0B") { | |
window._temp_bad_message_hash = window._temp_bad_message_hash || {}; | |
var i = "format bot"; | |
var p = (n) ? n.ts : s.substr(0, 30); | |
if (!window._temp_bad_message_hash[p] && (!n || n.username != i)) { | |
window._temp_bad_message_hash[p] = true; | |
TS.ims.addMsg(TS.ims.getImByMemberId("USLACKBOT").id, { | |
type: "message", | |
subtype: "bot_message", | |
is_ephemeral: true, | |
username: i, | |
icons: { | |
emoji: ":symbols:" | |
}, | |
ts: TS.utility.date.makeTsStamp(), | |
text: "check console for bad message report! ts: " + (n ? n.ts : "unknown") | |
}) | |
} | |
} | |
if (h) { | |
return o | |
} | |
} else { | |
if (window.show_all_msg_tests) { | |
TS.warn("================================" + f + " " + (o == y)); | |
TS.info("new_txt:" + y); | |
TS.info("tsf_str:" + o) | |
} | |
return o | |
} | |
} | |
return y | |
}, | |
hex_rx: /(\W|^)(#[A-Fa-f0-9]{6})(\b)/g, | |
hexReplace: function(f, g, e, h) { | |
return g + e + ' <div class="inline_color_block" style="background:' + e + ';"></div>' + h | |
}, | |
special_i_rx: /(^|\s|[\?\.,\-!\^;:{(\[%$#+=\u2000-\u206F\u2E00-\u2E7F"])\_(.*?\S *)?\_($|\s|[\?\.,\-!\^;:})\]%$#+=\u2000-\u206F\u2E00-\u2E7F…"])/g, | |
special_b_rx: /(^|\s|[\?\.,\-!\^;:{(\[%$#+=\u2000-\u206F\u2E00-\u2E7F"])\*(.*?\S *)?\*(?=$|\s|[\?\.,\-!\^;:})\]%$#+=\u2000-\u206F\u2E00-\u2E7F…"])/g, | |
special_code_rx: /(^|\s|[\?\.,\-!\^;:{(\[%$#+=\u2000-\u206F\u2E00-\u2E7F"])\`(.*?\S *)?\`/g, | |
special_pre_rx: /(^|\s|[\?\.,\-!\^;:{(\[%$#+=\u2000-\u206F\u2E00-\u2E7F"])```([\s\S]*?)?```(?=$|\s|[\?\.,\-!\^;:})\]%$#+=\u2000-\u206F\u2E00-\u2E7F…"])/g, | |
special_quote_rx: /(^|\n)>(?Dpb](?=\s|$)))(([^\n]*)(\n>[^\n]*)*)/g, | |
special_3_quote_rx: /(^|\n)>>>([\s\S]*$)/, | |
special_quote_prefix: '<span class="copyonly">></span>', | |
special_longquote_prefix: '<span class="copyonly">>>></span>', | |
special_i_open: '<i><span class="copyonly">_</span>', | |
special_i_close: '<span class="copyonly">_</span></i>', | |
special_b_open: '<b><span class="copyonly">*</span>', | |
special_b_close: '<span class="copyonly">*</span></b>', | |
special_pre_open: '<pre class="special_formatting"><span class="copyonly">```</span>', | |
special_pre_close: '<span class="copyonly">```</span></pre>', | |
special_code_open: '<code><span class="copyonly">`</span codecopyonly>', | |
special_code_close: '<span class="codecopyonly copyonly">`</span></code>', | |
special_quote_open: '<div class="special_formatting_quote"><div class="quote_bar"><div class="shim"></div></div><div class="content dynamic_content_max_width">', | |
special_quote_close: "</div></div>", | |
line_break: "<br>", | |
hard_space: " ", | |
generic_link_open: "<a>", | |
link_close: "</a>", | |
para_break: '<span class="para_break"><i class="copy_only"><br></i></span>', | |
specialPreReplace: function(f, e, g) { | |
if (!g) { | |
return f | |
} | |
if (g && g.length && g.substr(0, 1) == "\n") { | |
g = g.substr(1) | |
} | |
if (TS.format.special_token_map) { | |
g = TS.format.encodeForPre(g); | |
return e + TS.format.special_pre_open + TS.format.tokenizeStr(TS.format.special_token_map, g) + TS.format.special_pre_close | |
} | |
g = TS.format.encodeSpecialFormattingCharsAndMoreForPre(g); | |
return e + TS.format.special_pre_open + (g) + TS.format.special_pre_close | |
}, | |
specialCodeReplace: function(f, e, g) { | |
if (TS.format.log_specials) { | |
TS.warn('match in specialCodeReplace:\n"' + f + '"') | |
} | |
if (!g || g.substr(0, 1) == "`" || g.substr(g.length - 1, 1) == "`" || (g.match(/<pre/g) && g.match(/<\/pre/g))) { | |
return f | |
} | |
if (TS.format.special_token_map) { | |
return e + TS.format.special_code_open + TS.format.tokenizeStr(TS.format.special_token_map, g) + TS.format.special_code_close | |
} | |
g = TS.format.encodeSpecialFormattingCharsAndColon(g); | |
return e + TS.format.special_code_open + g + TS.format.special_code_close | |
}, | |
specialItalicReplace: function(f, e, h, g) { | |
if (TS.format.log_specials) { | |
TS.warn('match in specialItalicReplace:\n"' + f + '"') | |
} | |
if (!h || !h.match(/[^_*`]/) || h.substr(0, 1) == "_" || h.substr(h.length - 1, 1) == "_" || (e == ":" && g == ":")) { | |
return f | |
} | |
return e + TS.format.special_i_open + TS.format.doSpecials(h) + TS.format.special_i_close + g | |
}, | |
specialBoldReplace: function(f, e, g) { | |
if (!g || !g.match(/[^_*`]/) || g.substr(0, 1) == "*" || g.substr(g.length - 1, 1) == "*" || (g.substr(0, 1) == " " && g.substr(g.length - 1, 1) == " ")) { | |
return f | |
} | |
return e + TS.format.special_b_open + TS.format.doSpecials(g) + TS.format.special_b_close | |
}, | |
specialQuoteReplace: function(f, e, h, g) { | |
if (f == ">") { | |
return f | |
} | |
h = h.replace(/\n>/g, "\n" + TS.format.special_quote_prefix); | |
return TS.format.special_quote_open + TS.format.special_quote_prefix + h + TS.format.special_quote_close | |
}, | |
special3QuoteReplace: function(f, e, g) { | |
if (f == ">>>") { | |
return ">>>" | |
} | |
g = g.replace(/^([\s]*)(>)*/g, function(h, j, i, l, k) { | |
if (i) { | |
return h | |
} | |
return "" | |
}); | |
return TS.format.special_quote_open + TS.format.special_longquote_prefix + g + TS.format.special_quote_close | |
}, | |
log_specials: false, | |
doSpecials: function(f, e) { | |
f = f || ""; | |
if (e) { | |
TS.info("debugging specials for text:::::::::::::::::::::\n" + f); | |
TS.format.log_specials = true | |
} | |
f = f.replace(TS.format.special_pre_rx, TS.format.specialPreReplace); | |
f = f.replace(TS.format.special_code_rx, TS.format.specialCodeReplace); | |
f = f.replace(TS.format.special_i_rx, TS.format.specialItalicReplace); | |
f = f.replace(TS.format.special_b_rx, TS.format.specialBoldReplace); | |
f = f.replace(TS.format.special_3_quote_rx, TS.format.special3QuoteReplace); | |
f = f.replace(TS.format.special_quote_rx, TS.format.specialQuoteReplace); | |
TS.format.log_specials = false; | |
return f | |
}, | |
at_symbol_token: "thisreplacementtokenallowsustotreatatsymbolsasiftheywerewordcharactersinregex".split("").sort(function() { | |
return 0.5 - Math.random() | |
}).join(""), | |
swapInAts: function(e) { | |
if (!e) { | |
return e | |
} | |
return e.replace(new RegExp(TS.format.at_symbol_token, "g"), "@") | |
}, | |
swapOutAts: function(e) { | |
if (!e) { | |
return e | |
} | |
return e.replace(/@/g, TS.format.at_symbol_token) | |
}, | |
doHighlighting: function(g) { | |
var m; | |
var l; | |
var e = TS.model.highlight_words.concat(); | |
e.sort(function k(n, i) { | |
var o = n.length; | |
var p = i.length; | |
if (o < p) { | |
return 1 | |
} | |
if (o > p) { | |
return -1 | |
} | |
return 0 | |
}); | |
var f = false; | |
if (g.indexOf("@") != -1) { | |
f = true; | |
g = TS.format.swapOutAts(g) | |
} | |
for (var h = 0; h < e.length; h++) { | |
m = e[h]; | |
if (f) { | |
m = TS.format.swapOutAts(e[h]) | |
} | |
m = TS.utility.regexpEscape(m); | |
if (m == "don") { | |
m += "(?!'t)" | |
} | |
l = new RegExp("(\\b|_|\\s|^)(" + m + ")(\\b|_|\\s|$)", "ig"); | |
var j = 0; | |
g = g.replace(l, function(o, p, n, t, s, r) { | |
if (r.substr(0, s).match(/</)) { | |
for (var q = s; q >= j; q--) { | |
if (r.charAt(q) == "<") { | |
return p + n + t | |
} | |
if (r.charAt(q) == ">") { | |
break | |
} | |
} | |
} | |
j = s + o.length; | |
return p + '<span class="mention">' + n + "</span>" + t | |
}) | |
} | |
if (f) { | |
return TS.format.swapInAts(g) | |
} else { | |
return g | |
} | |
}, | |
encodeSpecialFormattingChars: function(e) { | |
e = e || ""; | |
return e.replace(/\*/g, "*").replace(/\_/g, "_").replace(/\`/g, "`") | |
}, | |
encodeSpecialFormattingCharsAndColon: function(e) { | |
e = e || ""; | |
return TS.format.encodeSpecialFormattingChars(e).replace(/\:/g, ":") | |
}, | |
encodeSpecialFormattingCharsAndMoreForPre: function(e) { | |
e = e || ""; | |
return TS.format.encodeForPre(TS.format.encodeSpecialFormattingCharsAndColon(e)) | |
}, | |
encodeForPre: function(e) { | |
e = e || ""; | |
return e.replace(/</g, "<").replace(/>/g, ">").replace(/\n/g, TS.format.line_break) | |
} | |
}); | |
var b = ["everyone", "channel", "group"]; | |
var d; | |
var c = function(k, P, l, p, n, B, x, V, D, J) { | |
d = d || { | |
"<B:START>": TS.format.special_b_open, | |
"<B:END>": TS.format.special_b_close, | |
"<PRE:START>": TS.format.special_pre_open, | |
"<PRE:END>": TS.format.special_pre_close, | |
"<CODE:START>": TS.format.special_code_open, | |
"<CODE:END>": TS.format.special_code_close, | |
"<I:START>": TS.format.special_i_open, | |
"<I:END>": TS.format.special_i_close, | |
"<QUOTE:START>": TS.format.special_quote_open, | |
"<QUOTE:PREFIX>": TS.format.special_quote_prefix, | |
"<LONGQUOTE:PREFIX>": TS.format.special_longquote_prefix, | |
"<QUOTE:END>": TS.format.special_quote_close, | |
"<LINK:END>": TS.format.link_close, | |
"<LINE:BREAK>": TS.format.line_break, | |
"<PARA:BREAK>": TS.format.para_break, | |
"<SPACE:HARD>": TS.format.hard_space | |
}; | |
var E = d; | |
var M = []; | |
if (J) { | |
k = k.replace(TS.format.theme_rx, function(A, i, Y) { | |
return i + TS.format.tokenizeStr(M, "<nobr>", ",") + Y + " " + TS.format.tokenizeStr(M, a(A) + "</nobr>") | |
}) | |
} | |
var G = ""; | |
var r = TSF.getTokensArray($.trim(k), l); | |
var X; | |
var I; | |
var F; | |
var T; | |
var K; | |
var R; | |
var u; | |
var e; | |
var U; | |
var Q; | |
var t; | |
var v; | |
var C; | |
var q; | |
var o; | |
var H; | |
var z; | |
if (l == "GROWL" || l == "EDIT") { | |
for (T = 0; T < r.length; T++) { | |
F = r[T]; | |
if (F.indexOf("<") === 0) { | |
if (E[F]) { | |
TS.error('unexpected: mode == "GROWL" || "EDIT", and yet we got something in the formatting map? ' + F) | |
} else { | |
if (F.indexOf("<!") === 0) { | |
I = F.replace(/<|>/g, ""); | |
t = (I || "").split("|"); | |
U = t[0].substr(1); | |
if (TS.utility.inArray(b, U)) { | |
G += "@" + U | |
} else { | |
Q = (t[1]) ? t[1] : U; | |
if (U.indexOf("^") !== -1) { | |
v = U.split("^"); | |
U = v[0]; | |
if (U === "date" && v.length >= 3 && TS.boot_data.feature_client_date_formatting) { | |
C = v[1]; | |
q = v[2]; | |
G += TS.utility.date.formatDate(q, C, Q) | |
} else { | |
G += "<" + Q + ">" | |
} | |
} else { | |
G += "<" + Q + ">" | |
} | |
} | |
} else { | |
if (F.indexOf("<@") === 0) { | |
I = F.replace(/<|>/g, ""); | |
R = TS.utility.msgs.getMemberFromMemberMarkup(I); | |
if (R) { | |
G += "@" + R.name | |
} else { | |
if (l == "EDIT") { | |
G += I | |
} else { | |
if (l == "GROWL") { | |
G += F | |
} | |
} | |
} | |
} else { | |
if (F.indexOf("<#") === 0) { | |
I = F.replace(/<|>|#/g, ""); | |
u = I.split("|"); | |
K = u[0]; | |
X = TS.channels.getChannelById(K); | |
if (X) { | |
G += "#" + X.name | |
} else { | |
if (u.length > 1 && u[1]) { | |
G += "#" + u[1] | |
} else { | |
if (TS.model.user.is_restricted) { | |
G += "#unknown-channel" | |
} else { | |
G += "#deleted-channel" | |
} | |
} | |
} | |
} else { | |
if (F.indexOf(TSF.LINK_START.split(" ")[0]) === 0) { | |
TS.error('unexpected: mode == "GROWL" || "EDIT", and yet we got ' + F) | |
} else { | |
if (F.indexOf(TSF.EMOJI_COLONS.split(" ")[0]) === 0) { | |
TS.error('unexpected: mode == "GROWL" || "EDIT", and yet we got ' + F) | |
} else { | |
if (F.indexOf(TSF.HEX_BLOCK.split(" ")[0]) === 0) { | |
TS.error('unexpected: mode == "GROWL" || "EDIT", and yet we got ' + F) | |
} else { | |
TS.error("markup token not handled:" + F) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} else { | |
if (F.indexOf("<") == -1) { | |
if (l == "EDIT") { | |
G += TS.utility.unHtmlEntities(F) | |
} else { | |
if (l == "GROWL") { | |
if (TS.utility.platformSupportsHtmlNotifications()) { | |
if (TS.utility.platformSupportsImgEmojiInHtmlNotifications()) { | |
G += TS.utility.emojiReplace(F, null, true) | |
} | |
} else { | |
var S = TS.utility.unHtmlEntities(F); | |
if (emoji.replace_mode == "unified") { | |
S = emoji.replace_colons_with_unified(S) | |
} | |
G += S | |
} | |
} | |
} | |
} else { | |
TS.error("token has a < in it but it is not the first character!\n" + F) | |
} | |
} | |
} | |
} else { | |
var W = ""; | |
var s; | |
for (T = 0; T < r.length; T++) { | |
F = r[T]; | |
if (F.indexOf("<") === 0) { | |
if (E[F]) { | |
G += E[F]; | |
if (F == TSF.LINK_END) { | |
G += W; | |
W = "" | |
} | |
} else { | |
if (F.indexOf("<!") === 0) { | |
I = F.replace(/<|>/g, ""); | |
t = (I || "").split("|"); | |
U = t[0].substr(1); | |
if (TS.utility.inArray(b, U)) { | |
G += '<b class="mention">@' + U + "</b>" | |
} else { | |
Q = (t[1]) ? t[1] : U; | |
if (U.indexOf("^") !== -1) { | |
v = U.split("^"); | |
U = v[0]; | |
if (U === "date" && v.length >= 3 && TS.boot_data.feature_client_date_formatting) { | |
C = v[1]; | |
q = v[2]; | |
o = (v.length > 3) ? v[3] : ""; | |
H = (o === "") ? "" : "<a " + TS.utility.makeRefererSafeLink(o) + ' target="_blank">'; | |
z = (o === "") ? "" : TS.format.link_close; | |
G += H + TS.utility.date.formatDate(q, C, Q) + z | |
} else { | |
G += "<" + Q + ">" | |
} | |
} else { | |
G += "<" + Q + ">" | |
} | |
} | |
} else { | |
if (F.indexOf("<@") === 0) { | |
I = F.replace(/<|>/g, ""); | |
R = TS.utility.msgs.getMemberFromMemberMarkup(I); | |
if (R) { | |
e = TS.utility.shouldLinksHaveTargets() ? 'target="/team/' + R.name + '" ' : ""; | |
var O = (n) ? "@" + R.name : TS.format.doHighlighting("@" + R.name); | |
G += '<a href="/team/' + R.name + '" ' + e + 'data-member-name="' + R.name + '" class="internal_member_link">' + O + TS.format.link_close | |
} else { | |
G += I | |
} | |
} else { | |
if (F.indexOf("<#") === 0) { | |
I = F.replace(/<|>|#/g, ""); | |
u = I.split("|"); | |
K = u[0]; | |
X = TS.channels.getChannelById(K); | |
if (X) { | |
e = (TS.utility.shouldLinksHaveTargets()) ? 'target="/archives/' + X.name + '"' : ""; | |
if (TS.format.testing_with_generic_tokens) { | |
G += TS.format.generic_link_open + "#" + X.name + TS.format.link_close | |
} | |
G += '<a href="/archives/' + X.name + '" ' + e + ' data-channel-name="' + X.name + '" data-channel-id="' + X.id + '" class="internal_channel_link">#' + X.name + TS.format.link_close | |
} else { | |
if (u.length > 1 && u[1]) { | |
G += "#" + u[1] | |
} else { | |
if (TS.model.user.is_restricted) { | |
G += "#unknown-channel" | |
} else { | |
G += "#deleted-channel" | |
} | |
} | |
} | |
} else { | |
if (F.indexOf(TSF.LINK_START.split(" ")[0]) === 0) { | |
var h = (function(m) { | |
var i = $.trim(m.replace(TSF.LINK_START.split(" ")[0], "")); | |
return i.substr(0, i.length - 1) | |
})(F); | |
if (h.indexOf(TS.utility.msgs.api_url_prefix + "chat.help") === 0) { | |
if (D) { | |
s = TS.utility.htmlEntities(TS.utility.jsString(h)); | |
G += '<a onclick="TS.utility.msgs.doApiUrl(' + s + ')" class="api_url">' | |
} else { | |
G += '<a class="api_url muted">(Disabled) ' | |
} | |
} else { | |
if (h.indexOf(TS.utility.msgs.new_api_url_prefix) === 0) { | |
if (D) { | |
s = TS.utility.htmlEntities(TS.utility.jsString(h)); | |
G += '<a onclick="TS.utility.msgs.doNewApiUrl(' + s + ')" class="api_url">' | |
} else { | |
G += '<a class="api_url muted">(Disabled) ' | |
} | |
} else { | |
if (h.indexOf("javascript:") === 0) { | |
G += '<a onclick="' + h.replace("javascript:", "") + '">' | |
} else { | |
if (TS.client && TS.client.core_url && h.indexOf(TS.client.core_url) === 0) { | |
G += '<a target="_self" href="' + h + '">' | |
} else { | |
var f = TS.utility.getFileIDFromURL(h); | |
var N = (f) ? ' class="file_preview_link"' : ""; | |
var j = (f) ? ' data-file-id="' + f + '"' : ""; | |
G += "<a " + TS.utility.makeRefererSafeLink(h) + ' target="_blank"' + N + j + ">"; | |
if (W) { | |
TS.error("WTF we should have no attach_html") | |
} | |
W = ""; | |
var y; | |
if (P && P.ts && V) { | |
y = TS.inline_attachments.getAttachmentByFromUrl(P.attachments, h); | |
if (y) { | |
if (TS.boot_data.feature_attachments_inline || TS.templates.builders.shouldDoSimpleAttachment(y, P)) { | |
W = TS.templates.builders.buildAttachmentHTML({ | |
attachment: y, | |
url: h, | |
msg: P, | |
show_initial_caret: true | |
}) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} else { | |
if (F.indexOf(TSF.EMOJI_COLONS.split(" ")[0]) === 0) { | |
var g = F.split(" ")[1].replace(">", ""); | |
if (!B) { | |
var w = TS.utility.emojiReplace(g); | |
if (w == g) { | |
if (n) { | |
G += g | |
} else { | |
G += TS.format.doHighlighting(g) | |
} | |
} else { | |
G += TS.utility.emojiReplace(g) | |
} | |
} else { | |
G += g | |
} | |
} else { | |
if (F.indexOf(TSF.HEX_BLOCK.split(" ")[0]) === 0) { | |
var L = F.split(" ")[1].replace(">", ""); | |
if (!x) { | |
G += ' <div class="inline_color_block" style="background:' + L + ';"></div>' | |
} | |
} else { | |
TS.error("markup token not handled:" + F) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} else { | |
if (F.indexOf("<") == -1) { | |
if (n) { | |
G += F | |
} else { | |
G += TS.format.doHighlighting(F) | |
} | |
} else { | |
TS.error("token has a < in it but it is not the first character!\n" + F) | |
} | |
} | |
} | |
} | |
G = TS.format.deTokenizeStr(M, G); | |
return G | |
}; | |
var a = function(f, e) { | |
e = (e) ? " to " + e : ""; | |
return '<a data-theme="' + TS.utility.htmlEntities(f) + '" class="btn btn_small tiny_right_margin theme_installer_btn" style="padding: 0px 7px 1px;"><i class="ts_icon ts_icon_cog align_middle"></i> Switch' + e + "</a>" | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment