diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 01:15:24 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 01:15:24 +0000 |
commit | 16f0604beca57b17c6e1fa330930a903a4fd81c7 (patch) | |
tree | b32522f821b9dc89a82bc494498650a4eb223948 /src | |
parent | 60cb80b459bb248fa907251b756f41a67a316e5b (diff) | |
download | pandoc-16f0604beca57b17c6e1fa330930a903a4fd81c7.tar.gz |
Use separate title, author, date variables in markdown template.
This allows us to simplify the writer code and gives the
user more control.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1719 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 45 |
1 files changed, 11 insertions, 34 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 = |