diff options
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 45 | ||||
-rw-r--r-- | templates/markdown.template | 4 | ||||
-rw-r--r-- | tests/writer.markdown | 2 |
3 files changed, 15 insertions, 36 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index c1172101d..7b3bb9f1f 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -50,11 +50,12 @@ writeMarkdown opts document = -- | Return markdown representation of document. pandocToMarkdown :: WriterOptions -> Pandoc -> State WriterState String -pandocToMarkdown opts (Pandoc meta blocks) = do - metaBlock <- metaToMarkdown opts meta - let head' = if writerStandalone opts - then metaBlock - else empty +pandocToMarkdown opts (Pandoc (Meta title authors date) blocks) = do + title' <- inlineListToMarkdown opts title + authors' <- liftM (hcat . intersperse (text "; ")) $ + mapM (inlineListToMarkdown opts) authors + date' <- inlineListToMarkdown opts date + let titleblock = not $ null title && null authors && null date let headerBlocks = filter isHeaderBlock blocks let toc = if writerTableOfContents opts then tableOfContents opts headerBlocks @@ -74,8 +75,11 @@ pandocToMarkdown opts (Pandoc meta blocks) = do let context = writerVariables opts ++ [ ("toc", render toc) , ("body", main) - , ("titleblock", render head') - ] + , ("title", render title') + , ("authors", render authors') + , ("date", render date') + ] ++ + [ ("titleblock", "yes") | titleblock ] if writerStandalone opts then return $ renderTemplate context $ writerTemplate opts else return main @@ -112,33 +116,6 @@ escapeString :: String -> String escapeString = escapeStringUsing markdownEscapes where markdownEscapes = backslashEscapes "\\`*_>#~^" --- | 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 opts authors - date' <- dateToMarkdown opts date - return $ title' $+$ authors' $+$ date' $+$ text "" - -titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc -titleToMarkdown _ [] = return empty -titleToMarkdown opts lst = do - contents <- inlineListToMarkdown opts lst - return $ text "% " <> contents - -authorsToMarkdown :: WriterOptions -> [[Inline]] -> State WriterState Doc -authorsToMarkdown _ [] = return empty -authorsToMarkdown opts lst = do - authors <- mapM (inlineListToMarkdown opts) lst - return $ text "% " <> (hcat $ intersperse (text ", ") authors) - -dateToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc -dateToMarkdown _ [] = return empty -dateToMarkdown opts str = do - date <- inlineListToMarkdown opts str - return $ text "% " <> date - -- | Construct table of contents from list of header blocks. tableOfContents :: WriterOptions -> [Block] -> Doc tableOfContents opts headers = diff --git a/templates/markdown.template b/templates/markdown.template index e9c54e246..68fe0eb13 100644 --- a/templates/markdown.template +++ b/templates/markdown.template @@ -1,5 +1,7 @@ $if(titleblock)$ -$titleblock$ +% $title$ +% $authors$ +% $date$ $endif$ $if(header-includes)$ diff --git a/tests/writer.markdown b/tests/writer.markdown index 2f7ac3f4b..cf476342c 100644 --- a/tests/writer.markdown +++ b/tests/writer.markdown @@ -1,5 +1,5 @@ % Pandoc Test Suite -% John MacFarlane, Anonymous +% John MacFarlane; Anonymous % July 17, 2006 This is a set of tests for pandoc. Most of them are adapted from |