mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
fix: extend remoteAnchorToLocalProfile ap helper to handle markdown content
This commit is contained in:
@@ -367,13 +367,25 @@ Helpers.generateTitle = (html) => {
|
||||
return title;
|
||||
};
|
||||
|
||||
Helpers.remoteAnchorToLocalProfile = async (content) => {
|
||||
const anchorRegex = /<a.*?href=['"](.+?)['"].*?>(.*?)<\/a>/ig;
|
||||
Helpers.remoteAnchorToLocalProfile = async (content, isMarkdown = false) => {
|
||||
let anchorRegex;
|
||||
if (isMarkdown) {
|
||||
anchorRegex = /\[(.*?)\]\((.+?)\)/ig;
|
||||
} else {
|
||||
anchorRegex = /<a.*?href=['"](.+?)['"].*?>(.*?)<\/a>/ig;
|
||||
}
|
||||
|
||||
const anchors = content.matchAll(anchorRegex);
|
||||
const urls = new Set();
|
||||
const matches = [];
|
||||
for (const anchor of anchors) {
|
||||
const [match, url] = anchor;
|
||||
let match;
|
||||
let url;
|
||||
if (isMarkdown) {
|
||||
[match,, url] = anchor;
|
||||
} else {
|
||||
[match, url] = anchor;
|
||||
}
|
||||
matches.push([match, url]);
|
||||
urls.add(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user