aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-09-19 23:32:23 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-09-19 23:32:23 -0700
commit54526665c39fe389ffaa202211e481fa9b692e76 (patch)
tree74fa7b28f33a0b5194fb298433f8cb6864bea4b7 /src/Text/Pandoc/Writers
parent4d49f76dbb8f51db5fd2527c3ef779996bf8936f (diff)
parent5788f62ef55f59d00f5fae7f309cd5d1b349d8f8 (diff)
downloadpandoc-54526665c39fe389ffaa202211e481fa9b692e76.tar.gz
Merge pull request #2405 from lierdakil/rest-normalize-amend
[RST Writer] Don't normalize heading levels below input minimum
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index fae908f30..754aee29c 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -81,7 +81,8 @@ pandocToRST (Pandoc meta blocks) = do
(fmap (render colwidth) . blockListToRST)
(fmap (trimr . render colwidth) . inlineListToRST)
$ deleteMeta "title" $ deleteMeta "subtitle" meta
- body <- blockListToRST' True $ normalizeHeadings 1 blocks
+ let minLev = findMinHeadingLevel Nothing blocks
+ body <- blockListToRST' True $ normalizeHeadings minLev blocks
notes <- liftM (reverse . stNotes) get >>= notesToRST
-- note that the notes may contain refs, so we do them first
refs <- liftM (reverse . stLinks) get >>= refsToRST
@@ -107,6 +108,11 @@ pandocToRST (Pandoc meta blocks) = do
headerLtEq _ _ = False
normalizeHeadings lev (b:bs) = b:normalizeHeadings lev bs
normalizeHeadings _ [] = []
+ findMinHeadingLevel Nothing (Header l _a _i:bs) = findMinHeadingLevel (Just l) bs
+ findMinHeadingLevel (Just ol) (Header l _a _i:bs) =
+ findMinHeadingLevel (Just $ if ol>l then l else ol) bs
+ findMinHeadingLevel l (_:bs) = findMinHeadingLevel l bs
+ findMinHeadingLevel l [] = fromMaybe 1 l
-- | Return RST representation of reference key table.
refsToRST :: Refs -> State WriterState Doc