diff options
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 13 | ||||
-rw-r--r-- | tests/Tests/Writers/RST.hs | 21 |
2 files changed, 18 insertions, 16 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 diff --git a/tests/Tests/Writers/RST.hs b/tests/Tests/Writers/RST.hs index bb7b2a446..b9e359dae 100644 --- a/tests/Tests/Writers/RST.hs +++ b/tests/Tests/Writers/RST.hs @@ -46,7 +46,10 @@ tests = [ testGroup "rubrics" unlines [ "foo" , "==="] - , "heading levels" =: + -- note: heading normalization is only done in standalone mode + , test (writeRST def{ writerStandalone = True, + writerTemplate = "$body$\n" } . toPandoc) + "heading levels" $ header 1 (text "Header 1") <> header 3 (text "Header 2") <> header 2 (text "Header 2") <> @@ -75,7 +78,9 @@ tests = [ testGroup "rubrics" , "" , "Header 2" , "--------"] - , "minimal heading levels" =: + , test (writeRST def{ writerStandalone = True, + writerTemplate = "$body$\n" } . toPandoc) + "minimal heading levels" $ header 2 (text "Header 1") <> header 3 (text "Header 2") <> header 2 (text "Header 1") <> @@ -84,21 +89,21 @@ tests = [ testGroup "rubrics" header 3 (text "Header 2") =?> unlines [ "Header 1" - , "--------" + , "========" , "" , "Header 2" - , "~~~~~~~~" + , "--------" , "" , "Header 1" - , "--------" + , "========" , "" , "Header 2" - , "~~~~~~~~" + , "--------" , "" , "Header 3" - , "^^^^^^^^" + , "~~~~~~~~" , "" , "Header 2" - , "~~~~~~~~"] + , "--------"] ] ] |