@telefonica/markdown-confluence-sync
Version:
Creates/updates/deletes Confluence pages based on markdown files in a directory. Supports Mermaid diagrams and per-page configuration using frontmatter metadata. Works great with Docusaurus
52 lines (51 loc) • 1.73 kB
JavaScript
// SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital
// SPDX-License-Identifier: Apache-2.0
import { remove } from "unist-util-remove";
import { replace } from "../../../../support/unist/unist-util-replace.js";
function isLink(node) {
return node.tagName === "a";
}
function isExternalLink(node) {
return (isLink(node) &&
(node.properties?.href?.toString().startsWith("http") ?? false));
}
function isInternalLink(node) {
return (isLink(node) && (node.properties?.href?.toString().startsWith(".") ?? false));
}
function isImage(node) {
return node.tagName === "img";
}
// FIXME: remove this plugin
/**
* UnifiedPlugin to remove links in html
*
* @deprecated Not required anymore
*/
const rehypeRemoveLinks = function rehypeRemoveLinks(options) {
return function (tree) {
if (options.anchors !== false) {
if (options.anchors === true || options.anchors?.external === true) {
replace(tree, isExternalLink, (node) => {
return {
type: "element",
tagName: "span",
children: node.children,
};
});
}
if (options.anchors === true || options.anchors?.internal === true) {
replace(tree, isInternalLink, (node) => {
return {
type: "element",
tagName: "span",
children: node.children,
};
});
}
}
if (options.images === true) {
remove(tree, { cascade: true }, isImage);
}
};
};
export default rehypeRemoveLinks;