scuffed way to make some links in parentheses work better

merge-requests/208/head
fatchan 4 years ago
parent 6f405fd9f8
commit 8b5c88332c
  1. 23
      helpers/posting/linkmatch.js
  2. 14
      helpers/posting/markdown.js

@ -0,0 +1,23 @@
'use strict';
const parenPairRegex = /\((?:[^)(]+|\((?:[^)(]+|\([^)(]\))*\))*\)/g
module.exports = (match) => {
let trimmedMatch;
let excess = '';
const parensPairs = match.match(parenPairRegex);
//naive solution
if (parensPairs) {
const lastMatch = parensPairs[parensPairs.length-1];
const lastIndex = match.lastIndexOf(lastMatch);
trimmedMatch = match.substring(0, lastIndex+lastMatch.length);
excess = match.substring(lastIndex+lastMatch.length);
} else {
trimmedMatch = match.substring(0, match.indexOf(')'));
excess = match.substring(match.indexOf(')'));
}
trimmedMatch = trimmedMatch
.replace(/\(/g, '%28')
.replace(/\)/g, '%29');
return `<a rel='nofollow' referrerpolicy='same-origin' target='_blank' href='${trimmedMatch}'>${trimmedMatch}</a>${excess}`;
};

@ -22,16 +22,16 @@ const greentextRegex = /^&gt;((?!&gt;\d+|&gt;&gt;&#x2F;\w+(&#x2F;\d*)?).*)/gm
, replacements = [
{ regex: pinktextRegex, cb: (match, pinktext) => `<span class='pinktext'>&lt;${pinktext}</span>` },
{ regex: greentextRegex, cb: (match, greentext) => `<span class='greentext'>&gt;${greentext}</span>` },
{ regex: boldRegex, cb: (match, bold) => `<span class='bold'>${bold}</span>` },
{ regex: boldRegex, cb: (match, bold) => `<span class='bold'>${bold}</span>` },
{ regex: underlineRegex, cb: (match, underline) => `<span class='underline'>${underline}</span>` },
{ regex: strikeRegex, cb: (match, strike) => `<span class='strike'>${strike}</span>` },
{ regex: titleRegex, cb: (match, title) => `<span class='title'>${title}</span>` },
{ regex: italicRegex, cb: (match, italic) => `<span class='em'>${italic}</span>` },
{ regex: strikeRegex, cb: (match, strike) => `<span class='strike'>${strike}</span>` },
{ regex: titleRegex, cb: (match, title) => `<span class='title'>${title}</span>` },
{ regex: italicRegex, cb: (match, italic) => `<span class='em'>${italic}</span>` },
{ regex: spoilerRegex, cb: (match, spoiler) => `<span class='spoiler'>${spoiler}</span>` },
{ regex: monoRegex, cb: (match, mono) => `<span class='mono'>${mono}</span>` },
{ regex: monoRegex, cb: (match, mono) => `<span class='mono'>${mono}</span>` },
{ regex: linkRegex, cb: require(__dirname+'/linkmatch.js') },
{ regex: detectedRegex, cb: (match, detected) => `<span class='detected'>${detected}</span>` },
{ regex: linkRegex, cb: (match) => `<a rel='nofollow' referrerpolicy='same-origin' target='_blank' href='${match}'>${match}</a>` },
{ regex: diceRegex, cb: require(__dirname+'/diceroll.js') },
{ regex: diceRegex, cb: require(__dirname+'/diceroll.js') },
];
module.exports = {

Loading…
Cancel
Save