/g, ' ')
.replace(/~~(.+?)~~/g, '$1 ')
- .replace(/\`(?!\`)([^\`]+?)\`(?!\`)/g, '$1
')
- .replace(/\`\`(?!\`)([^\`]+?)\`\`(?!\`)/g, '$1
')
.replace(/\*\*\*(.+?)\*\*\*/g, '$1 ')
.replace(/\*\*(.+?)\*\*/g, '$1 ')
.replace(/__(.+?)__/g, '$1 ')
.replace(/\*(.+?)\*/g, '$1 ')
.replace(/_(.+?)_/g, '$1 ')
- // Block
- .replace(/\n/g, ' ')
- .replace(/\`\`\`(\w{1,15}) ((\n|.)+?)\`\`\`/g, isEmbed ? '$2
' : '$2
')
- .replace(/\`\`\`(\w{1,15}) ((\n|.)+?)\`\`\`/g, isEmbed ? '$2
' : '$2
')
- .replace(/\`\`\`( )?((\n|.)+?)\`\`\`/g, isEmbed ? '$2
' : '$2
')
- if (isEmbed) txt = txt
- .replace(/\[(.+)\]\((.+)\)/g, `$1 `);
+ if (opts.inlineBlock) txt = txt.replace(/\`([^\`]+?)\`|\`\`([^\`]+?)\`\`|\`\`\`((?:\n|.)+?)\`\`\`/g, (m, x, y, z) => x ? `${x}
` : y ? `${y}
` : z ? `${z}
` : m);
+ else txt = txt.replace(/\`\`\`(\w{1,15})?\n((?:\n|.)+?)\`\`\`|\`\`(.+?)\`\`(?!\`)|\`([^\`]+?)\`/g, (m, w, x, y, z) => w && x ? `${x}
` : x ? `${x}
` : y || z ? `${y || z}
` : m);
+ if (opts.inEmbed) txt = txt.replace(/\[([^\[\]]+)\]\((.+?)\)/g, `$1 `);
+ if (opts.replaceEmojis) {
+ txt = txt.replace(/(?[^>]+)(? x && emojis[x] ? emojis[x] : match);
+ !opts.noEmoticons && Object.keys(emoticons).forEach(e => txt = txt.replace(new RegExp(`(?<=^|\\s)${regEscape(e)}(?=$|\\s)`, 'g'), emoticons[e]));
+ }
+ txt = txt
+ .replace(/(?<=\n|^)\s*>\s+([^\n]+)/g, '')
+ .replace(/\n/g, ' ');
return txt;
},
content = document.querySelector('.messageContent'),
@@ -77,15 +75,16 @@ window.onload = () => {
el.style.display = displayType || "unset";
}, hide = el => el.style.removeProperty('display'),
+ regEscape = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'),
toObj = jsonString => JSON.parse(jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (x, y) => y ? "" : x)),
update = data => {
try {
- content.innerHTML = data.content ? markup(data.content) : '';
+ content.innerHTML = data.content ? markup(data.content, { replaceEmojis: true }) : '';
if (data.embed) {
let e = data.embed;
- if (e.title) display(embedTitle, markup(`${e.url ? '' + e.title + ' ' : e.title}`));
+ if (e.title) display(embedTitle, markup(`${e.url ? '' + e.title + ' ' : e.title}`, { replaceEmojis: true, noEmoticons: true, inlineBlock: true }));
else hide(embedTitle);
- if (e.description) display(embedDescription, markup(e.description, true));
+ if (e.description) display(embedDescription, markup(e.description, { inEmbed: true, replaceEmojis: true }));
else hide(embedDescription);
if (e.color) embed.closest('.embed').style.borderColor = (typeof e.color === 'number' ? '#' + e.color.toString(16) : e.color);
else embed.closest('.embed').style.removeProperty('border-color');
@@ -110,15 +109,15 @@ window.onload = () => {
let el = fields.insertBefore(document.createElement('div'), null);
el.outerHTML = `
-
${markup(f.name)}
-
${markup(f.value)}
+
${markup(f.name, { inEmbed: true, replaceEmojis: true, inlineBlock: true })}
+
${markup(f.value, { inEmbed: true, replaceEmojis: true })}
`;
} else {
el = fields.insertBefore(document.createElement('div'), null);
el.outerHTML = `
-
${markup(f.name)}
-
${markup(f.value)}
+
${markup(f.name, { inEmbed: true, replaceEmojis: true, inlineBlock: true })}
+
${markup(f.value, { inEmbed: true, replaceEmojis: true })}
`;
colNum = (colNum === 9 ? 1 : colNum + 4);
num++;
@@ -127,16 +126,16 @@ window.onload = () => {
colNum = 1;
let len = e.fields.filter(f => f.inline).length;
if (len === 2 || (len > 3 && len % 2 !== 0)) {
- let children = Array.from(fields.children),
- arr = children.filter(x => x === children[len] || x === children[len - 1]);
+ let children = Array.from(fields.children), arr = children.filter(x => x === children[len] || x === children[len - 1]);
arr[0].style.gridColumn = '1 / 7', arr[1].style.gridColumn = '7 / 13';
}
display(fields, undefined, 'grid');
} else hide(fields);
embed.classList.remove('empty');
- let re = /"((icon_)?url")(: *)("(?!\w+?:\/\/).+?")/g.exec(editor.getValue())
- if (re) error(`URLs should have a valid protocol (eg. https://) on this line ${makeShort(re[0], 30, 600)} `, true);
+ let re = /"((icon_)?url")(: *)("(?!https?:\/\/).+?")/g.exec(editor.getValue())
+ if (re) error(`URLs should start with https://
or http://
on this line ${makeShort(re[0], 30, 600)} `, true);
else notif.animate({ opacity: '0', bottom: '-50px', offset: 1 }, { easing: 'ease', duration: 500 }).onfinish = () => notif.style.removeProperty('display');
+ twemoji.parse(msgEmbed);
}
} catch (e) {
error(e);
@@ -146,16 +145,14 @@ window.onload = () => {
editor.on('change', editor => {
try { update(toObj(editor.getValue())); }
catch (e) {
- if (editor.getValue()) return; // error("Couldn't parse JSON; Invalid JSON syntax", e)
+ if (editor.getValue()) return;
embed.classList.add('empty');
content.innerHTML = '';
}
document.querySelectorAll('.markup pre > code').forEach((block) => hljs.highlightBlock(block));
- twemoji.parse(msgEmbed);
});
update(toObj(editor.getValue()));
- twemoji.parse(msgEmbed);
document.querySelector('.timeText').innerText = tstamp()
document.querySelectorAll('.markup pre > code').forEach((block) => hljs.highlightBlock(block))
!window.navigator.userAgent.match(/Firefox\/[\d\.]+$/g) && // Firefox pushes the text up a little
diff --git a/index.html b/index.html
index a322c92..9c09a0d 100644
--- a/index.html
+++ b/index.html
@@ -23,6 +23,8 @@
+
+
@@ -31,10 +33,10 @@