Update extract-url-from-mfm.ts
This commit is contained in:
parent
c6957f6c00
commit
2b12319b63
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue