mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
891 B
25 lines
891 B
'use strict';
|
|
|
|
const parenPairRegex = /\((?:[^)(]+|\((?:[^)(]+|\([^)(]\))*\))*\)/g
|
|
|
|
module.exports = (match) => {
|
|
let trimmedMatch;
|
|
let excess = '';
|
|
const parensPairs = match.match(parenPairRegex);
|
|
//naive solution to conflict with detected markdown
|
|
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 if (match.indexOf(')') !== -1){
|
|
trimmedMatch = match.substring(0, match.indexOf(')'));
|
|
excess = match.substring(match.indexOf(')'));
|
|
} else {
|
|
trimmedMatch = match;
|
|
}
|
|
trimmedMatch = trimmedMatch
|
|
.replace(/\(/g, '%28')
|
|
.replace(/\)/g, '%29');
|
|
return `<a rel='nofollow' referrerpolicy='same-origin' target='_blank' href='${trimmedMatch}'>${trimmedMatch}</a>${excess}`;
|
|
};
|
|
|