Update extract-url-from-mfm.ts

This commit is contained in:
FineArchs 2024-08-22 11:56:08 +09:00 committed by GitHub
parent c6957f6c00
commit 2b12319b63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,8 +11,11 @@ import { unique } from '@/scripts/array.js';
const removeHash = (x: string) => x.replace(/#[^#]*$/, '');
export function extractUrlFromMfm(nodes: mfm.MfmNode[], respectSilentFlag = true): string[] {
const quotedUrlNodes = mfm.extract(nodes, (node) => {
return (node.type === 'quote') && (node.children.length === 1) && (node.children[0].type === 'url');
}).map(quote => quote.children[0]);
const urlNodes = mfm.extract(nodes, (node) => {
return (node.type === 'url') || (node.type === 'link' && (!respectSilentFlag || !node.props.silent));
return (node.type === 'url' && !quotedUrlNodes.includes(node)) || (node.type === 'link' && (!respectSilentFlag || !node.props.silent));
});
const urls: string[] = unique(urlNodes.map(x => x.props.url));