fix error + format
This commit is contained in:
+51
-41
@@ -1,45 +1,56 @@
|
||||
const urlregex = /(([a-z]+:\/\/)(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|app|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal|tk|rocks|ga|to))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi
|
||||
const urlregex =
|
||||
/(([a-z]+:\/\/)(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|app|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal|tk|rocks|ga|to))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi
|
||||
function urlify(text) {
|
||||
return text.replace(urlregex,'<a href="$1" target="_blank" class="insertedlink">$1</a> ')
|
||||
return text.replace(
|
||||
urlregex,
|
||||
'<a href="$1" target="_blank" class="insertedlink">$1</a> '
|
||||
)
|
||||
}
|
||||
|
||||
const newlregex = /(\n)/gi
|
||||
function newlineify(text) {
|
||||
return text.replace(newlregex,' <br>')
|
||||
return text.replace(newlregex, ' <br>')
|
||||
}
|
||||
|
||||
const crossregex = /~([^~]*)~/gi
|
||||
function crossout(text) {
|
||||
return text.replace(crossregex,'<span class="crossout">$1</span>')
|
||||
return text.replace(crossregex, '<span class="crossout">$1</span>')
|
||||
}
|
||||
|
||||
const italicregex = /\*([^\*]*)\*/gi
|
||||
function italicify(text) {
|
||||
return text.replace(italicregex,'<i>$1</i> ')
|
||||
return text.replace(italicregex, '<i>$1</i> ')
|
||||
}
|
||||
|
||||
const boldregex = /\*\*([^\*]*)\*\*/gi
|
||||
function boldify(text) {
|
||||
return text.replace(boldregex,'<b>$1</b> ')
|
||||
return text.replace(boldregex, '<b>$1</b> ')
|
||||
}
|
||||
|
||||
const mentionregex = /@([^\s]*)/gi
|
||||
function filterMentions(text) {
|
||||
return text.replace(mentionregex,`<span><a href="/users/$1" class="mention">$1</a></span> `)
|
||||
return text.replace(
|
||||
mentionregex,
|
||||
`<span><a href="/users/$1" class="mention">$1</a></span> `
|
||||
)
|
||||
}
|
||||
|
||||
const emojiregex = /:([^:\s]*):/gi
|
||||
function emojify(text) {
|
||||
return text.replace(emojiregex,"<img class='emoji' src='/images/emoji/$1.png' alt=':$1:' title=':$1:' height=20/>")
|
||||
return text.replace(
|
||||
emojiregex,
|
||||
"<img class='emoji' src='/images/emoji/$1.png' alt=':$1:' title=':$1:' height=20/>"
|
||||
)
|
||||
}
|
||||
|
||||
function unemojify(text){
|
||||
text = text.replace(/\u{1F5FF}/gu,":moyai:")
|
||||
text = text.replace(/\u{1F440}/gu,":eyes:")
|
||||
return text
|
||||
function unemojify(text) {
|
||||
text = text.replace(/\u{1F5FF}/gu, ':moyai:')
|
||||
text = text.replace(/\u{1F440}/gu, ':eyes:')
|
||||
return text
|
||||
}
|
||||
|
||||
const allregex = /(```([^```]*)```)|(\n)|(~([^~]*)~)|(\*\*([^\*]*)\*\*)|(\*([^\*]*)\*)|(@[^\s]*)|(:([^:\s]*):)/gi
|
||||
const allregex =
|
||||
/(```([^```]*)```)|(\n)|(~([^~]*)~)|(\*\*([^\*]*)\*\*)|(\*([^\*]*)\*)|(@[^\s]*)|(:([^:\s]*):)/gi
|
||||
|
||||
const cdblregex = /```([^```]*)```/gi
|
||||
|
||||
@@ -48,29 +59,28 @@ const cdblregex = /```([^```]*)```/gi
|
||||
* @param {string} text text to filter/format
|
||||
* @return {string} html that represents the filtered text
|
||||
*/
|
||||
function filterPost(text){
|
||||
text = unemojify(text)
|
||||
let result = htmlesc(text).replace(allregex, function (match) {
|
||||
let out = match
|
||||
if(cdblregex.test(match)) {
|
||||
let paddlen = 3
|
||||
out = out.substring(paddlen,out.length-paddlen).trim()+"\n"
|
||||
out = newlineify(out)
|
||||
return `<div class="ovfl-bw"><code>${out}</code></div>`
|
||||
}
|
||||
out = newlineify(out)
|
||||
out = urlify(out)
|
||||
out = emojify(out)
|
||||
out = filterMentions(out)
|
||||
out = crossout(out)
|
||||
out = boldify(out)
|
||||
out = italicify(out)
|
||||
function filterPost(text) {
|
||||
text = unemojify(text)
|
||||
let result = htmlesc(text).replace(allregex, function (match) {
|
||||
let out = match
|
||||
if (cdblregex.test(match)) {
|
||||
let paddlen = 3
|
||||
out = out.substring(paddlen, out.length - paddlen).trim() + '\n'
|
||||
out = newlineify(out)
|
||||
return `<div class="ovfl-bw"><code>${out}</code></div>`
|
||||
}
|
||||
out = newlineify(out)
|
||||
out = urlify(out)
|
||||
out = emojify(out)
|
||||
out = filterMentions(out)
|
||||
out = crossout(out)
|
||||
out = boldify(out)
|
||||
out = italicify(out)
|
||||
|
||||
return out
|
||||
|
||||
});
|
||||
return out
|
||||
})
|
||||
|
||||
return result
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,12 +89,12 @@ function filterPost(text){
|
||||
* @return {string} html that represents the filtered text
|
||||
*/
|
||||
function filterReply(text) {
|
||||
text = htmlesc(text)
|
||||
text = newlineify(text)
|
||||
text = urlify(text)
|
||||
text = crossout(text)
|
||||
text = boldify(text)
|
||||
text = italicify(text)
|
||||
text = htmlesc(text)
|
||||
text = newlineify(text)
|
||||
text = urlify(text)
|
||||
text = crossout(text)
|
||||
text = boldify(text)
|
||||
text = italicify(text)
|
||||
|
||||
return text
|
||||
return text
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user