From e52278b0828ffb2da495b14bcf3f5d2ac760ff4c Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 22 Mar 2023 14:22:18 +0100 Subject: [PATCH] Add gfm_auto_identifiers to reader for correct ids in TOC link due to current limitation of Pandoc https://github.com/jgm/pandoc/issues/8709 --- src/format/markdown/format-markdown.ts | 15 ++++++++++++++- .../docs/smoke-all/2023/03/22/gha-toc-4917.qmd | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/docs/smoke-all/2023/03/22/gha-toc-4917.qmd diff --git a/src/format/markdown/format-markdown.ts b/src/format/markdown/format-markdown.ts index 83fdde7874b..6e2c9d256be 100644 --- a/src/format/markdown/format-markdown.ts +++ b/src/format/markdown/format-markdown.ts @@ -4,8 +4,9 @@ * Copyright (C) 2020-2022 Posit Software, PBC */ -import { kOutputDivs, kVariant } from "../../config/constants.ts"; +import { kFrom, kOutputDivs, kToc, kVariant } from "../../config/constants.ts"; import { Format } from "../../config/types.ts"; +import { pandocFormat } from "../../core/pandoc/pandoc-formats.ts"; import { createFormat, plaintextFormat } from "../formats-shared.ts"; import { kGfmCommonmarkVariant } from "./format-markdown-consts.ts"; @@ -36,6 +37,18 @@ export function gfmFormat(): Format { render: { [kVariant]: kGfmCommonmarkVariant, }, + resolveFormat: (format: Format) => { + if (format.pandoc[kToc] === true) { + // we need to add gfm_auto_identifiers to reader otherwise ids for toc are not valid + // see https://github.com/quarto-dev/quarto-cli/issues/4917 and + // https://github.com/jgm/pandoc/issues/8709 + format.pandoc[kFrom] = pandocFormat( + format.pandoc[kFrom] || "markdown", + ["gfm_auto_identifiers"], + [], + ); + } + }, }); } diff --git a/tests/docs/smoke-all/2023/03/22/gha-toc-4917.qmd b/tests/docs/smoke-all/2023/03/22/gha-toc-4917.qmd new file mode 100644 index 00000000000..aaa4b96185f --- /dev/null +++ b/tests/docs/smoke-all/2023/03/22/gha-toc-4917.qmd @@ -0,0 +1,17 @@ +--- +format: + gfm: + toc: true +_quarto: + tests: + gfm: + ensureFileRegexMatches: + - ["\\(#with-ending-dot\\)", "\\(#with-adot-in-the-middle\\)"] + - ["\\(#with-ending-dot\\.\\)","\\(#with-a\\.dot-in-the-middle\\)"] +--- + +# A header + +# With ending dot. + +# With a.dot in the middle