changed filterPost
added multi-line texts added bold text added italic text
This commit is contained in:
parent
886178b79d
commit
083136a94e
16
js/posts.js
16
js/posts.js
@ -13,6 +13,18 @@ function urlify(text) {
|
||||
let urlRegex = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal|tk|ga))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi
|
||||
return text.replace(urlRegex,'<a href="$1">$1</a> ')
|
||||
}
|
||||
function newlineify(text) {
|
||||
let urlRegex = /(\n)/gi
|
||||
return text.replace(urlRegex,' <br>')
|
||||
}
|
||||
function italicify(text) {
|
||||
let urlRegex = /\*([^\*]*)\*/gi
|
||||
return text.replace(urlRegex,'<i>$1</i> ')
|
||||
}
|
||||
function boldify(text) {
|
||||
let urlRegex = /\*\*([^\*]*)\*\*/gi
|
||||
return text.replace(urlRegex,'<b>$1</b> ')
|
||||
}
|
||||
function filterMentions(text) {
|
||||
let mentionRegex = /(@[^\s]*)/gi
|
||||
return text.replace(mentionRegex,'<span class="mention">$1</span> ')
|
||||
@ -27,8 +39,12 @@ document.getElementById("post-btn").addEventListener("click",async function() {
|
||||
})
|
||||
function filterPost(text) {
|
||||
text = escape(text)
|
||||
text = newlineify(text)
|
||||
text = urlify(text)
|
||||
text = filterMentions(text)
|
||||
text = boldify(text)
|
||||
text = italicify(text)
|
||||
|
||||
return text
|
||||
}
|
||||
function createPost(username,text,time,specialtext) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user