UNPKG

@limetech/lime-elements

Version:
31 lines (30 loc) 1.05 kB
import { visit } from 'unist-util-visit'; import { getLinkAttributes } from '../text-editor/prosemirror-adapter/plugins/link/utils'; /** * Creates a unified.js plugin that transforms link elements * to add target, rel, and referrerpolicy attributes. * * @returns A unified.js plugin function */ export function createLinksPlugin() { return () => { return (tree) => { visit(tree, 'element', (node) => { var _a, _b; if (node.tagName === 'a') { const href = (_a = node.properties) === null || _a === void 0 ? void 0 : _a.href; const title = (_b = node.properties) === null || _b === void 0 ? void 0 : _b.title; if (!href) { return; } const attributes = getLinkAttributes(href, title); node.properties.target = attributes.target; node.properties.rel = attributes.rel; node.properties.referrerpolicy = attributes.referrerpolicy; } }); return tree; }; }; } //# sourceMappingURL=link-markdown-plugin.js.map