Improve htmlify and markdown rules

This commit is contained in:
Rogerio Chaves 2020-04-26 19:55:55 +02:00
parent 5ea14d906e
commit b4d92d66e4
No known key found for this signature in database
GPG Key ID: E6AF5440509B1D94
1 changed files with 6 additions and 6 deletions

View File

@ -131,22 +131,22 @@ app.use((_req, res, next) => {
result = result.replace(/!\[.*?\]\((.*?)\)/g, `$1`); // Images
result = result.replace(/\[(@.*?)\]\(@.*?\)/g, `$1`); // Link to mention
result = result.replace(/\[.*?\]\((.*?)\)/g, `$1`); // Any Link
result = result.replace(/^#+ /g, "");
result = result.replace(/^#+ /gm, "");
return result;
};
res.locals.htmlify = (str) => {
let result = str;
result = result.replace(
BLOB_PATTERN,
`<a target="_blank" href="/blob/$1">$1</a>`
/(\s|^)&amp;(\S*?=\.sha\d+)/g, // Blobs
`$1<a target="_blank" href="/blob/&$2">&$2</a>`
);
result = result.replace(
/(https?:\/\/\S+)/g,
/(https?:\/\/\S+)/g, // Urls with http in front
`<a target="_blank" href="$1">$1</a>`
);
result = result.replace(
/( ([a-z-_]+\.)?[a-z-_]+\.[a-z]+(\/\S+))/g,
` <a target="_blank" href="http://$1">$1</a>`
/(\s|^)(([a-z-_])*\.\S{2,})/gm, // Domains without http
`$1<a target="_blank" href="http://$2">$2</a>`
);
result = result.replace(/\n/g, "<br />");
return result;