aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:12:03 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:12:03 +0000
commit359f1109745afbfb1a38754576ba875a406de122 (patch)
tree1ef03822adcbf0975287308d3d8610ebb325fa81
parent858f728d433c32e73d0e17c230e3e1bdbb452508 (diff)
downloadpandoc-359f1109745afbfb1a38754576ba875a406de122.tar.gz
Fixed markdown writer to use templates.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1696 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs52
-rw-r--r--templates/markdown.template17
2 files changed, 44 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index e95b139a6..305b71310 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -31,6 +31,7 @@ Markdown: <http://daringfireball.net/projects/markdown/>
-}
module Text.Pandoc.Writers.Markdown ( writeMarkdown) where
import Text.Pandoc.Definition
+import Text.Pandoc.Templates
import Text.Pandoc.Shared
import Text.Pandoc.Blocks
import Text.ParserCombinators.Parsec ( parse, GenParser )
@@ -45,33 +46,36 @@ type WriterState = (Notes, Refs)
-- | Convert Pandoc to Markdown.
writeMarkdown :: WriterOptions -> Pandoc -> String
writeMarkdown opts document =
- render $ evalState (pandocToMarkdown opts document) ([],[])
+ evalState (pandocToMarkdown opts document) ([],[])
-- | Return markdown representation of document.
-pandocToMarkdown :: WriterOptions -> Pandoc -> State WriterState Doc
+pandocToMarkdown :: WriterOptions -> Pandoc -> State WriterState String
pandocToMarkdown opts (Pandoc meta blocks) = do
- return empty -- TODO
--- 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 $+$ header'
--- else empty
--- let headerBlocks = filter isHeaderBlock blocks
--- let toc = if writerTableOfContents opts
--- then tableOfContents opts headerBlocks
--- else empty
--- body <- blockListToMarkdown opts blocks
--- (notes, _) <- get
--- notes' <- notesToMarkdown opts (reverse notes)
--- (_, refs) <- get -- note that the notes may contain refs
--- refs' <- keyTableToMarkdown opts (reverse refs)
--- return $ head' $+$ before' $+$ toc $+$ body $+$ text "" $+$
--- notes' $+$ text "" $+$ refs' $+$ after'
+ metaBlock <- metaToMarkdown opts meta
+ let head' = if writerStandalone opts
+ then metaBlock
+ else empty
+ let headerBlocks = filter isHeaderBlock blocks
+ let toc = if writerTableOfContents opts
+ then tableOfContents opts headerBlocks
+ else empty
+ body <- blockListToMarkdown opts blocks
+ (notes, _) <- get
+ notes' <- notesToMarkdown opts (reverse notes)
+ (_, refs) <- get -- note that the notes may contain refs
+ refs' <- keyTableToMarkdown opts (reverse refs)
+ let context = writerVariables opts ++
+ [ ("toc", render toc)
+ , ("body", render $ body $+$ text "" $+$ notes' $+$
+ text "" $+$ refs')
+ , ("titleblock", render head')
+ ]
+ let templ = if writerStandalone opts
+ then writerTemplate opts
+ else "$if(toc)$$toc$\n$endif$" ++
+ "$if(before)$$before$\n$endif$" ++
+ "$body$$if(after)$$after$\n$endif$"
+ return $ renderTemplate context templ
-- | Return markdown representation of reference key table.
keyTableToMarkdown :: WriterOptions -> KeyTable -> State WriterState Doc
diff --git a/templates/markdown.template b/templates/markdown.template
index 1333ed77b..d5df8a606 100644
--- a/templates/markdown.template
+++ b/templates/markdown.template
@@ -1 +1,16 @@
-TODO
+$if(titleblock)$
+$titleblock$
+$endif$
+$if(header-includes)$
+$header-includes$
+$endif$
+$if(before)$
+$before$
+$endif$
+$if(toc)$
+$toc$
+$endif$
+$body$
+$if(after)$
+$after$
+$endif$