mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-09 21:07:49 +00:00
fix #1016 - exclude headings in tabs or collapsibles from table of contents
This commit is contained in:
@@ -2,7 +2,7 @@ import { headingRank } from "hast-util-heading-rank";
|
|||||||
import { hasProperty } from "hast-util-has-property";
|
import { hasProperty } from "hast-util-has-property";
|
||||||
import { toString } from "hast-util-to-string";
|
import { toString } from "hast-util-to-string";
|
||||||
import { Root, Parent } from "hast";
|
import { Root, Parent } from "hast";
|
||||||
import { visit } from "unist-util-visit";
|
import { visit, SKIP } from "unist-util-visit";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin to add `data-header-text`s to headings.
|
* Plugin to add `data-header-text`s to headings.
|
||||||
@@ -12,6 +12,14 @@ export const rehypeHeaderText = () => {
|
|||||||
const headingsWithId = (file.data.astro.frontmatter.headingsWithId = []);
|
const headingsWithId = (file.data.astro.frontmatter.headingsWithId = []);
|
||||||
|
|
||||||
visit(tree, "element", (node: Parent["children"][number]) => {
|
visit(tree, "element", (node: Parent["children"][number]) => {
|
||||||
|
// Don't descend into tab containers or collapsible <details> elements
|
||||||
|
if (
|
||||||
|
"properties" in node &&
|
||||||
|
(node.properties["role"] === "tabpanel" || node.tagName === "details")
|
||||||
|
) {
|
||||||
|
return SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
headingRank(node) &&
|
headingRank(node) &&
|
||||||
"properties" in node &&
|
"properties" in node &&
|
||||||
|
|||||||
Reference in New Issue
Block a user