mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-17 14:00:29 +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;
|
return title;
|
||||||
};
|
};
|
||||||
|
|
||||||
Helpers.remoteAnchorToLocalProfile = async (content) => {
|
Helpers.remoteAnchorToLocalProfile = async (content, isMarkdown = false) => {
|
||||||
const anchorRegex = /<a.*?href=['"](.+?)['"].*?>(.*?)<\/a>/ig;
|
let anchorRegex;
|
||||||
|
if (isMarkdown) {
|
||||||
|
anchorRegex = /\[(.*?)\]\((.+?)\)/ig;
|
||||||
|
} else {
|
||||||
|
anchorRegex = /<a.*?href=['"](.+?)['"].*?>(.*?)<\/a>/ig;
|
||||||
|
}
|
||||||
|
|
||||||
const anchors = content.matchAll(anchorRegex);
|
const anchors = content.matchAll(anchorRegex);
|
||||||
const urls = new Set();
|
const urls = new Set();
|
||||||
const matches = [];
|
const matches = [];
|
||||||
for (const anchor of anchors) {
|
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]);
|
matches.push([match, url]);
|
||||||
urls.add(url);
|
urls.add(url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,9 +176,10 @@ Mocks.post = async (objects) => {
|
|||||||
let edited = new Date(updated);
|
let edited = new Date(updated);
|
||||||
edited = Number.isNaN(edited.valueOf()) ? undefined : edited;
|
edited = Number.isNaN(edited.valueOf()) ? undefined : edited;
|
||||||
|
|
||||||
const sourceContent = source && source.mediaType === 'text/markdown' ? source.content : undefined;
|
let sourceContent = source && source.mediaType === 'text/markdown' ? source.content : undefined;
|
||||||
if (sourceContent) {
|
if (sourceContent) {
|
||||||
content = null;
|
content = null;
|
||||||
|
sourceContent = await activitypub.helpers.remoteAnchorToLocalProfile(sourceContent, true);
|
||||||
} else if (content && content.length) {
|
} else if (content && content.length) {
|
||||||
content = sanitize(content, sanitizeConfig);
|
content = sanitize(content, sanitizeConfig);
|
||||||
content = await activitypub.helpers.remoteAnchorToLocalProfile(content);
|
content = await activitypub.helpers.remoteAnchorToLocalProfile(content);
|
||||||
|
|||||||
@@ -183,7 +183,6 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
_activitypub: mainPost._activitypub,
|
_activitypub: mainPost._activitypub,
|
||||||
}),
|
}),
|
||||||
Notes.updateLocalRecipients(mainPid, { to, cc }),
|
Notes.updateLocalRecipients(mainPid, { to, cc }),
|
||||||
posts.attachments.update(mainPid, attachment),
|
|
||||||
]);
|
]);
|
||||||
unprocessed.shift();
|
unprocessed.shift();
|
||||||
|
|
||||||
@@ -193,6 +192,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
id: tid,
|
id: tid,
|
||||||
path: mainPost._activitypub.image,
|
path: mainPost._activitypub.image,
|
||||||
}) : null,
|
}) : null,
|
||||||
|
posts.attachments.update(mainPid, attachment),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (context) {
|
if (context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user