Skip to content

Commit

Permalink
Merge pull request #38 from Loping151/patch-3
Browse files Browse the repository at this point in the history
🛠️ fix: katex in content index
  • Loading branch information
EveSunMaple authored Sep 15, 2024
2 parents 5ad9044 + a21e10c commit a16c5b4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/Content.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,25 @@ import ThemeIcon from "../components/ThemeIcon.astro";
</div>
</div>
<script>
function getCleanText(element: HTMLElement) {
let text = "";
element.childNodes.forEach((node: ChildNode) => {
if (node.nodeType === Node.TEXT_NODE) {
text += node.textContent;
} else if (node.nodeType === Node.ELEMENT_NODE && (node as HTMLElement).className !== 'katex-mathml') {
text += getCleanText(node as HTMLElement);
}
});
return text;
}
function addContent() {
const headings = document.querySelectorAll("h1, h2, h3, h4, h5, h6");

const generateTocContent = () => {
let tocContent = "<ul class='overflow-auto w-full list-none m-0 p-0'>";
let levelCounters = [0, 0, 0, 0, 0, 0];
headings.forEach((heading) => {
let headingText = heading.textContent;
let headingText = getCleanText(heading as HTMLElement);
const headingId = heading.id;
const headingLevel = parseInt(heading.tagName.charAt(1), 10);

Expand Down

0 comments on commit a16c5b4

Please sign in to comment.