git.iko.soy/typeable/pandoc
on master help sign in
Use doctemplates 0.3, change type of writerTemplate.

* Require recent doctemplates. It is more flexible and supports partials. * Changed type of writerTemplate to Maybe Template instead of Maybe String. * Remove code from the LaTeX, Docbook, and JATS writers that looked in the template for strings to determine whether it is a book or an article, or whether csquotes is used. This was always kludgy and unreliable. To use csquotes for LaTeX, set `csquotes` in your variables or metadata. It is no longer sufficient to put `\usepackage{csquotes}` in your template or header includes. To specify a book style, use the `documentclass` variable or `--top-level-division`. * Change template code to use new API for doctemplates.

commitb35fae651145482f1218d32dbea5fffff60e0b0b authorJohn MacFarlane <jgm@berkeley.edu> dateFri 26 Jul 2019, 12:00 (7 years ago) parent99e24cf
41 files changed+221−214
MANUAL.txt+12−13 pandoc.cabal+2−1 src/Text/Pandoc/App/CommandLineOptions.hs+5−4 src/Text/Pandoc/App/OutputSettings.hs+12−2 src/Text/Pandoc/Class.hs+13 src/Text/Pandoc/Options.hs+2−1 src/Text/Pandoc/Templates.hs+9−20 src/Text/Pandoc/Writers/AsciiDoc.hs+5−4 src/Text/Pandoc/Writers/CommonMark.hs+5−4 src/Text/Pandoc/Writers/ConTeXt.hs+5−4 src/Text/Pandoc/Writers/Custom.hs+4−7 src/Text/Pandoc/Writers/Docbook.hs+10−14 src/Text/Pandoc/Writers/DokuWiki.hs+5−4 src/Text/Pandoc/Writers/HTML.hs+1−1 src/Text/Pandoc/Writers/Haddock.hs+5−4 src/Text/Pandoc/Writers/ICML.hs+5−4 src/Text/Pandoc/Writers/JATS.hs+11−15 src/Text/Pandoc/Writers/Jira.hs+5−4 src/Text/Pandoc/Writers/LaTeX.hs+15−44 src/Text/Pandoc/Writers/Man.hs+4−3 src/Text/Pandoc/Writers/Markdown.hs+5−4 src/Text/Pandoc/Writers/MediaWiki.hs+5−4 src/Text/Pandoc/Writers/Ms.hs+4−3 src/Text/Pandoc/Writers/Muse.hs+5−4 src/Text/Pandoc/Writers/OPML.hs+5−4 src/Text/Pandoc/Writers/OpenDocument.hs+5−4 src/Text/Pandoc/Writers/Org.hs+5−4 src/Text/Pandoc/Writers/RST.hs+5−4 src/Text/Pandoc/Writers/RTF.hs+5−4 src/Text/Pandoc/Writers/TEI.hs+5−4 src/Text/Pandoc/Writers/Texinfo.hs+5−4 src/Text/Pandoc/Writers/Textile.hs+5−4 src/Text/Pandoc/Writers/ZimWiki.hs+5−4 stack.yaml+1 test/Tests/Helpers.hs+1−1 test/Tests/Readers/Docx.hs+1−1 test/Tests/Readers/FB2.hs+1−1 test/Tests/Readers/Odt.hs+1−1 test/Tests/Writers/Native.hs+1−1 test/Tests/Writers/RST.hs+15−4 test/writer.muse+1−1
MANUAL.txt+12−13
@@ -152,18 +152,17 @@ the PDF engine requires [`fontspec`]. `xelatex` uses
152152`xelatex` will use [`mathspec`] instead of [`unicode-math`].
153153The [`upquote`] and [`microtype`] packages are used if
154154available, and [`csquotes`] will be used for [typography]
155−if `\usepackage{csquotes}` is present in the template or
156−included via `/H/--include-in-header`. The [`natbib`],
157−[`biblatex`], [`bibtex`], and [`biber`] packages can optionally
158−be used for [citation rendering]. The following packages
159−will be used to improve output quality if present, but
160−pandoc does not require them to be present:
161−[`upquote`] (for straight quotes in verbatim environments),
162−[`microtype`] (for better spacing adjustments),
163−[`parskip`] (for better inter-paragraph spaces),
164−[`xurl`] (for better line breaks in URLs),
165−[`bookmark`] (for better PDF bookmarks),
166−and [`footnotehyper`] or [`footnote`] (to allow footnotes in tables).
155+if the `csquotes` variable or metadata field is set to a
156+true value. The [`natbib`], [`biblatex`], [`bibtex`], and
157+[`biber`] packages can optionally be used for [citation
158+rendering]. The following packages will be used to improve
159+output quality if present, but pandoc does not require them to
160+be present: [`upquote`] (for straight quotes in verbatim
161+environments), [`microtype`] (for better spacing adjustments),
162+[`parskip`] (for better inter-paragraph spaces), [`xurl`] (for
163+better line breaks in URLs), [`bookmark`] (for better PDF
164+bookmarks), and [`footnotehyper`] or [`footnote`] (to allow
165+footnotes in tables).
167166
168167[TeX Live]: http://www.tug.org/texlive/
169168[`amsfonts`]: https://ctan.org/pkg/amsfonts
@@ -927,7 +926,7 @@ Options affecting specific writers {.options}
927926 all headings are shifted such that the top-level heading becomes the specified
928927 type. The default behavior is to determine the best division type via
929928 heuristics: unless other conditions apply, `section` is chosen. When the
930− LaTeX document class is set to `report`, `book`, or `memoir` (unless the
929+ `documentclass` variable is set to `report`, `book`, or `memoir` (unless the
931930 `article` option is specified), `chapter` is implied as the setting for this
932931 option. If `beamer` is the output format, specifying either `chapter` or
933932 `part` will cause top-level headings to become `\part{..}`, while
pandoc.cabal+2−1
@@ -408,7 +408,7 @@ library
408408 JuicyPixels >= 3.1.6.1 && < 3.4,
409409 Glob >= 0.7 && < 0.11,
410410 cmark-gfm >= 0.2 && < 0.3,
411− doctemplates >= 0.2.2.1 && < 0.4,
411+ doctemplates >= 0.3 && < 0.4,
412412 network-uri >= 2.6 && < 2.7,
413413 network >= 2.6,
414414 http-client >= 0.4.30 && < 0.7,
@@ -677,6 +677,7 @@ test-suite test-pandoc
677677 build-depends: base >= 4.8 && < 5,
678678 pandoc,
679679 pandoc-types >= 1.17.5 && < 1.18,
680+ mtl >= 2.2 && < 2.3,
680681 bytestring >= 0.9 && < 0.11,
681682 base64-bytestring >= 0.1 && < 1.1,
682683 text >= 1.1.1.0 && < 1.3,
src/Text/Pandoc/App/CommandLineOptions.hs+5−4
@@ -794,10 +794,11 @@ options =
794794 setUserDataDir Nothing
795795 getDefaultTemplate arg
796796 case templ of
797− Right "" -> -- e.g. for docx, odt, json:
798− E.throwIO $ PandocCouldNotFindDataFileError
799− ("templates/default." ++ arg)
800− Right t -> write t
797+ Right t
798+ | T.null t -> -- e.g. for docx, odt, json:
799+ E.throwIO $ PandocCouldNotFindDataFileError
800+ ("templates/default." ++ arg)
801+ | otherwise -> write . T.unpack $ t
801802 Left e -> E.throwIO e
802803 exitSuccess)
803804 "FORMAT")
src/Text/Pandoc/App/OutputSettings.hs+12−2
@@ -163,7 +163,7 @@ optToOutputSettings opts = do
163163 return $ ("dzslides-core", dzcore) : vars
164164 else return vars)
165165
166− templ <- case optTemplate opts of
166+ templStr <- case optTemplate opts of
167167 _ | not standalone -> return Nothing
168168 Nothing -> Just <$> getDefaultTemplate format
169169 Just tp -> do
@@ -171,7 +171,7 @@ optToOutputSettings opts = do
171171 let tp' = case takeExtension tp of
172172 "" -> tp <.> format
173173 _ -> tp
174− Just . UTF8.toString <$>
174+ Just . UTF8.toText <$>
175175 ((do surl <- stSourceURL <$> getCommonState
176176 -- we don't want to look for templates remotely
177177 -- unless the full URL is specified:
@@ -188,6 +188,16 @@ optToOutputSettings opts = do
188188 readDataFile ("templates" </> tp')
189189 _ -> throwError e))
190190
191+ let templatePath = fromMaybe "" $ optTemplate opts
192+
193+ templ <- case templStr of
194+ Nothing -> return Nothing
195+ Just ts -> do
196+ res <- compileTemplate templatePath ts
197+ case res of
198+ Left e -> throwError $ PandocTemplateError e
199+ Right t -> return $ Just t
200+
191201 case lookup "lang" (optMetadata opts) of
192202 Just l -> case parseBCP47 l of
193203 Left _ -> return ()
src/Text/Pandoc/Class.hs+13
@@ -90,6 +90,7 @@ import Text.Parsec (ParsecT, getPosition, sourceLine, sourceName)
9090import qualified Data.Time as IO (getCurrentTime)
9191import Text.Pandoc.MIME (MimeType, getMimeType, extensionFromMimeType)
9292import Text.Pandoc.Definition
93+import Text.DocTemplates (TemplateMonad(..))
9394import Data.Digest.Pure.SHA (sha1, showDigest)
9495import Data.Maybe (fromMaybe)
9596import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
@@ -313,6 +314,18 @@ readFileFromDirs (d:ds) f = catchError
313314 ((Just . UTF8.toStringLazy) <$> readFileLazy (d </> f))
314315 (\_ -> readFileFromDirs ds f)
315316
317+instance TemplateMonad PandocIO where
318+ getPartial fp =
319+ lift $ UTF8.toText <$>
320+ catchError (readFileStrict fp)
321+ (\_ -> readDataFile ("templates" </> fp))
322+
323+instance TemplateMonad PandocPure where
324+ getPartial fp =
325+ lift $ UTF8.toText <$>
326+ catchError (readFileStrict fp)
327+ (\_ -> readDataFile ("templates" </> fp))
328+
316329--
317330
318331-- | 'CommonState' represents state that is used by all
src/Text/Pandoc/Options.hs+2−1
@@ -41,6 +41,7 @@ import GHC.Generics (Generic)
4141import Skylighting (SyntaxMap, defaultSyntaxMap)
4242import Text.Pandoc.Extensions
4343import Text.Pandoc.Highlighting (Style, pygments)
44+import Text.DocTemplates (Template)
4445
4546#ifdef DERIVE_JSON_VIA_TH
4647import Data.Aeson.TH (deriveJSON, defaultOptions)
@@ -151,7 +152,7 @@ data ReferenceLocation = EndOfBlock -- ^ End of block
151152
152153-- | Options for writers
153154data WriterOptions = WriterOptions
154− { writerTemplate :: Maybe String -- ^ Template to use
155+ { writerTemplate :: Maybe Template -- ^ Template to use
155156 , writerVariables :: [(String, String)] -- ^ Variables to set in template
156157 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
157158 , writerTableOfContents :: Bool -- ^ Include table of contents
src/Text/Pandoc/Templates.hs+9−20
@@ -12,26 +12,23 @@ A simple templating system with variable substitution and conditionals.
1212
1313-}
1414
15−module Text.Pandoc.Templates ( module Text.DocTemplates
16− , renderTemplate'
15+module Text.Pandoc.Templates ( Template
16+ , compileTemplate
17+ , renderTemplate
1718 , getDefaultTemplate
1819 ) where
1920
2021import Prelude
21−import Control.Monad.Except (throwError)
22−import Data.Aeson (ToJSON (..))
23−import qualified Data.Text as T
2422import System.FilePath ((<.>), (</>))
25−import Text.DocTemplates (Template, applyTemplate,
26− compileTemplate, renderTemplate)
23+import Text.DocTemplates (Template, compileTemplate, renderTemplate)
2724import Text.Pandoc.Class (PandocMonad, readDataFile)
28−import Text.Pandoc.Error
2925import qualified Text.Pandoc.UTF8 as UTF8
26+import Data.Text (Text)
3027
3128-- | Get default template for the specified writer.
3229getDefaultTemplate :: PandocMonad m
3330 => String -- ^ Name of writer
34− -> m String
31+ -> m Text
3532getDefaultTemplate writer = do
3633 let format = takeWhile (`notElem` ("+-" :: String)) writer -- strip off extensions
3734 case format of
@@ -52,14 +49,6 @@ getDefaultTemplate writer = do
5249 "markdown_mmd" -> getDefaultTemplate "markdown"
5350 "markdown_phpextra" -> getDefaultTemplate "markdown"
5451 "gfm" -> getDefaultTemplate "commonmark"
55− _ -> let fname = "templates" </> "default" <.> format
56− in UTF8.toString <$> readDataFile fname
57−
58−-- | Like 'applyTemplate', but runs in PandocMonad and
59−-- raises an error if compilation fails.
60−renderTemplate' :: (PandocMonad m, ToJSON a)
61− => String -> a -> m T.Text
62−renderTemplate' template context =
63− case applyTemplate (T.pack template) context of
64− Left e -> throwError (PandocTemplateError e)
65− Right r -> return r
52+ _ -> do
53+ let fname = "templates" </> "default" <.> format
54+ UTF8.toText <$> readDataFile fname
src/Text/Pandoc/Writers/AsciiDoc.hs+5−4
@@ -35,7 +35,7 @@ import Text.Pandoc.Options
3535import Text.Pandoc.Parsing hiding (blankline, space)
3636import Text.Pandoc.Pretty
3737import Text.Pandoc.Shared
38−import Text.Pandoc.Templates (renderTemplate')
38+import Text.Pandoc.Templates (renderTemplate)
3939import Text.Pandoc.Writers.Shared
4040
4141data WriterState = WriterState { defListMarker :: String
@@ -94,9 +94,10 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
9494 isJust (writerTemplate opts))
9595 $ defField "math" (hasMath st)
9696 $ defField "titleblock" titleblock metadata
97− case writerTemplate opts of
98− Nothing -> return main
99− Just tpl -> renderTemplate' tpl context
97+ return $
98+ case writerTemplate opts of
99+ Nothing -> main
100+ Just tpl -> renderTemplate tpl context
100101
101102elementToAsciiDoc :: PandocMonad m
102103 => Int -> WriterOptions -> Element -> ADW m Doc
src/Text/Pandoc/Writers/CommonMark.hs+5−4
@@ -29,7 +29,7 @@ import Text.Pandoc.Definition
2929import Text.Pandoc.Options
3030import Text.Pandoc.Shared (capitalize, isHeaderBlock, isTightList,
3131 linesToPara, onlySimpleTableCells, substitute, taskListItemToAscii)
32−import Text.Pandoc.Templates (renderTemplate')
32+import Text.Pandoc.Templates (renderTemplate)
3333import Text.Pandoc.Walk (walk, walkM)
3434import Text.Pandoc.Writers.HTML (writeHtml5String, tagWithAttributes)
3535import Text.Pandoc.Writers.Shared
@@ -59,9 +59,10 @@ writeCommonMark opts (Pandoc meta blocks) = do
5959 defField "toc" toc
6060 $ defField "table-of-contents" toc
6161 $ defField "body" main metadata
62− case writerTemplate opts of
63− Nothing -> return main
64− Just tpl -> renderTemplate' tpl context
62+ return $
63+ case writerTemplate opts of
64+ Nothing -> main
65+ Just tpl -> renderTemplate tpl context
6566
6667softBreakToSpace :: Inline -> Inline
6768softBreakToSpace SoftBreak = Space
src/Text/Pandoc/Writers/ConTeXt.hs+5−4
@@ -28,7 +28,7 @@ import Text.Pandoc.Logging
2828import Text.Pandoc.Options
2929import Text.Pandoc.Pretty
3030import Text.Pandoc.Shared
31−import Text.Pandoc.Templates (renderTemplate')
31+import Text.Pandoc.Templates (renderTemplate)
3232import Text.Pandoc.Walk (query)
3333import Text.Pandoc.Writers.Shared
3434import Text.Printf (printf)
@@ -99,9 +99,10 @@ pandocToConTeXt options (Pandoc meta blocks) = do
9999 _ -> id) metadata
100100 let context' = defField "context-dir" (toContextDir
101101 $ getField "dir" context) context
102− case writerTemplate options of
103− Nothing -> return main
104− Just tpl -> renderTemplate' tpl context'
102+ return $
103+ case writerTemplate options of
104+ Nothing -> main
105+ Just tpl -> renderTemplate tpl context'
105106
106107toContextDir :: Maybe String -> String
107108toContextDir (Just "rtl") = "r2l"
src/Text/Pandoc/Writers/Custom.hs+4−7
@@ -25,7 +25,6 @@ import Data.Typeable
2525import Foreign.Lua (Lua, Pushable)
2626import Text.Pandoc.Class (PandocIO)
2727import Text.Pandoc.Definition
28−import Text.Pandoc.Error
2928import Text.Pandoc.Lua (Global (..), LuaException (LuaException),
3029 runLua, setGlobals)
3130import Text.Pandoc.Lua.Util (addField, dofileWithTraceback)
@@ -109,12 +108,10 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
109108 let (body, context) = case res of
110109 Left (LuaException msg) -> throw (PandocLuaException msg)
111110 Right x -> x
112− case writerTemplate opts of
113− Nothing -> return $ pack body
114− Just tpl ->
115− case applyTemplate (pack tpl) $ setField "body" body context of
116− Left e -> throw (PandocTemplateError e)
117− Right r -> return r
111+ return $
112+ case writerTemplate opts of
113+ Nothing -> pack body
114+ Just tpl -> renderTemplate tpl $ setField "body" body context
118115
119116docToCustom :: WriterOptions -> Pandoc -> Lua String
120117docToCustom opts (Pandoc (Meta metamap) blocks) = do
src/Text/Pandoc/Writers/Docbook.hs+10−14
@@ -17,7 +17,7 @@ import Prelude
1717import Control.Monad.Reader
1818import Data.Char (toLower)
1919import Data.Generics (everywhere, mkT)
20−import Data.List (isPrefixOf, isSuffixOf, stripPrefix)
20+import Data.List (isPrefixOf, stripPrefix)
2121import Data.Monoid (Any (..))
2222import Data.Text (Text)
2323import qualified Text.Pandoc.Builder as B
@@ -29,7 +29,7 @@ import Text.Pandoc.Logging
2929import Text.Pandoc.Options
3030import Text.Pandoc.Pretty
3131import Text.Pandoc.Shared
32−import Text.Pandoc.Templates (renderTemplate')
32+import Text.Pandoc.Templates (renderTemplate)
3333import Text.Pandoc.Walk
3434import Text.Pandoc.Writers.Math
3535import Text.Pandoc.Writers.Shared
@@ -83,13 +83,8 @@ writeDocbook opts (Pandoc meta blocks) = do
8383 else Nothing
8484 let render' :: Doc -> Text
8585 render' = render colwidth
86− let opts' = if maybe False (("/book>" `isSuffixOf`) . trimr)
87− (writerTemplate opts) &&
88− TopLevelDefault == writerTopLevelDivision opts
89− then opts{ writerTopLevelDivision = TopLevelChapter }
90− else opts
9186 -- The numbering here follows LaTeX's internal numbering
92− let startLvl = case writerTopLevelDivision opts' of
87+ let startLvl = case writerTopLevelDivision opts of
9388 TopLevelPart -> -1
9489 TopLevelChapter -> 0
9590 TopLevelSection -> 1
@@ -98,20 +93,21 @@ writeDocbook opts (Pandoc meta blocks) = do
9893 let meta' = B.setMeta "author" auths' meta
9994 metadata <- metaToJSON opts
10095 (fmap (render' . vcat) .
101− mapM (elementToDocbook opts' startLvl) .
96+ mapM (elementToDocbook opts startLvl) .
10297 hierarchicalize)
103− (fmap render' . inlinesToDocbook opts')
98+ (fmap render' . inlinesToDocbook opts)
10499 meta'
105− main <- (render' . vcat) <$> mapM (elementToDocbook opts' startLvl) elements
100+ main <- (render' . vcat) <$> mapM (elementToDocbook opts startLvl) elements
106101 let context = defField "body" main
107102 $
108103 defField "mathml" (case writerHTMLMathMethod opts of
109104 MathML -> True
110105 _ -> False) metadata
111− (if writerPreferAscii opts then toEntities else id) <$>
106+ return $
107+ (if writerPreferAscii opts then toEntities else id) $
112108 case writerTemplate opts of
113− Nothing -> return main
114− Just tpl -> renderTemplate' tpl context
109+ Nothing -> main
110+ Just tpl -> renderTemplate tpl context
115111
116112-- | Convert an Element to Docbook.
117113elementToDocbook :: PandocMonad m => WriterOptions -> Int -> Element -> DB m Doc
src/Text/Pandoc/Writers/DokuWiki.hs+5−4
@@ -36,7 +36,7 @@ import Text.Pandoc.Logging
3636import Text.Pandoc.Options (WrapOption (..), WriterOptions (writerTableOfContents, writerTemplate, writerWrapText))
3737import Text.Pandoc.Shared (camelCaseToHyphenated, escapeURI, isURI, linesToPara,
3838 removeFormatting, substitute, trimr)
39−import Text.Pandoc.Templates (renderTemplate')
39+import Text.Pandoc.Templates (renderTemplate)
4040import Text.Pandoc.Writers.Shared (defField, metaToJSON)
4141
4242data WriterState = WriterState {
@@ -78,9 +78,10 @@ pandocToDokuWiki opts (Pandoc meta blocks) = do
7878 let main = pack body
7979 let context = defField "body" main
8080 $ defField "toc" (writerTableOfContents opts) metadata
81− case writerTemplate opts of
82− Nothing -> return main
83− Just tpl -> renderTemplate' tpl context
81+ return $
82+ case writerTemplate opts of
83+ Nothing -> main
84+ Just tpl -> renderTemplate tpl context
8485
8586-- | Escape special characters for DokuWiki.
8687escapeString :: String -> String
src/Text/Pandoc/Writers/HTML.hs+1−1
@@ -226,7 +226,7 @@ writeHtmlString' st opts d = do
226226 lookup "sourcefile" (writerVariables opts)
227227 report $ NoTitleElement fallback
228228 return $ resetField "pagetitle" fallback context
229− renderTemplate' tpl
229+ return $ renderTemplate tpl
230230 (defField "body" (renderHtml' body) context')
231231
232232writeHtml' :: PandocMonad m => WriterState -> WriterOptions -> Pandoc -> m Html
src/Text/Pandoc/Writers/Haddock.hs+5−4
@@ -25,7 +25,7 @@ import Text.Pandoc.Logging
2525import Text.Pandoc.Options
2626import Text.Pandoc.Pretty
2727import Text.Pandoc.Shared
28−import Text.Pandoc.Templates (renderTemplate')
28+import Text.Pandoc.Templates (renderTemplate)
2929import Text.Pandoc.Writers.Shared
3030
3131type Notes = [[Block]]
@@ -58,9 +58,10 @@ pandocToHaddock opts (Pandoc meta blocks) = do
5858 (fmap render' . inlineListToHaddock opts)
5959 meta
6060 let context = defField "body" main metadata
61− case writerTemplate opts of
62− Nothing -> return main
63− Just tpl -> renderTemplate' tpl context
61+ return $
62+ case writerTemplate opts of
63+ Nothing -> main
64+ Just tpl -> renderTemplate tpl context
6465
6566-- | Return haddock representation of notes.
6667notesToHaddock :: PandocMonad m
src/Text/Pandoc/Writers/ICML.hs+5−4
@@ -33,7 +33,7 @@ import Text.Pandoc.Logging
3333import Text.Pandoc.Options
3434import Text.Pandoc.Pretty
3535import Text.Pandoc.Shared (isURI, linesToPara, splitBy)
36−import Text.Pandoc.Templates (renderTemplate')
36+import Text.Pandoc.Templates (renderTemplate)
3737import Text.Pandoc.Writers.Math (texMathToInlines)
3838import Text.Pandoc.Writers.Shared
3939import Text.Pandoc.XML
@@ -149,10 +149,11 @@ writeICML opts (Pandoc meta blocks) = do
149149 $ defField "charStyles" (render' $ charStylesToDoc st)
150150 $ defField "parStyles" (render' $ parStylesToDoc st)
151151 $ defField "hyperlinks" (render' $ hyperlinksToDoc $ links st) metadata
152− (if writerPreferAscii opts then toEntities else id) <$>
152+ return $
153+ (if writerPreferAscii opts then toEntities else id) $
153154 case writerTemplate opts of
154− Nothing -> return main
155− Just tpl -> renderTemplate' tpl context
155+ Nothing -> main
156+ Just tpl -> renderTemplate tpl context
156157
157158-- | Auxiliary functions for parStylesToDoc and charStylesToDoc.
158159contains :: String -> (String, (String, String)) -> [(String, String)]
src/Text/Pandoc/Writers/JATS.hs+11−15
@@ -19,7 +19,7 @@ import Control.Monad.Reader
1919import Control.Monad.State
2020import Data.Char (toLower)
2121import Data.Generics (everywhere, mkT)
22−import Data.List (isSuffixOf, partition, isPrefixOf)
22+import Data.List (partition, isPrefixOf)
2323import qualified Data.Map as M
2424import Data.Maybe (fromMaybe)
2525import Data.Time (toGregorian, Day, parseTimeM, defaultTimeLocale, formatTime)
@@ -33,7 +33,7 @@ import Text.Pandoc.Walk (walk)
3333import Text.Pandoc.Options
3434import Text.Pandoc.Pretty
3535import Text.Pandoc.Shared
36−import Text.Pandoc.Templates (renderTemplate')
36+import Text.Pandoc.Templates (renderTemplate)
3737import Text.Pandoc.Writers.Math
3838import Text.Pandoc.Writers.Shared
3939import Text.Pandoc.XML
@@ -67,27 +67,22 @@ docToJATS opts (Pandoc meta blocks) = do
6767 else Nothing
6868 let render' :: Doc -> Text
6969 render' = render colwidth
70− let opts' = if maybe False (("/book>" `isSuffixOf`) . trimr)
71− (writerTemplate opts) &&
72− TopLevelDefault == writerTopLevelDivision opts
73− then opts{ writerTopLevelDivision = TopLevelChapter }
74− else opts
7570 -- The numbering here follows LaTeX's internal numbering
76− let startLvl = case writerTopLevelDivision opts' of
71+ let startLvl = case writerTopLevelDivision opts of
7772 TopLevelPart -> -1
7873 TopLevelChapter -> 0
7974 TopLevelSection -> 1
8075 TopLevelDefault -> 1
8176 metadata <- metaToJSON opts
8277 (fmap (render' . vcat) .
83− mapM (elementToJATS opts' startLvl) .
78+ mapM (elementToJATS opts startLvl) .
8479 hierarchicalize)
85− (fmap render' . inlinesToJATS opts')
80+ (fmap render' . inlinesToJATS opts)
8681 meta
8782 main <- (render' . vcat) <$>
88− mapM (elementToJATS opts' startLvl) elements
83+ mapM (elementToJATS opts startLvl) elements
8984 notes <- reverse . map snd <$> gets jatsNotes
90− backs <- mapM (elementToJATS opts' startLvl) backElements
85+ backs <- mapM (elementToJATS opts startLvl) backElements
9186 let fns = if null notes
9287 then mempty
9388 else inTagsIndented "fn-group" $ vcat notes
@@ -110,10 +105,11 @@ docToJATS opts (Pandoc meta blocks) = do
110105 $ defField "mathml" (case writerHTMLMathMethod opts of
111106 MathML -> True
112107 _ -> False) metadata
113− (if writerPreferAscii opts then toEntities else id) <$>
108+ return $
109+ (if writerPreferAscii opts then toEntities else id) $
114110 case writerTemplate opts of
115− Nothing -> return main
116− Just tpl -> renderTemplate' tpl context
111+ Nothing -> main
112+ Just tpl -> renderTemplate tpl context
117113
118114-- | Convert an Element to JATS.
119115elementToJATS :: PandocMonad m => WriterOptions -> Int -> Element -> JATS m Doc
src/Text/Pandoc/Writers/Jira.hs+5−4
@@ -25,7 +25,7 @@ import Text.Pandoc.Definition
2525import Text.Pandoc.Logging (LogMessage (BlockNotRendered, InlineNotRendered))
2626import Text.Pandoc.Options (WriterOptions (writerTemplate))
2727import Text.Pandoc.Shared (blocksToInlines, linesToPara)
28−import Text.Pandoc.Templates (renderTemplate')
28+import Text.Pandoc.Templates (renderTemplate)
2929import Text.Pandoc.Writers.Math (texMathToInlines)
3030import Text.Pandoc.Writers.Shared (metaToJSON, defField)
3131import qualified Data.Text as T
@@ -59,9 +59,10 @@ pandocToJira opts (Pandoc meta blocks) = do
5959 notes <- gets $ T.intercalate "\n" . reverse . stNotes
6060 let main = body <> if T.null notes then "" else "\n\n" <> notes
6161 let context = defField "body" main metadata
62− case writerTemplate opts of
63− Nothing -> return main
64− Just tpl -> renderTemplate' tpl context
62+ return $
63+ case writerTemplate opts of
64+ Nothing -> main
65+ Just tpl -> renderTemplate tpl context
6566
6667-- | Escape one character as needed for Jira.
6768escapeCharForJira :: Char -> Text
src/Text/Pandoc/Writers/LaTeX.hs+15−44
@@ -21,10 +21,10 @@ import Prelude
2121import Control.Applicative ((<|>))
2222import Control.Monad.State.Strict
2323import Data.Monoid (Any(..))
24−import Data.Aeson (FromJSON, object, (.=))
24+import Data.Aeson (object, (.=))
2525import Data.Char (isAlphaNum, isAscii, isDigit, isLetter, isSpace,
2626 isPunctuation, ord, toLower)
27−import Data.List (foldl', intercalate, intersperse, isInfixOf, nubBy,
27+import Data.List (foldl', intercalate, intersperse, nubBy,
2828 stripPrefix, (\\), uncons)
2929import Data.Maybe (catMaybes, fromMaybe, isJust, mapMaybe, isNothing)
3030import qualified Data.Map as M
@@ -45,7 +45,6 @@ import Text.Pandoc.Slides
4545import Text.Pandoc.Templates
4646import Text.Pandoc.Walk
4747import Text.Pandoc.Writers.Shared
48−import qualified Text.Parsec as P
4948import Text.Printf (printf)
5049import qualified Data.Text.Normalize as Normalize
5150
@@ -131,7 +130,6 @@ pandocToLaTeX options (Pandoc meta blocks) = do
131130 let isInternalLink (Link _ _ ('#':xs,_)) = [xs]
132131 isInternalLink _ = []
133132 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
134− let template = fromMaybe "" $ writerTemplate options
135133 let colwidth = if writerWrapText options == WrapAuto
136134 then Just $ writerColumns options
137135 else Nothing
@@ -149,26 +147,17 @@ pandocToLaTeX options (Pandoc meta blocks) = do
149147 case lookup "documentclass" (writerVariables options) `mplus`
150148 fmap stringify (lookupMeta "documentclass" meta) of
151149 Just x -> x
152− Nothing ->
153− case P.parse pDocumentClass "template" template of
154− Right r -> r
155− Left _
156− | beamer -> "beamer"
157− | otherwise -> case writerTopLevelDivision options of
158− TopLevelPart -> "book"
159− TopLevelChapter -> "book"
160− _ -> "article"
150+ Nothing | beamer -> "beamer"
151+ | otherwise -> case writerTopLevelDivision options of
152+ TopLevelPart -> "book"
153+ TopLevelChapter -> "book"
154+ _ -> "article"
161155 when (documentClass `elem` chaptersClasses) $
162156 modify $ \s -> s{ stHasChapters = True }
163− -- check for \usepackage...{csquotes}; if present, we'll use
164− -- \enquote{...} for smart quotes:
165− let headerIncludesField :: FromJSON a => Maybe a
166− headerIncludesField = getField "header-includes" metadata
167− let headerIncludes = fromMaybe [] $ mplus
168− (fmap return headerIncludesField)
169− headerIncludesField
170− when (any (isInfixOf "{csquotes}") (template : headerIncludes)) $
171− modify $ \s -> s{stCsquotes = True}
157+ case T.toLower <$> getField "csquotes" metadata of
158+ Nothing -> return ()
159+ Just "false" -> return ()
160+ Just _ -> modify $ \s -> s{stCsquotes = True}
172161 let (blocks'', lastHeader) = if writerCiteMethod options == Citeproc then
173162 (blocks', [])
174163 else case reverse blocks' of
@@ -288,9 +277,10 @@ pandocToLaTeX options (Pandoc meta blocks) = do
288277 $
289278 defField "latex-dir-rtl"
290279 (getField "dir" context == Just ("rtl" :: String)) context
291− case writerTemplate options of
292− Nothing -> return main
293− Just tpl -> renderTemplate' tpl context'
280+ return $
281+ case writerTemplate options of
282+ Nothing -> main
283+ Just tpl -> renderTemplate tpl context'
294284
295285-- | Convert Elements to LaTeX
296286elementToLaTeX :: PandocMonad m => WriterOptions -> Element -> LW m Doc
@@ -1658,22 +1648,3 @@ commonFromBcp47 (Lang l _ _ _) = fromIso l
16581648 fromIso "vi" = "vietnamese"
16591649 fromIso _ = ""
16601650
1661−pDocumentOptions :: P.Parsec String () [String]
1662−pDocumentOptions = do
1663− P.char '['
1664− opts <- P.sepBy
1665− (P.many $ P.spaces *> P.noneOf (" ,]" :: String) <* P.spaces)
1666− (P.char ',')
1667− P.char ']'
1668− return opts
1669−
1670−pDocumentClass :: P.Parsec String () String
1671−pDocumentClass =
1672− do P.skipMany (P.satisfy (/='\\'))
1673− P.string "\\documentclass"
1674− classOptions <- pDocumentOptions <|> return []
1675− if ("article" :: String) `elem` classOptions
1676− then return "article"
1677− else do P.skipMany (P.satisfy (/='{'))
1678− P.char '{'
1679− P.manyTill P.letter (P.char '}')
src/Text/Pandoc/Writers/Man.hs+4−3
@@ -76,9 +76,10 @@ pandocToMan opts (Pandoc meta blocks) = do
7676 $ defField "has-tables" hasTables
7777 $ defField "hyphenate" True
7878 $ defField "pandoc-version" pandocVersion metadata
79− case writerTemplate opts of
80− Nothing -> return main
81− Just tpl -> renderTemplate' tpl context
79+ return $
80+ case writerTemplate opts of
81+ Nothing -> main
82+ Just tpl -> renderTemplate tpl context
8283
8384escString :: WriterOptions -> String -> String
8485escString _ = escapeString AsciiOnly -- for better portability
src/Text/Pandoc/Writers/Markdown.hs+5−4
@@ -43,7 +43,7 @@ import Text.Pandoc.Options
4343import Text.Pandoc.Parsing hiding (blankline, blanklines, char, space)
4444import Text.Pandoc.Pretty
4545import Text.Pandoc.Shared
46−import Text.Pandoc.Templates (renderTemplate')
46+import Text.Pandoc.Templates (renderTemplate)
4747import Text.Pandoc.Walk
4848import Text.Pandoc.Writers.HTML (writeHtml5String)
4949import Text.Pandoc.Writers.Math (texMathToInlines)
@@ -223,9 +223,10 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
223223 then id
224224 else defField "titleblock" (render' titleblock))
225225 $ addVariablesToJSON opts metadata
226− case writerTemplate opts of
227− Nothing -> return main
228− Just tpl -> renderTemplate' tpl context
226+ return $
227+ case writerTemplate opts of
228+ Nothing -> main
229+ Just tpl -> renderTemplate tpl context
229230
230231-- | Return markdown representation of reference key table.
231232refsToMarkdown :: PandocMonad m => WriterOptions -> Refs -> MD m Doc
src/Text/Pandoc/Writers/MediaWiki.hs+5−4
@@ -26,7 +26,7 @@ import Text.Pandoc.Logging
2626import Text.Pandoc.Options
2727import Text.Pandoc.Pretty (render)
2828import Text.Pandoc.Shared
29−import Text.Pandoc.Templates (renderTemplate')
29+import Text.Pandoc.Templates (renderTemplate)
3030import Text.Pandoc.Writers.Shared
3131import Text.Pandoc.XML (escapeStringForXML)
3232
@@ -66,9 +66,10 @@ pandocToMediaWiki (Pandoc meta blocks) = do
6666 let main = body ++ notes
6767 let context = defField "body" main
6868 $ defField "toc" (writerTableOfContents opts) metadata
69− case writerTemplate opts of
70− Nothing -> return $ pack main
71− Just tpl -> renderTemplate' tpl context
69+ return $
70+ case writerTemplate opts of
71+ Nothing -> pack main
72+ Just tpl -> renderTemplate tpl context
7273
7374-- | Escape special characters for MediaWiki.
7475escapeString :: String -> String
src/Text/Pandoc/Writers/Ms.hs+4−3
@@ -83,9 +83,10 @@ pandocToMs opts (Pandoc meta blocks) = do
8383 $ defField "title-meta" titleMeta
8484 $ defField "author-meta" (intercalate "; " authorsMeta)
8585 $ defField "highlighting-macros" highlightingMacros metadata
86− case writerTemplate opts of
87− Nothing -> return main
88− Just tpl -> renderTemplate' tpl context
86+ return $
87+ case writerTemplate opts of
88+ Nothing -> main
89+ Just tpl -> renderTemplate tpl context
8990
9091escapeStr :: WriterOptions -> String -> String
9192escapeStr opts =
src/Text/Pandoc/Writers/Muse.hs+5−4
@@ -40,7 +40,7 @@ import Text.Pandoc.ImageSize
4040import Text.Pandoc.Options
4141import Text.Pandoc.Pretty
4242import Text.Pandoc.Shared
43−import Text.Pandoc.Templates (renderTemplate')
43+import Text.Pandoc.Templates (renderTemplate)
4444import Text.Pandoc.Writers.Math
4545import Text.Pandoc.Writers.Shared
4646
@@ -114,9 +114,10 @@ pandocToMuse (Pandoc meta blocks) = do
114114 notes <- currentNotesToMuse
115115 let main = render colwidth $ body $+$ notes
116116 let context = defField "body" main metadata
117− case writerTemplate opts of
118− Nothing -> return main
119− Just tpl -> renderTemplate' tpl context
117+ return $
118+ case writerTemplate opts of
119+ Nothing -> main
120+ Just tpl -> renderTemplate tpl context
120121
121122-- | Helper function for flatBlockListToMuse
122123-- | Render all blocks and insert blank lines between the first two
src/Text/Pandoc/Writers/OPML.hs+5−4
@@ -24,7 +24,7 @@ import Text.Pandoc.Error
2424import Text.Pandoc.Options
2525import Text.Pandoc.Pretty
2626import Text.Pandoc.Shared
27−import Text.Pandoc.Templates (renderTemplate')
27+import Text.Pandoc.Templates (renderTemplate)
2828import Text.Pandoc.Writers.HTML (writeHtml5String)
2929import Text.Pandoc.Writers.Markdown (writeMarkdown)
3030import Text.Pandoc.Writers.Shared
@@ -44,10 +44,11 @@ writeOPML opts (Pandoc meta blocks) = do
4444 meta'
4545 main <- (render colwidth . vcat) <$> mapM (elementToOPML opts) elements
4646 let context = defField "body" main metadata
47− (if writerPreferAscii opts then toEntities else id) <$>
47+ return $
48+ (if writerPreferAscii opts then toEntities else id) $
4849 case writerTemplate opts of
49− Nothing -> return main
50− Just tpl -> renderTemplate' tpl context
50+ Nothing -> main
51+ Just tpl -> renderTemplate tpl context
5152
5253
5354writeHtmlInlines :: PandocMonad m => [Inline] -> m Text
src/Text/Pandoc/Writers/OpenDocument.hs+5−4
@@ -32,7 +32,7 @@ import Text.Pandoc.Logging
3232import Text.Pandoc.Options
3333import Text.Pandoc.Pretty
3434import Text.Pandoc.Shared (linesToPara)
35−import Text.Pandoc.Templates (renderTemplate')
35+import Text.Pandoc.Templates (renderTemplate)
3636import qualified Text.Pandoc.Translations as Term (Term(Figure, Table))
3737import Text.Pandoc.Writers.Math
3838import Text.Pandoc.Writers.Shared
@@ -240,9 +240,10 @@ writeOpenDocument opts (Pandoc meta blocks) = do
240240 let context = defField "body" body
241241 $ defField "toc" (writerTableOfContents opts)
242242 $defField "automatic-styles" (render' automaticStyles) metadata
243− case writerTemplate opts of
244− Nothing -> return body
245− Just tpl -> renderTemplate' tpl context
243+ return $
244+ case writerTemplate opts of
245+ Nothing -> body
246+ Just tpl -> renderTemplate tpl context
246247
247248withParagraphStyle :: PandocMonad m
248249 => WriterOptions -> String -> [Block] -> OD m Doc
src/Text/Pandoc/Writers/Org.hs+5−4
@@ -27,7 +27,7 @@ import Text.Pandoc.Logging
2727import Text.Pandoc.Options
2828import Text.Pandoc.Pretty
2929import Text.Pandoc.Shared
30−import Text.Pandoc.Templates (renderTemplate')
30+import Text.Pandoc.Templates (renderTemplate)
3131import Text.Pandoc.Writers.Shared
3232
3333data WriterState =
@@ -66,9 +66,10 @@ pandocToOrg (Pandoc meta blocks) = do
6666 let context = defField "body" main
6767 . defField "math" hasMath
6868 $ metadata
69− case writerTemplate opts of
70− Nothing -> return main
71− Just tpl -> renderTemplate' tpl context
69+ return $
70+ case writerTemplate opts of
71+ Nothing -> main
72+ Just tpl -> renderTemplate tpl context
7273
7374-- | Return Org representation of notes.
7475notesToOrg :: PandocMonad m => [[Block]] -> Org m Doc
src/Text/Pandoc/Writers/RST.hs+5−4
@@ -28,7 +28,7 @@ import Text.Pandoc.Logging
2828import Text.Pandoc.Options
2929import Text.Pandoc.Pretty
3030import Text.Pandoc.Shared
31−import Text.Pandoc.Templates (renderTemplate')
31+import Text.Pandoc.Templates (renderTemplate)
3232import Text.Pandoc.Writers.Shared
3333import Text.Pandoc.Walk
3434
@@ -88,9 +88,10 @@ pandocToRST (Pandoc meta blocks) = do
8888 $ defField "titleblock" (render Nothing title :: String)
8989 $ defField "math" hasMath
9090 $ defField "rawtex" rawTeX metadata
91− case writerTemplate opts of
92− Nothing -> return main
93− Just tpl -> renderTemplate' tpl context
91+ return $
92+ case writerTemplate opts of
93+ Nothing -> main
94+ Just tpl -> renderTemplate tpl context
9495 where
9596 normalizeHeadings lev (Header l a i:bs) =
9697 Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
src/Text/Pandoc/Writers/RTF.hs+5−4
@@ -30,7 +30,7 @@ import Text.Pandoc.ImageSize
3030import Text.Pandoc.Logging
3131import Text.Pandoc.Options
3232import Text.Pandoc.Shared
33−import Text.Pandoc.Templates (renderTemplate')
33+import Text.Pandoc.Templates (renderTemplate)
3434import Text.Pandoc.Walk
3535import Text.Pandoc.Writers.Math
3636import Text.Pandoc.Writers.Shared
@@ -112,9 +112,10 @@ writeRTF options doc = do
112112 -- of the toc rather than a boolean:
113113 . defField "toc" toc
114114 else id) metadata
115− case writerTemplate options of
116− Just tpl -> renderTemplate' tpl context
117− Nothing -> return $ T.pack $
115+ return $
116+ case writerTemplate options of
117+ Just tpl -> renderTemplate tpl context
118+ Nothing -> T.pack $
118119 case reverse body of
119120 ('\n':_) -> body
120121 _ -> body ++ "\n"
src/Text/Pandoc/Writers/TEI.hs+5−4
@@ -25,7 +25,7 @@ import Text.Pandoc.Logging
2525import Text.Pandoc.Options
2626import Text.Pandoc.Pretty
2727import Text.Pandoc.Shared
28−import Text.Pandoc.Templates (renderTemplate')
28+import Text.Pandoc.Templates (renderTemplate)
2929import Text.Pandoc.Writers.Shared
3030import Text.Pandoc.XML
3131
@@ -54,9 +54,10 @@ writeTEI opts (Pandoc meta blocks) = do
5454 defField "mathml" (case writerHTMLMathMethod opts of
5555 MathML -> True
5656 _ -> False) metadata
57− case writerTemplate opts of
58− Nothing -> return main
59− Just tpl -> renderTemplate' tpl context
57+ return $
58+ case writerTemplate opts of
59+ Nothing -> main
60+ Just tpl -> renderTemplate tpl context
6061
6162-- | Convert an Element to TEI.
6263elementToTEI :: PandocMonad m => WriterOptions -> Int -> Element -> m Doc
src/Text/Pandoc/Writers/Texinfo.hs+5−4
@@ -31,7 +31,7 @@ import Text.Pandoc.Logging
3131import Text.Pandoc.Options
3232import Text.Pandoc.Pretty
3333import Text.Pandoc.Shared
34−import Text.Pandoc.Templates (renderTemplate')
34+import Text.Pandoc.Templates (renderTemplate)
3535import Text.Pandoc.Writers.Shared
3636import Text.Printf (printf)
3737
@@ -82,9 +82,10 @@ pandocToTexinfo options (Pandoc meta blocks) = do
8282 $ defField "titlepage" titlePage
8383 $
8484 defField "strikeout" (stStrikeout st) metadata
85− case writerTemplate options of
86− Nothing -> return body
87− Just tpl -> renderTemplate' tpl context
85+ return $
86+ case writerTemplate options of
87+ Nothing -> body
88+ Just tpl -> renderTemplate tpl context
8889
8990-- | Escape things as needed for Texinfo.
9091stringToTexinfo :: String -> String
src/Text/Pandoc/Writers/Textile.hs+5−4
@@ -25,7 +25,7 @@ import Text.Pandoc.Logging
2525import Text.Pandoc.Options
2626import Text.Pandoc.Pretty (render)
2727import Text.Pandoc.Shared
28−import Text.Pandoc.Templates (renderTemplate')
28+import Text.Pandoc.Templates (renderTemplate)
2929import Text.Pandoc.Writers.Shared
3030import Text.Pandoc.XML (escapeStringForXML)
3131
@@ -57,9 +57,10 @@ pandocToTextile opts (Pandoc meta blocks) = do
5757 notes <- gets $ unlines . reverse . stNotes
5858 let main = pack $ body ++ if null notes then "" else "\n\n" ++ notes
5959 let context = defField "body" main metadata
60− case writerTemplate opts of
61− Nothing -> return main
62− Just tpl -> renderTemplate' tpl context
60+ return $
61+ case writerTemplate opts of
62+ Nothing -> main
63+ Just tpl -> renderTemplate tpl context
6364
6465withUseTags :: PandocMonad m => TW m a -> TW m a
6566withUseTags action = do
src/Text/Pandoc/Writers/ZimWiki.hs+5−4
@@ -29,7 +29,7 @@ import Text.Pandoc.Logging
2929import Text.Pandoc.Options (WrapOption (..), WriterOptions (writerTableOfContents, writerTemplate, writerWrapText))
3030import Text.Pandoc.Shared (escapeURI, isURI, linesToPara, removeFormatting,
3131 substitute, trimr)
32−import Text.Pandoc.Templates (renderTemplate')
32+import Text.Pandoc.Templates (renderTemplate)
3333import Text.Pandoc.Writers.Shared (defField, metaToJSON)
3434
3535data WriterState = WriterState {
@@ -59,9 +59,10 @@ pandocToZimWiki opts (Pandoc meta blocks) = do
5959 let main = body
6060 let context = defField "body" main
6161 $ defField "toc" (writerTableOfContents opts) metadata
62− case writerTemplate opts of
63− Just tpl -> renderTemplate' tpl context
64− Nothing -> return main
62+ return $
63+ case writerTemplate opts of
64+ Just tpl -> renderTemplate tpl context
65+ Nothing -> main
6566
6667-- | Escape special characters for ZimWiki.
6768escapeString :: String -> String
stack.yaml+1
@@ -19,6 +19,7 @@ extra-deps:
1919- tasty-lua-0.2.0
2020- skylighting-core-0.8.2
2121- skylighting-0.8.2
22+- doctemplates-0.3
2223ghc-options:
2324 "$locals": -Wall -fno-warn-unused-do-bind -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -Wincomplete-uni-patterns -Widentities -Wcpp-undef -fhide-source-paths -Wno-missing-home-modules
2425resolver: lts-13.17
test/Tests/Helpers.hs+1−1
@@ -136,7 +136,7 @@ instance ToString Pandoc where
136136 where s = case d of
137137 (Pandoc (Meta m) _)
138138 | M.null m -> Nothing
139− | otherwise -> Just "" -- need this to get meta output
139+ | otherwise -> Just mempty -- need this to get meta output
140140
141141instance ToString Blocks where
142142 toString = unpack . purely (writeNative def) . toPandoc
test/Tests/Readers/Docx.hs+1−1
@@ -46,7 +46,7 @@ instance ToString NoNormPandoc where
4646 where s = case d of
4747 NoNormPandoc (Pandoc (Meta m) _)
4848 | M.null m -> Nothing
49− | otherwise -> Just "" -- need this to get meta output
49+ | otherwise -> Just mempty -- need this to get meta output
5050
5151instance ToPandoc NoNormPandoc where
5252 toPandoc = unNoNorm
test/Tests/Readers/FB2.hs+1−1
@@ -24,7 +24,7 @@ import Data.Text.Lazy (fromStrict)
2424import System.FilePath (replaceExtension)
2525
2626fb2ToNative :: Text -> Text
27−fb2ToNative = purely (writeNative def{ writerTemplate = Just "" }) . purely (readFB2 def)
27+fb2ToNative = purely (writeNative def{ writerTemplate = Just mempty }) . purely (readFB2 def)
2828
2929fb2Test :: TestName -> FilePath -> TestTree
3030fb2Test name path = goldenVsString name native (fromTextLazy . fromStrict . fb2ToNative . toText <$> BS.readFile path)
test/Tests/Readers/Odt.hs+1−1
@@ -61,7 +61,7 @@ instance ToString NoNormPandoc where
6161 where s = case d of
6262 NoNormPandoc (Pandoc (Meta m) _)
6363 | M.null m -> Nothing
64− | otherwise -> Just "" -- need this for Meta output
64+ | otherwise -> Just mempty -- need this for Meta output
6565
6666instance ToPandoc NoNormPandoc where
6767 toPandoc = unNoNorm
test/Tests/Writers/Native.hs+1−1
@@ -11,7 +11,7 @@ import Text.Pandoc.Arbitrary ()
1111
1212p_write_rt :: Pandoc -> Bool
1313p_write_rt d =
14− read (unpack $ purely (writeNative def{ writerTemplate = Just "" }) d) == d
14+ read (unpack $ purely (writeNative def{ writerTemplate = Just mempty }) d) == d
1515
1616p_write_blocks_rt :: [Block] -> Bool
1717p_write_blocks_rt bs =
test/Tests/Writers/RST.hs+15−4
@@ -3,6 +3,7 @@
33module Tests.Writers.RST (tests) where
44
55import Prelude
6+import Control.Monad.Identity
67import Test.Tasty
78import Test.Tasty.HUnit
89import Tests.Helpers
@@ -10,6 +11,8 @@ import Text.Pandoc
1011import Text.Pandoc.Arbitrary ()
1112import Text.Pandoc.Builder
1213import Text.Pandoc.Writers.RST
14+import Text.Pandoc.Templates (compileTemplate)
15+import qualified Data.Text as T
1316
1417infix 4 =:
1518(=:) :: (ToString a, ToPandoc a)
@@ -18,8 +21,15 @@ infix 4 =:
1821
1922testTemplate :: (ToString a, ToString c, ToPandoc a) =>
2023 String -> String -> (a, c) -> TestTree
21−testTemplate t =
22− test (purely (writeRST def{ writerTemplate = Just t }) . toPandoc)
24+testTemplate t = case runIdentity (compileTemplate [] (T.pack t)) of
25+ Left e -> error $ "Could not compile RST template: " ++ e
26+ Right templ -> test (purely (writeRST def{ writerTemplate = Just templ }) . toPandoc)
27+
28+bodyTemplate :: Template
29+bodyTemplate = case runIdentity (compileTemplate [] "$body$\n") of
30+ Left e -> error $
31+ "Could not compile RST bodyTemplate" ++ e
32+ Right templ -> templ
2333
2434tests :: [TestTree]
2535tests = [ testGroup "rubrics"
@@ -104,7 +114,8 @@ tests = [ testGroup "rubrics"
104114 [ "foo"
105115 , "==="]
106116 -- note: heading normalization is only done in standalone mode
107− , test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
117+ , test (purely (writeRST def{ writerTemplate = Just bodyTemplate })
118+ . toPandoc)
108119 "heading levels" $
109120 header 1 (text "Header 1") <>
110121 header 3 (text "Header 2") <>
@@ -134,7 +145,7 @@ tests = [ testGroup "rubrics"
134145 , ""
135146 , "Header 2"
136147 , "--------"]
137− , test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
148+ , test (purely (writeRST def{ writerTemplate = Just bodyTemplate }) . toPandoc)
138149 "minimal heading levels" $
139150 header 2 (text "Header 1") <>
140151 header 3 (text "Header 2") <>
test/writer.muse+1−1
@@ -1,4 +1,4 @@
1−#author John MacFarlane
1+#author John MacFarlane, Anonymous
22#title Pandoc Test Suite
33#date July 17, 2006
44