aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:15:24 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:15:24 +0000
commit16f0604beca57b17c6e1fa330930a903a4fd81c7 (patch)
treeb32522f821b9dc89a82bc494498650a4eb223948
parent60cb80b459bb248fa907251b756f41a67a316e5b (diff)
downloadpandoc-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
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs45
-rw-r--r--templates/markdown.template4
-rw-r--r--tests/writer.markdown2
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