Files
milkblogs-fuwari/src/plugins/remark-directive-rehype.js
T
Katsuyuki Karasawa 9130765d45 Biome 2.0 with format (#510)
* execute migrate command

* migrate to v2

* update config

* supress linter error
2025-06-18 23:01:28 +09:00

31 lines
855 B
JavaScript

import { h } from "hastscript";
import { visit } from "unist-util-visit";
export function parseDirectiveNode() {
return (tree, { _data }) => {
visit(tree, (node) => {
if (
node.type === "containerDirective" ||
node.type === "leafDirective" ||
node.type === "textDirective"
) {
// biome-ignore lint/suspicious/noAssignInExpressions: <check later>
const data = node.data || (node.data = {});
node.attributes = node.attributes || {};
if (
node.children.length > 0 &&
node.children[0].data &&
node.children[0].data.directiveLabel
) {
// Add a flag to the node to indicate that it has a directive label
node.attributes["has-directive-label"] = true;
}
const hast = h(node.name, node.attributes);
data.hName = hast.tagName;
data.hProperties = hast.properties;
}
});
};
}