diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-09-10 23:16:13 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-09-10 23:16:13 -0700 |
commit | 88dc6fac5d2d6f494e9c334261ecb40d3e156667 (patch) | |
tree | b4786323d43f44433a41bddc5b85433af34bfcb4 /src/Text/Pandoc/Shared.hs | |
parent | a64b3ab61ff34dca25f04f4f97b283dc5159ac87 (diff) | |
download | pandoc-88dc6fac5d2d6f494e9c334261ecb40d3e156667.tar.gz |
Add --shift-heading-level-by option.
Deprecate --base-heading-level.
The new option does everything the old one does, but also
allows negative shifts. It also promotes the document
metadata (if not null) to a level-1 heading with a +1 shift,
and demotes an initial level-1 heading to document metadata
with a -1 shift. This supports converting documents that
use an initial level-1 heading for the document title.
Closes #5615.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 06715145e..e169ccb82 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -565,10 +565,23 @@ isHeaderBlock _ = False -- | Shift header levels up or down. headerShift :: Int -> Pandoc -> Pandoc -headerShift n = walk shift - where shift :: Block -> Block - shift (Header level attr inner) = Header (level + n) attr inner - shift x = x +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 + shift (Header level attr inner) + | level + n > 0 = Header (level + n) attr inner + | otherwise = Para inner + shift x = x -- | Remove empty paragraphs. stripEmptyParagraphs :: Pandoc -> Pandoc |