UNPKG

@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

59 lines (58 loc) 2.13 kB
// SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital // SPDX-License-Identifier: Apache-2.0 import find from "unist-util-find"; import { remove } from "unist-util-remove"; import { replace } from "../../../../support/unist/unist-util-replace.js"; /** * UnifiedPlugin to replace task lists in Confluence Storage Format * * @see {@link https://developer.atlassian.com/server/confluence/confluence-storage-format/ | Confluence Storage Format } */ const rehypeReplaceTaskList = function rehypeReplaceTaskList() { return function (tree) { replace(tree, "element", replaceTaskList); }; }; function replaceTaskList(node) { if (node.tagName !== "ul") return node; if (!node.properties?.className?.includes("contains-task-list")) return node; return { type: "element", tagName: "ac:task-list", children: node.children.map((child) => child.type !== "element" ? child : { type: "element", tagName: "ac:task", children: [ { type: "element", tagName: "ac:task-status", children: [ { type: "text", value: find(child, { type: "element", tagName: "input" }) ?.properties.checked ? "complete" : "incomplete", }, ], }, { type: "element", tagName: "ac:task-body", children: processChildren(remove(child, find(child, { type: "element", tagName: "input" }))), }, ], }), }; } function processChildren(node) { if (!node?.children) return []; const childrenToProcess = node.children; return childrenToProcess.map(replaceTaskList); } export default rehypeReplaceTaskList;