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.
This commit is contained in:
parent
5711ca3880
commit
992f77c17c
3 changed files with 9 additions and 15 deletions
13
MANUAL.txt
13
MANUAL.txt
|
@ -493,14 +493,15 @@ header when requesting a document from a URL:
|
|||
headings become level 1 headings, and level 3 headings
|
||||
become level 2 headings. Headings cannot have a level
|
||||
less than 1, so a heading that would be shifted below level 1
|
||||
becomes a regular paragraph. Exception: with a shift of -1,
|
||||
a level-1 heading at the beginning of the document
|
||||
replaces the metadata title. Conversely, with a shift
|
||||
of +1, a nonempty metadata title becomes a level-1 heading at
|
||||
the beginning of the document. `--shift-heading-level-by=-1`
|
||||
becomes a regular paragraph. Exception: with a shift of -N,
|
||||
a level-N heading at the beginning of the document
|
||||
replaces the metadata title. `--shift-heading-level-by=-1`
|
||||
is a good choice when converting HTML or Markdown documents that
|
||||
use an initial level-1 heading for the document title and
|
||||
level-2+ headings for sections.
|
||||
level-2+ headings for sections. `--shift-heading-level-by=1`
|
||||
may be a good choice for converting Markdown documents that
|
||||
use level-1 headings for sections to HTML, since pandoc uses
|
||||
a level-1 heading to render the document title.
|
||||
|
||||
`--base-header-level=`*NUMBER*
|
||||
|
||||
|
|
|
@ -641,12 +641,6 @@ headerShift n (Pandoc meta (Header m _ ils : bs))
|
|||
| n < 0
|
||||
, m + n == 0 = headerShift n $
|
||||
B.setTitle (B.fromList ils) $ Pandoc meta bs
|
||||
headerShift n (Pandoc meta bs)
|
||||
| n > 0
|
||||
, not (null (docTitle meta))
|
||||
= Pandoc meta' (Header n nullAttr (docTitle meta) : bs')
|
||||
where
|
||||
Pandoc meta' bs' = headerShift n $ B.deleteMeta "title" $ Pandoc meta bs
|
||||
headerShift n (Pandoc meta bs) = Pandoc meta (walk shift bs)
|
||||
where
|
||||
shift :: Block -> Block
|
||||
|
|
|
@ -8,9 +8,8 @@ title: My title
|
|||
|
||||
## Second
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList []})
|
||||
[Header 1 ("",[],[]) [Str "My",Space,Str "title"]
|
||||
,Header 2 ("first-heading",[],[]) [Str "First",Space,Str "heading"]
|
||||
Pandoc (Meta {unMeta = fromList [("title",MetaInlines [Str "My",Space,Str "title"])]})
|
||||
[Header 2 ("first-heading",[],[]) [Str "First",Space,Str "heading"]
|
||||
,Header 3 ("second",[],[]) [Str "Second"]]
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue