Skip to content

Commit 8875ec6

Browse files
committed
allow pandoc to handle section numbering for markdown formats
1 parent 85c3639 commit 8875ec6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/command/render/pandoc.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
isHtmlOutput,
4444
isIpynbOutput,
4545
isLatexOutput,
46+
isMarkdownOutput,
4647
} from "../../config/format.ts";
4748
import {
4849
isIncludeMetadata,
@@ -636,7 +637,10 @@ export async function runPandoc(
636637
// remove selected args and defaults if we are handling some things on behalf of pandoc
637638
// (e.g. handling section numbering). note that section numbering is handled by the
638639
// crossref filter so we only do this if the user hasn't disabled the crossref filter
639-
if (!isLatexOutput(options.format.pandoc) && crossrefFilterActive(options)) {
640+
if (
641+
!isLatexOutput(options.format.pandoc) &&
642+
!isMarkdownOutput(options.format.pandoc) && crossrefFilterActive(options)
643+
) {
640644
delete allDefaults[kNumberSections];
641645
delete allDefaults[kNumberOffset];
642646
const removeArgs = new Map<string, boolean>();

src/resources/filters/crossref/sections.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ function sections()
6161
el.content:insert(1, pandoc.Space())
6262
end
6363

64-
el.content:insert(1, pandoc.Span(
65-
stringToInlines(section),
66-
pandoc.Attr("", { "header-section-number"})
67-
))
64+
if _quarto.format.isHtmlOutput() then
65+
el.content:insert(1, pandoc.Span(
66+
stringToInlines(section),
67+
pandoc.Attr("", { "header-section-number"})
68+
))
69+
else
70+
tprepend(el.content, stringToInlines(section))
71+
end
6872

6973
if appendix then
7074
el.content:insert(1, pandoc.Space())
@@ -93,7 +97,9 @@ function currentSectionLevel()
9397
end
9498

9599
function numberSections()
96-
return not _quarto.format.isLatexOutput() and numberSectionsOptionEnabled()
100+
return not _quarto.format.isLatexOutput() and
101+
not _quarto.format.isMarkdownOutput()
102+
and numberSectionsOptionEnabled()
97103
end
98104

99105
function numberSectionsOptionEnabled()

0 commit comments

Comments
 (0)