From 3fb3930df8d3bc61bbf6ac69360a1b5949270cca Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 04 Feb 2024 03:44:24 +0000
Subject: [PATCH] fix: calculate heading after latex (closes #719)

---
 quartz/plugins/transformers/toc.ts |    3 ++-
 quartz.config.ts                   |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/quartz.config.ts b/quartz.config.ts
index 1f7399a..d4fc5d3 100644
--- a/quartz.config.ts
+++ b/quartz.config.ts
@@ -45,7 +45,6 @@
   plugins: {
     transformers: [
       Plugin.FrontMatter(),
-      Plugin.TableOfContents(),
       Plugin.CreatedModifiedDate({
         // you can add 'git' here for last modified from Git
         // if you do rely on git for dates, ensure defaultDateType is 'modified'
@@ -55,6 +54,7 @@
       Plugin.SyntaxHighlighting(),
       Plugin.ObsidianFlavoredMarkdown({ enableInHtmlEmbed: false }),
       Plugin.GitHubFlavoredMarkdown(),
+      Plugin.TableOfContents(),
       Plugin.CrawlLinks({ markdownLinkResolution: "shortest" }),
       Plugin.Description(),
     ],
diff --git a/quartz/plugins/transformers/toc.ts b/quartz/plugins/transformers/toc.ts
index d0781ec..e831f94 100644
--- a/quartz/plugins/transformers/toc.ts
+++ b/quartz/plugins/transformers/toc.ts
@@ -26,6 +26,7 @@
 }
 
 const regexMdLinks = new RegExp(/\[([^\[]+)\](\(.*\))/, "g")
+const slugAnchor = new Slugger()
 export const TableOfContents: QuartzTransformerPlugin<Partial<Options> | undefined> = (
   userOpts,
 ) => {
@@ -38,7 +39,7 @@
           return async (tree: Root, file) => {
             const display = file.data.frontmatter?.enableToc ?? opts.showByDefault
             if (display) {
-              const slugAnchor = new Slugger()
+              slugAnchor.reset()
               const toc: TocEntry[] = []
               let highestDepth: number = opts.maxDepth
               visit(tree, "heading", (node) => {

--
Gitblit v1.10.0