different way of handling post styling. also added links

merge-requests/208/head
fatchan 5 years ago
parent 09a729a3c9
commit cbc7135c90
  1. 103
      helpers/markdown.js
  2. 4
      static/css/style.css

@ -1,62 +1,57 @@
'use strict'; 'use strict';
const Posts = require(__dirname+'/../db-models/posts.js') const Posts = require(__dirname+'/../db-models/posts.js')
, quoteRegex = /^>>\d+/g , quoteRegex = /^>>\d+$/gm
, greentextRegex = /^>[^>].+/g , greentextRegex = /^>[^>].+$/gm
, redtextRegex = /^<[^<].+/g , redtextRegex = /^<[^<].+$/gm
, boldRegex = /==.+==/g , boldRegex = /==.+==/gm
, italicRegex = /__.+__/g , italicRegex = /__.+__/gm
, spoilerRegex = /\|.+\|/g; , linkRegex = /https?\:\/\/[^\s]+/g
, spoilerRegex = /\|.+\|/gm;
module.exports = (board, thread, text) => { module.exports = (board, thread, text) => {
const lines = text.split('\n') //redtext
text = text.replace(redtextRegex, (match) => {
for(let j = 0; j < lines.length; j++) { const red = match.substring(1);
//replace quotes return `<span class='redtext'>&lt;${red}</span>`;
const quote = lines[j].match(quoteRegex); });
if (quote) {
const quotenum = quote[0].substring(2); //greentext
lines[j] = lines[j].replace(quote[0], `<a class='quote' href='/${board}/thread/${thread}#${quotenum}'>&gt;&gt;${quotenum}</a>`); text = text.replace(greentextRegex, (match) => {
continue; const green = match.substring(1);
} return `<span class='greentext'>&gt;${green}</span>`;
//replace greentexts });
const greentext = lines[j].match(greentextRegex);
if (greentext) { //links
const green = greentext[0].substring(1); text = text.replace(linkRegex, (match) => {
lines[j] = lines[j].replace(greentext[0], `<span class='greentext'>&gt;${green}</span>`); return `<a href="${match}">${match}</a>`;
continue; });
}
//replace redtexts //quotes
const redtext = lines[j].match(redtextRegex); text = text.replace(quoteRegex, (match) => {
if (redtext) { const quotenum = match.substring(2);
const red = redtext[0].substring(1); return `<a class='quote' href='/${board}/thread/${thread}#${quotenum}'>&gt;&gt;${quotenum}</a>`;
lines[j] = lines[j].replace(redtext[0], `<span class='redtext'>&lt;${red}</span>`); });
continue;
} //bold
//replace bolds text = text.replace(boldRegex, (match) => {
const boldtext = lines[j].match(boldRegex); const bold = match.substring(2, match.length-2);
if (boldtext) { return `<strong>${bold}</strong>`;
const bold = boldtext[0].substring(2, boldtext[0].length-2); });
lines[j] = lines[j].replace(boldtext[0], `<strong>${bold}</strong>`);
continue; //italic
} text = text.replace(italicRegex, (match) => {
//replace italics const italic = match.substring(2, match.length-2);
const italictext = lines[j].match(italicRegex); return `<italic>${italic}</em>`;
if (italictext) { });
const italic = italictext[0].substring(2, italictext[0].length-2);
lines[j] = lines[j].replace(italictext[0], `<em>${italic}</em>`); //spoilers
continue; text = text.replace(spoilerRegex, (match) => {
} const spoiler = match.substring(1, match.length-1);
//replace spoilers return `<span class='spoiler'>${spoiler}</span>`;
const spoilertext = lines[j].match(spoilerRegex); });
if (spoilertext) {
const spoiler = spoilertext[0].substring(1, spoilertext[0].length-1); return text;
lines[j] = lines[j].replace(spoilertext[0], `<span class='spoiler'>${spoiler}</span>`);
continue;
}
}
return lines.join('\n');
} }

@ -204,8 +204,8 @@ input textarea {
} }
.post-container:target, .op:target { .post-container:target, .op:target {
outline: 1px dashed blue; background-color: #d6bad0;
outline-offset: -1px; border-color: #ba9dbf;
} }
.post-container.op { .post-container.op {

Loading…
Cancel
Save