20 lines
465 B
JavaScript
20 lines
465 B
JavaScript
import {fromHtml} from 'hast-util-from-html';
|
|
import {visit} from 'unist-util-visit';
|
|
|
|
export default async function(value) {
|
|
const tree = fromHtml(value);
|
|
const links = [];
|
|
|
|
//take tree;
|
|
//visit nodes matching one of the test patterns;
|
|
//apply function to those nodes.
|
|
visit(tree, [
|
|
{tagName: 'link'},
|
|
{tagName: 'img'}
|
|
], function(node) {
|
|
links.push(node);
|
|
})
|
|
|
|
return links.map(link => link.properties.href || link.properties.src)
|
|
}
|