Skip to content

Commit 80fff1c

Browse files
committed
Don’t shift headings if the documents H1s
1 parent 2569ab2 commit 80fff1c

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

src/command/render/pandoc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export async function runPandoc(
269269
const formatExtras = options.format.formatExtras
270270
? (await options.format.formatExtras(
271271
options.source,
272+
options.markdown,
272273
options.flags || {},
273274
options.format,
274275
options.libDir,

src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export interface Format {
281281
resolveFormat?: (format: Format) => void;
282282
formatExtras?: (
283283
input: string,
284+
markdown: string,
284285
flags: PandocFlags,
285286
format: Format,
286287
libDir: string,

src/format/html/format-html.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export function htmlFormat(
106106
},
107107
formatExtras: async (
108108
input: string,
109+
_markdown: string,
109110
flags: PandocFlags,
110111
format: Format,
111112
_libDir: string,

src/format/ipynb/format-ipynb.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export function ipynbFormat(): Format {
3030
standalone: true,
3131
[kDefaultImageExtension]: "png",
3232
},
33-
formatExtras: (_input: string, _flags: PandocFlags, format: Format) => {
33+
formatExtras: (
34+
_input: string,
35+
_markdown: string,
36+
_flags: PandocFlags,
37+
format: Format,
38+
) => {
3439
// Snag the p
3540

3641
const resolveTemplate = () => {

src/format/pdf/format-pdf.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function createPdfFormat(autoShiftHeadings = true, koma = true): Format {
109109
},
110110
formatExtras: (
111111
_input: string,
112+
markdown: string,
112113
flags: PandocFlags,
113114
format: Format,
114115
_libDir: string,
@@ -218,8 +219,12 @@ function createPdfFormat(autoShiftHeadings = true, koma = true): Format {
218219
}),
219220
};
220221

222+
// Don't shift the headings if we see any H1s (we can't shift up any longer)
223+
const hasLevelOneHeadings = !!markdown.match(/\n^#\s.*$/gm);
224+
221225
// pdfs with no other heading level oriented options get their heading level shifted by -1
222226
if (
227+
!hasLevelOneHeadings &&
223228
autoShiftHeadings &&
224229
(flags?.[kNumberSections] === true ||
225230
format.pandoc[kNumberSections] === true) &&

src/format/reveal/format-reveal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function revealjsFormat() {
9999
formatPreviewFile: revealMuliplexPreviewFile,
100100
formatExtras: async (
101101
input: string,
102+
_markdown: string,
102103
flags: PandocFlags,
103104
format: Format,
104105
libDir: string,

0 commit comments

Comments
 (0)