aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-10-12 23:00:27 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-10-12 23:00:27 -0700
commit24f68654e919a8ff138d0a1fcfbf8e045b8ae38b (patch)
treec25384e1afcc515f96aff2ae0120f39c4877c48f /src/Text
parentfb51077712fbe2bca80b52d8e4b5f96b07980dcf (diff)
downloadpandoc-24f68654e919a8ff138d0a1fcfbf8e045b8ae38b.tar.gz
RST writer: do header normalization only in "standalone" mode.
If we're producing a fragment, just skip normalization. After all, the fragment might be somewhere in the middle of the document. It's more important for fragments to have consistency in rendering (so they can be pieced together) than to normalize. This closes #2394. It's simpler and more robust than my earlier fix.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 754aee29c..cb3ead514 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -81,8 +81,9 @@ pandocToRST (Pandoc meta blocks) = do
(fmap (render colwidth) . blockListToRST)
(fmap (trimr . render colwidth) . inlineListToRST)
$ deleteMeta "title" $ deleteMeta "subtitle" meta
- let minLev = findMinHeadingLevel Nothing blocks
- body <- blockListToRST' True $ normalizeHeadings minLev blocks
+ body <- blockListToRST' True $ if writerStandalone opts
+ then normalizeHeadings 1 blocks
+ else 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
@@ -102,17 +103,13 @@ pandocToRST (Pandoc meta blocks) = do
then return $ renderTemplate' (writerTemplate opts) context
else return main
where
- normalizeHeadings lev (Header l a i:bs) = Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
+ normalizeHeadings lev (Header l a i:bs) =
+ Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
where (cont,bs') = break (headerLtEq l) bs
headerLtEq level (Header l' _ _) = l' <= level
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