Skip to content

Commit

Permalink
fix katex in content index
Browse files Browse the repository at this point in the history
  • Loading branch information
Loping151 authored Sep 15, 2024
1 parent 5ad9044 commit a21e10c
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 a21e10c

Please sign in to comment.