git.iko.soy/typeable/pandoc
on master help sign in
RST writer: use `titleblock` instead of `title` variable for title block

Closes #4803 After this commit use `$titleblock$` in order to get what was contained in `$title$` before, that is a title and subtitle rendered according to the official rST method: http://docutils.sourceforge.net/docs/user/rst/quickstart.html#document-title-subtitle. from With this commit, the `$title$` and `$subtitle$` metadata are available and they simply carry the metadata values. This opens up more possibilities in templates.

commit2661658a696ebaab14b2792b7bbd38ef2b5904e4 authorFrancesco Occhipinti <focchi.pinti@gmail.com> dateWed 1 Aug 2018, 21:32 (8 years ago) parent08694ef
3 files changed+15−6
data/templates/default.rst+2−2 src/Text/Pandoc/Writers/RST.hs+5−4 test/Tests/Writers/RST.hs+8
data/templates/default.rst+2−2
@@ -1,5 +1,5 @@
1−$if(title)$
2−$title$
1+$if(titleblock)$
2+$titleblock$
33
44$endif$
55$for(author)$
src/Text/Pandoc/Writers/RST.hs+5−4
@@ -83,13 +83,14 @@ pandocToRST (Pandoc meta blocks) = do
8383 let render' :: Doc -> Text
8484 render' = render colwidth
8585 let subtit = case lookupMeta "subtitle" meta of
86− Just (MetaBlocks [Plain xs]) -> xs
87− _ -> []
86+ Just (MetaBlocks [Plain xs]) -> xs
87+ Just (MetaInlines xs) -> xs
88+ _ -> []
8889 title <- titleToRST (docTitle meta) subtit
8990 metadata <- metaToJSON opts
9091 (fmap render' . blockListToRST)
9192 (fmap (stripEnd . render') . inlineListToRST)
92− $ B.deleteMeta "title" $ B.deleteMeta "subtitle" meta
93+ meta
9394 body <- blockListToRST' True $ case writerTemplate opts of
9495 Just _ -> normalizeHeadings 1 blocks
9596 Nothing -> blocks
@@ -105,7 +106,7 @@ pandocToRST (Pandoc meta blocks) = do
105106 $ defField "toc-depth" (show $ writerTOCDepth opts)
106107 $ defField "number-sections" (writerNumberSections opts)
107108 $ defField "math" hasMath
108− $ defField "title" (render Nothing title :: String)
109+ $ defField "titleblock" (render Nothing title :: String)
109110 $ defField "math" hasMath
110111 $ defField "rawtex" rawTeX metadata
111112 case writerTemplate opts of
test/Tests/Writers/RST.hs+8
@@ -16,6 +16,11 @@ infix 4 =:
1616 => String -> (a, String) -> TestTree
1717(=:) = test (purely (writeRST def . toPandoc))
1818
19+testTemplate :: (ToString a, ToString c, ToPandoc a) =>
20+ String -> String -> (a, c) -> TestTree
21+testTemplate t =
22+ test (purely (writeRST def{ writerTemplate = Just t }) . toPandoc)
23+
1924tests :: [TestTree]
2025tests = [ testGroup "rubrics"
2126 [ "in list item" =:
@@ -156,4 +161,7 @@ tests = [ testGroup "rubrics"
156161 , "Header 2"
157162 , "--------"]
158163 ]
164+ , testTemplate "$subtitle$\n" "subtitle" $
165+ (setMeta "subtitle" ("subtitle" :: Inlines) $ doc $ plain "") =?>
166+ ("subtitle" :: String)
159167 ]