@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
22 lines (21 loc) • 869 B
JavaScript
// SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital
// SPDX-License-Identifier: Apache-2.0
import { visit } from "unist-util-visit";
/**
* Replace nodes in a tree given a test and a replacement function.
*
* @param tree - Root node of the tree to visit.
* @param is - Test to check if a node should be replaced.
* @param replacement - Function to build the replacement node.
*/
export function replace(tree, is, replacement) {
visit(tree, is, (node, index, parent) => {
// NOTE: Coverage ignored because it is unreachable from tests. Defensive programming.
/* istanbul ignore if */
if (index === null || parent === null) {
throw new SyntaxError("Unexpected null value");
}
const newUnistNode = replacement(node, index, parent);
parent.children.splice(index, 1, newUnistNode);
});
}