git.iko.soy/typeable/pandoc
on master help sign in
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

commit16f0604beca57b17c6e1fa330930a903a4fd81c7 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:15 (17 years ago) parent60cb80b
3 files changed+15−36
src/Text/Pandoc/Writers/Markdown.hs+11−34 templates/markdown.template+3−1 tests/writer.markdown+1−1
src/Text/Pandoc/Writers/Markdown.hs+11−34
@@ -50,11 +50,12 @@ writeMarkdown opts document =
5050
5151-- | Return markdown representation of document.
5252pandocToMarkdown :: WriterOptions -> Pandoc -> State WriterState String
53−pandocToMarkdown opts (Pandoc meta blocks) = do
54− metaBlock <- metaToMarkdown opts meta
55− let head' = if writerStandalone opts
56− then metaBlock
57− else empty
53+pandocToMarkdown opts (Pandoc (Meta title authors date) blocks) = do
54+ title' <- inlineListToMarkdown opts title
55+ authors' <- liftM (hcat . intersperse (text "; ")) $
56+ mapM (inlineListToMarkdown opts) authors
57+ date' <- inlineListToMarkdown opts date
58+ let titleblock = not $ null title && null authors && null date
5859 let headerBlocks = filter isHeaderBlock blocks
5960 let toc = if writerTableOfContents opts
6061 then tableOfContents opts headerBlocks
@@ -74,8 +75,11 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
7475 let context = writerVariables opts ++
7576 [ ("toc", render toc)
7677 , ("body", main)
77− , ("titleblock", render head')
78− ]
78+ , ("title", render title')
79+ , ("authors", render authors')
80+ , ("date", render date')
81+ ] ++
82+ [ ("titleblock", "yes") | titleblock ]
7983 if writerStandalone opts
8084 then return $ renderTemplate context $ writerTemplate opts
8185 else return main
@@ -112,33 +116,6 @@ escapeString :: String -> String
112116escapeString = escapeStringUsing markdownEscapes
113117 where markdownEscapes = backslashEscapes "\\`*_>#~^"
114118
115−-- | Convert bibliographic information into Markdown header.
116−metaToMarkdown :: WriterOptions -> Meta -> State WriterState Doc
117−metaToMarkdown _ (Meta [] [] []) = return empty
118−metaToMarkdown opts (Meta title authors date) = do
119− title' <- titleToMarkdown opts title
120− authors' <- authorsToMarkdown opts authors
121− date' <- dateToMarkdown opts date
122− return $ title' $+$ authors' $+$ date' $+$ text ""
123−
124−titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
125−titleToMarkdown _ [] = return empty
126−titleToMarkdown opts lst = do
127− contents <- inlineListToMarkdown opts lst
128− return $ text "% " <> contents
129−
130−authorsToMarkdown :: WriterOptions -> [[Inline]] -> State WriterState Doc
131−authorsToMarkdown _ [] = return empty
132−authorsToMarkdown opts lst = do
133− authors <- mapM (inlineListToMarkdown opts) lst
134− return $ text "% " <> (hcat $ intersperse (text ", ") authors)
135−
136−dateToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
137−dateToMarkdown _ [] = return empty
138−dateToMarkdown opts str = do
139− date <- inlineListToMarkdown opts str
140− return $ text "% " <> date
141−
142119-- | Construct table of contents from list of header blocks.
143120tableOfContents :: WriterOptions -> [Block] -> Doc
144121tableOfContents opts headers =
templates/markdown.template+3−1
@@ -1,5 +1,7 @@
11$if(titleblock)$
2−$titleblock$
2+% $title$
3+% $authors$
4+% $date$
35
46$endif$
57$if(header-includes)$
tests/writer.markdown+1−1
@@ -1,5 +1,5 @@
11% Pandoc Test Suite
2−% John MacFarlane, Anonymous
2+% John MacFarlane; Anonymous
33% July 17, 2006
44
55This is a set of tests for pandoc. Most of them are adapted from