From dcedb2f71243197f34c241b28b8ae76c2f1422c6 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 7 Feb 2009 19:20:35 +0000 Subject: Fixed bug with header spacing in Markdown and RST writers. A null header (Meta [] [] []) should not cause a blank line at the beginning of output. But a blank line is needed between a non-null header and the main text. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1536 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Writers/Markdown.hs | 7 +++++-- src/Text/Pandoc/Writers/RST.hs | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 70d1f0c91..bebb88a76 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -52,11 +52,13 @@ pandocToMarkdown :: WriterOptions -> Pandoc -> State WriterState Doc pandocToMarkdown opts (Pandoc meta blocks) = do let before = writerIncludeBefore opts let after = writerIncludeAfter opts + let header = writerHeader opts let before' = if null before then empty else text before let after' = if null after then empty else text after + let header' = if null header then empty else text header metaBlock <- metaToMarkdown opts meta let head' = if writerStandalone opts - then metaBlock $+$ text (writerHeader opts) + then metaBlock $+$ header' else empty let headerBlocks = filter isHeaderBlock blocks let toc = if writerTableOfContents opts @@ -104,11 +106,12 @@ escapeString = escapeStringUsing markdownEscapes -- | Convert bibliographic information into Markdown header. metaToMarkdown :: WriterOptions -> Meta -> State WriterState Doc +metaToMarkdown _ (Meta [] [] []) = return empty metaToMarkdown opts (Meta title authors date) = do title' <- titleToMarkdown opts title authors' <- authorsToMarkdown authors date' <- dateToMarkdown date - return $ title' $+$ authors' $+$ date' + return $ title' $+$ authors' $+$ date' $+$ text "" titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc titleToMarkdown _ [] = return empty diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 91826cbcd..728c78712 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -59,12 +59,14 @@ pandocToRST :: Pandoc -> State WriterState Doc pandocToRST (Pandoc meta blocks) = do opts <- get >>= (return . stOptions) let before = writerIncludeBefore opts - let after = writerIncludeAfter opts + after = writerIncludeAfter opts + header = writerHeader opts before' = if null before then empty else text before after' = if null after then empty else text after + header' = if null header then empty else text header metaBlock <- metaToRST opts meta let head' = if (writerStandalone opts) - then metaBlock $+$ text (writerHeader opts) + then metaBlock $+$ header' else empty body <- blockListToRST blocks includes <- get >>= (return . concat . stIncludes) @@ -129,6 +131,7 @@ escapeString = escapeStringUsing (backslashEscapes "`\\|*_") -- | Convert bibliographic information into RST header. metaToRST :: WriterOptions -> Meta -> State WriterState Doc +metaToRST _ (Meta [] [] []) = return empty metaToRST opts (Meta title authors date) = do title' <- titleToRST title authors' <- authorsToRST authors @@ -136,7 +139,7 @@ metaToRST opts (Meta title authors date) = do let toc = if writerTableOfContents opts then text "" $+$ text ".. contents::" else empty - return $ title' $+$ authors' $+$ date' $+$ toc + return $ title' $+$ authors' $+$ date' $+$ toc $+$ text "" titleToRST :: [Inline] -> State WriterState Doc titleToRST [] = return empty -- cgit v1.2.3