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
This commit is contained in:
fiddlosopher 2009-02-07 19:20:35 +00:00
parent a03331a3b4
commit dcedb2f712
2 changed files with 11 additions and 5 deletions

View file

@ -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

View file

@ -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