aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:16:19 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:16:19 +0000
commit312d9337b99070dc7eae365dd0b1b3148aecc349 (patch)
treeb66effffdfd16a0334f2d255d8cf4ba2f446bb1f /src
parentf4e738a6a9c21507ca6cad16125bdd96afeaf473 (diff)
downloadpandoc-312d9337b99070dc7eae365dd0b1b3148aecc349.tar.gz
Improved RST writer.
Updated test suite. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1725 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs43
1 files changed, 9 insertions, 34 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 7deb1d629..3cd705ff9 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -58,16 +58,15 @@ writeRST opts document =
-- | Return RST representation of document.
pandocToRST :: Pandoc -> State WriterState String
-pandocToRST (Pandoc meta blocks) = do
+pandocToRST (Pandoc (Meta tit auth dat) blocks) = do
opts <- liftM stOptions get
let before = writerIncludeBefore opts
after = writerIncludeAfter opts
before' = if null before then empty else text before
after' = if null after then empty else text after
- metaBlock <- metaToRST opts meta
- let head' = if writerStandalone opts
- then render metaBlock
- else ""
+ title <- titleToRST tit
+ authors <- mapM inlineListToRST auth
+ date <- inlineListToRST dat
body <- blockListToRST blocks
notes <- liftM (reverse . stNotes) get >>= notesToRST
-- note that the notes may contain refs, so we do them first
@@ -78,9 +77,10 @@ pandocToRST (Pandoc meta blocks) = do
text "" $+$ refs $+$ pics $+$ after'
let context = writerVariables opts ++
[ ("body", main)
- , ("titleblock", head')
- ] ++
- [ ("math", "yes") | hasMath ]
+ , ("title", render title)
+ , ("date", render date) ] ++
+ [ ("math", "yes") | hasMath ] ++
+ [ ("author", render a) | a <- authors ]
if writerStandalone opts
then return $ renderTemplate context $ writerTemplate opts
else return main
@@ -136,38 +136,13 @@ wrappedRST opts inlines = do
escapeString :: String -> String
escapeString = escapeStringUsing (backslashEscapes "`\\|*_")
--- | Convert bibliographic information into RST header.
-metaToRST :: WriterOptions -> Meta -> State WriterState Doc
-metaToRST _ (Meta [] [] []) = return empty
-metaToRST opts (Meta title authors date) = do
- title' <- titleToRST title
- authors' <- authorsToRST authors
- date' <- dateToRST date
- let toc = if writerTableOfContents opts
- then text "" $+$ text ".. contents::"
- else empty
- return $ title' $+$ authors' $+$ date' $+$ toc $+$ text ""
-
titleToRST :: [Inline] -> State WriterState Doc
titleToRST [] = return empty
titleToRST lst = do
contents <- inlineListToRST lst
let titleLength = length $ render contents
let border = text (replicate titleLength '=')
- return $ border $+$ contents $+$ border <> text "\n"
-
-authorsToRST :: [[Inline]] -> State WriterState Doc
-authorsToRST [] = return empty
-authorsToRST (first:rest) = do
- rest' <- authorsToRST rest
- first' <- inlineListToRST first
- return $ (text ":Author: " <> first') $+$ rest'
-
-dateToRST :: [Inline] -> State WriterState Doc
-dateToRST [] = return empty
-dateToRST str = do
- date <- inlineListToRST str
- return $ text ":Date: " <> date
+ return $ border $+$ contents $+$ border
-- | Convert Pandoc block element to RST.
blockToRST :: Block -- ^ Block element