diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 01:16:19 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 01:16:19 +0000 |
commit | 312d9337b99070dc7eae365dd0b1b3148aecc349 (patch) | |
tree | b66effffdfd16a0334f2d255d8cf4ba2f446bb1f | |
parent | f4e738a6a9c21507ca6cad16125bdd96afeaf473 (diff) | |
download | pandoc-312d9337b99070dc7eae365dd0b1b3148aecc349.tar.gz |
Improved RST writer.
Updated test suite.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1725 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 43 | ||||
-rw-r--r-- | templates/rst.template | 14 | ||||
-rw-r--r-- | tests/s5.basic.html | 3 | ||||
-rw-r--r-- | tests/s5.fancy.html | 3 | ||||
-rw-r--r-- | tests/s5.inserts.html | 4 | ||||
-rw-r--r-- | tests/writer.html | 3 | ||||
-rw-r--r-- | tests/writer.rst | 2 |
7 files changed, 28 insertions, 44 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 diff --git a/templates/rst.template b/templates/rst.template index abca8d81a..b4c3e2733 100644 --- a/templates/rst.template +++ b/templates/rst.template @@ -1,15 +1,19 @@ -$if(titleblock)$ $if(title)$ $title$ $endif$ -$if(authors)$ -$authors$ -$endif$ +$for(author)$ +:Author: $author$ +$endfor$ $if(date)$ -Date: $date$ +:Date: $date$ $endif$ +$if(author)$ +$else$ +$if(date)$ + +$endif$ $endif$ $if(math)$ .. role:: math(raw) diff --git a/tests/s5.basic.html b/tests/s5.basic.html index 5e1b0abcf..4f49e3a57 100644 --- a/tests/s5.basic.html +++ b/tests/s5.basic.html @@ -4,7 +4,8 @@ <title>My S5 Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> - <meta name="author" content="Sam Smith; Jen Jones" /> + <meta name="author" content="Sam Smith" /> + <meta name="author" content="Jen Jones" /> <meta name="date" content="July 15, 2006" /> <!-- configuration parameters --> <meta name="defaultView" content="slideshow" /> diff --git a/tests/s5.fancy.html b/tests/s5.fancy.html index 5a2e534f0..42a6aaf8a 100644 --- a/tests/s5.fancy.html +++ b/tests/s5.fancy.html @@ -4,7 +4,8 @@ <title>My S5 Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> - <meta name="author" content="Sam Smith; Jen Jones" /> + <meta name="author" content="Sam Smith" /> + <meta name="author" content="Jen Jones" /> <meta name="date" content="July 15, 2006" /> <!-- configuration parameters --> <meta name="defaultView" content="slideshow" /> diff --git a/tests/s5.inserts.html b/tests/s5.inserts.html index 53a89457e..c8704871d 100644 --- a/tests/s5.inserts.html +++ b/tests/s5.inserts.html @@ -4,8 +4,10 @@ <title>My S5 Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> - <meta name="author" content="Sam Smith; Jen Jones" /> + <meta name="author" content="Sam Smith" /> + <meta name="author" content="Jen Jones" /> <meta name="date" content="July 15, 2006" /> + <link rel="stylesheet" href="main.css" type="text/css" /> STUFF INSERTED </head> <body> diff --git a/tests/writer.html b/tests/writer.html index 2996c135d..c6f31b107 100644 --- a/tests/writer.html +++ b/tests/writer.html @@ -4,7 +4,8 @@ <title>Pandoc Test Suite</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> - <meta name="author" content="John MacFarlane; Anonymous" /> + <meta name="author" content="John MacFarlane" /> + <meta name="author" content="Anonymous" /> <meta name="date" content="July 17, 2006" /> </head> <body> diff --git a/tests/writer.rst b/tests/writer.rst index a0a75adc9..c2ef31b34 100644 --- a/tests/writer.rst +++ b/tests/writer.rst @@ -4,7 +4,7 @@ Pandoc Test Suite :Author: John MacFarlane :Author: Anonymous -:Date: July 17, 2006 +:Date: July 17, 2006 .. role:: math(raw) :format: html latex |