git.iko.soy/typeable/pandoc
on master help sign in
Roll back part of of `--shift-heading-level-by` change.

With positive heading shifts, starting in 2.8 this option caused metadata titles to be removed and changed to regular headings. This behavior is incompatible with the old behavior of `--base-header-level` and breaks old workflows, so with this commit we are rolling back this change. Now, there is an asymmetry in positive and negative heading level shifts: + With positive shifts, the metadata title stays the same and does not get changed to a heading in the body. + With negative shifts, a heading can be converted into the metadata title. I think this is a desirable combination of features, despite the asymmetry. One might, e.g., want to have a document with level-1 section headigs, but render it to HTML with level-2 headings, retaining the metadata title (which pandoc will render as a level-1 heading with the default template). Closes #5957. Revises #5615.

commit992f77c17c4c86b7f4836767457094a3a20cdc65 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 5 Dec 2019, 09:54 (7 years ago) parent5711ca3
3 files changed+9−15
MANUAL.txt+7−6 src/Text/Pandoc/Shared.hs−6 test/command/shift-heading-level-by.md+2−3
MANUAL.txt+7−6
@@ -493,14 +493,15 @@ header when requesting a document from a URL:
493493 headings become level 1 headings, and level 3 headings
494494 become level 2 headings. Headings cannot have a level
495495 less than 1, so a heading that would be shifted below level 1
496− becomes a regular paragraph. Exception: with a shift of -1,
497− a level-1 heading at the beginning of the document
498− replaces the metadata title. Conversely, with a shift
499− of +1, a nonempty metadata title becomes a level-1 heading at
500− the beginning of the document. `--shift-heading-level-by=-1`
496+ becomes a regular paragraph. Exception: with a shift of -N,
497+ a level-N heading at the beginning of the document
498+ replaces the metadata title. `--shift-heading-level-by=-1`
501499 is a good choice when converting HTML or Markdown documents that
502500 use an initial level-1 heading for the document title and
503− level-2+ headings for sections.
501+ level-2+ headings for sections. `--shift-heading-level-by=1`
502+ may be a good choice for converting Markdown documents that
503+ use level-1 headings for sections to HTML, since pandoc uses
504+ a level-1 heading to render the document title.
504505
505506`--base-header-level=`*NUMBER*
506507
src/Text/Pandoc/Shared.hs−6
@@ -641,12 +641,6 @@ headerShift n (Pandoc meta (Header m _ ils : bs))
641641 | n < 0
642642 , m + n == 0 = headerShift n $
643643 B.setTitle (B.fromList ils) $ Pandoc meta bs
644−headerShift n (Pandoc meta bs)
645− | n > 0
646− , not (null (docTitle meta))
647− = Pandoc meta' (Header n nullAttr (docTitle meta) : bs')
648− where
649− Pandoc meta' bs' = headerShift n $ B.deleteMeta "title" $ Pandoc meta bs
650644headerShift n (Pandoc meta bs) = Pandoc meta (walk shift bs)
651645 where
652646 shift :: Block -> Block
test/command/shift-heading-level-by.md+2−3
@@ -8,9 +8,8 @@ title: My title
88
99## Second
1010^D
11−Pandoc (Meta {unMeta = fromList []})
12−[Header 1 ("",[],[]) [Str "My",Space,Str "title"]
13−,Header 2 ("first-heading",[],[]) [Str "First",Space,Str "heading"]
11+Pandoc (Meta {unMeta = fromList [("title",MetaInlines [Str "My",Space,Str "title"])]})
12+[Header 2 ("first-heading",[],[]) [Str "First",Space,Str "heading"]
1413,Header 3 ("second",[],[]) [Str "Second"]]
1514```
1615