marked.use({
breaks: true,
extensions: [
{
name: 'mention',
level: 'inline',
start: function(src){
const match = src.match(/@[a-zA-Z0-9_\-]+/);
return match != null ? match.index : -1;
},
tokenizer: function(src) {
const rule = /^@[a-zA-Z0-9_\-]+/;
const match = rule.exec(src);
if(match){
return {
type: 'mention',
raw: match[0],
text: match[0].trim().slice(1),
tokens: []
};
}
},
renderer(token) {
const u = token.raw;
return ` ${u}`;
}
},
{
name: 'group_mention',
level: 'inline',
start: function(src){
const match = src.match(/![a-zA-Z0-9_\-]+/);
return match != null ? match.index : -1;
},
tokenizer: function(src) {
const rule = /^![a-zA-Z0-9_\-]+/;
const match = rule.exec(src);
if(match){
return {
type: 'group_mention',
raw: match[0],
text: match[0].trim().slice(1),
tokens: []
};
}
},
renderer(token) {
const g = token.raw;
return `${g}`;
}
},
]
});
const reDisableBeforeUnload = /^\/submit|^\/h\/[a-zA-Z0-9_\-]{3,20}\/submit/;
const image_regex_extensions = document.getElementById('IMAGE_FORMATS').value.replaceAll(',', '|')
const regex_pattern = String.raw`(^|\s)(https:\/\/[\w\-.#&/=\?@%;+,:]{5,250}(\.|\?format=)(` + image_regex_extensions + String.raw`)((\?|&)[\w\-.#&/=\?@%;+,:]*)?)($|\s)`
const compiled_regex = new RegExp(regex_pattern, "g");
const approved_embed_hosts = document.getElementById('approved_embed_hosts').value.replace("{'", "").replace("'}", "").split("', '")
function replace_image(match, prefix, url) {
if (approved_embed_hosts.some(x => url.startsWith(`https://${x}/`)))
return `${prefix}![](${url})`
return match
}
const MODIFIERS = {
PAT: 1,
TALKING: 2,
LARGE: 3,
REVERSED: 4,
USER: 5
};
function markdown(t) {
let input = t.value;
if (!reDisableBeforeUnload.test(location.pathname))
{
if (!window.onbeforeunload)
{
window.onbeforeunload = function (e) {
e = e || window.event;
if (e) {
e.returnValue = 'Any string';
}
return 'Any string';
};
}
else if (!input) {
window.onbeforeunload = null
}
}
input = input.replace(/\|\|(.*?)\|\|/g, '
` : '';
const patHtml = modifiers.has(MODIFIERS.PAT) ? `
` : '';
const url = modifiers.has(MODIFIERS.USER) ? `/@${emoji}/pic` : `${SITE_FULL_IMAGES}/e/${emoji}.webp`;
const modifierHtml = isTalkingFirst ? `${talkingHtml}${patHtml}` : `${patHtml}${talkingHtml}`;
input = input.replace(old, `${modifierHtml}
`);
} else {
input = input.replace(old, `
`);
}
}
}
let options = Array.from(input.matchAll(/\$\$([^\$\n]+)\$\$(?![^`]*`)/gi))
if(options != null){
for(i = 0; i < options.length; i++){
const option = options[i][0];
const option2 = option.replace(/\$\$/g, '').replace(/\n/g, '')
input = input.replace(option, `