git.iko.soy/typeable/pandoc
on master help sign in
Options: Removed writerStandalone, made writerTemplate a Maybe.

Previously setting writerStandalone = True did nothing unless a template was provided in writerTemplate. Now a fragment will be generated if writerTemplate is Nothing; otherwise, the specified template will be used and standalone output generated. [API change]

commitfb8a2540bdb91eee0ecf620b4e9d7acf3d78042f authorJohn MacFarlane <jgm@berkeley.edu> dateWed 30 Nov 2016, 15:34 (10 years ago) parentac312ca
33 files changed+117−133
pandoc.hs+4−5 src/Text/Pandoc/Options.hs+2−4 src/Text/Pandoc/Writers/AsciiDoc.hs+5−4 src/Text/Pandoc/Writers/CommonMark.hs+3−3 src/Text/Pandoc/Writers/ConTeXt.hs+3−3 src/Text/Pandoc/Writers/Custom.hs+3−5 src/Text/Pandoc/Writers/Docbook.hs+5−4 src/Text/Pandoc/Writers/DokuWiki.hs+3−4 src/Text/Pandoc/Writers/EPUB.hs−1 src/Text/Pandoc/Writers/FB2.hs+1−1 src/Text/Pandoc/Writers/HTML.hs+8−14 src/Text/Pandoc/Writers/Haddock.hs+3−3 src/Text/Pandoc/Writers/ICML.hs+3−3 src/Text/Pandoc/Writers/LaTeX.hs+4−4 src/Text/Pandoc/Writers/Man.hs+3−3 src/Text/Pandoc/Writers/Markdown.hs+14−14 src/Text/Pandoc/Writers/MediaWiki.hs+3−3 src/Text/Pandoc/Writers/Native.hs+3−7 src/Text/Pandoc/Writers/OPML.hs+3−3 src/Text/Pandoc/Writers/OpenDocument.hs+3−3 src/Text/Pandoc/Writers/Org.hs+3−3 src/Text/Pandoc/Writers/RST.hs+6−6 src/Text/Pandoc/Writers/RTF.hs+5−5 src/Text/Pandoc/Writers/Shared.hs+2−1 src/Text/Pandoc/Writers/TEI.hs+3−3 src/Text/Pandoc/Writers/Texinfo.hs+3−3 src/Text/Pandoc/Writers/Textile.hs+3−3 src/Text/Pandoc/Writers/ZimWiki.hs+4−4 tests/Tests/Helpers.hs+3−3 tests/Tests/Readers/Docx.hs+3−3 tests/Tests/Readers/Odt.hs+3−3 tests/Tests/Writers/Native.hs+1−1 tests/Tests/Writers/RST.hs+2−4
pandoc.hs+4−5
@@ -1292,18 +1292,18 @@ convertWithOpts opts args = do
12921292 let standalone' = standalone || not (isTextFormat format) || pdfOutput
12931293
12941294 templ <- case templatePath of
1295− _ | not standalone' -> return ""
1295+ _ | not standalone' -> return Nothing
12961296 Nothing -> do
12971297 deftemp <- getDefaultTemplate datadir format
12981298 case deftemp of
12991299 Left e -> throwIO e
1300− Right t -> return t
1300+ Right t -> return (Just t)
13011301 Just tp -> do
13021302 -- strip off extensions
13031303 let tp' = case takeExtension tp of
13041304 "" -> tp <.> format
13051305 _ -> tp
1306− E.catch (UTF8.readFile tp')
1306+ Just <$> E.catch (UTF8.readFile tp')
13071307 (\e -> if isDoesNotExistError e
13081308 then E.catch
13091309 (readDataFileUTF8 datadir
@@ -1416,8 +1416,7 @@ convertWithOpts opts args = do
14161416 _ -> do pairs <- mapM (\s -> sourceToDoc [s]) sources
14171417 return (mconcat $ map fst pairs, mconcat $ map snd pairs)
14181418
1419− let writerOptions = def { writerStandalone = standalone',
1420− writerTemplate = templ,
1419+ let writerOptions = def { writerTemplate = templ,
14211420 writerVariables = variables'',
14221421 writerTabStop = tabStop,
14231422 writerTableOfContents = toc,
src/Text/Pandoc/Options.hs+2−4
@@ -356,8 +356,7 @@ data ReferenceLocation = EndOfBlock -- ^ End of block
356356
357357-- | Options for writers
358358data WriterOptions = WriterOptions
359− { writerStandalone :: Bool -- ^ Include header and footer
360− , writerTemplate :: String -- ^ Template to use in standalone mode
359+ { writerTemplate :: Maybe String -- ^ Template to use
361360 , writerVariables :: [(String, String)] -- ^ Variables to set in template
362361 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
363362 , writerTableOfContents :: Bool -- ^ Include table of contents
@@ -405,8 +404,7 @@ data WriterOptions = WriterOptions
405404 } deriving (Show, Data, Typeable, Generic)
406405
407406instance Default WriterOptions where
408− def = WriterOptions { writerStandalone = False
409− , writerTemplate = ""
407+ def = WriterOptions { writerTemplate = Nothing
410408 , writerVariables = []
411409 , writerTabStop = 4
412410 , writerTableOfContents = False
src/Text/Pandoc/Writers/AsciiDoc.hs+5−4
@@ -92,12 +92,13 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
9292 let main = render colwidth body
9393 let context = defField "body" main
9494 $ defField "toc"
95− (writerTableOfContents opts && writerStandalone opts)
95+ (writerTableOfContents opts &&
96+ writerTemplate opts /= Nothing)
9697 $ defField "titleblock" titleblock
9798 $ metadata'
98− if writerStandalone opts
99− then return $ renderTemplate' (writerTemplate opts) context
100− else return main
99+ case writerTemplate opts of
100+ Nothing -> return main
101+ Just tpl -> return $ renderTemplate' tpl context
101102
102103-- | Escape special characters for AsciiDoc.
103104escapeString :: String -> String
src/Text/Pandoc/Writers/CommonMark.hs+3−3
@@ -56,9 +56,9 @@ writeCommonMark opts (Pandoc meta blocks) = rendered
5656 (inlinesToCommonMark opts)
5757 meta
5858 context = defField "body" main $ metadata
59− rendered = if writerStandalone opts
60− then renderTemplate' (writerTemplate opts) context
61− else main
59+ rendered = case writerTemplate opts of
60+ Nothing -> main
61+ Just tpl -> renderTemplate' tpl context
6262
6363processNotes :: Inline -> State [[Block]] Inline
6464processNotes (Note bs) = do
src/Text/Pandoc/Writers/ConTeXt.hs+3−3
@@ -98,9 +98,9 @@ pandocToConTeXt options (Pandoc meta blocks) = do
9898 getField "lang" context)
9999 $ defField "context-dir" (toContextDir $ getField "dir" context)
100100 $ context
101− return $ if writerStandalone options
102− then renderTemplate' (writerTemplate options) context'
103− else main
101+ return $ case writerTemplate options of
102+ Nothing -> main
103+ Just tpl -> renderTemplate' tpl context'
104104
105105toContextDir :: Maybe String -> String
106106toContextDir (Just "rtl") = "r2l"
src/Text/Pandoc/Writers/Custom.hs+3−5
@@ -202,11 +202,9 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
202202 Lua.close lua
203203 setForeignEncoding enc
204204 let body = rendered
205− if writerStandalone opts
206− then do
207− let context' = setField "body" body context
208− return $ renderTemplate' (writerTemplate opts) context'
209− else return body
205+ case writerTemplate opts of
206+ Nothing -> return body
207+ Just tpl -> return $ renderTemplate' tpl $ setField "body" body context
210208
211209docToCustom :: LuaState -> WriterOptions -> Pandoc -> IO String
212210docToCustom lua opts (Pandoc (Meta metamap) blocks) = do
src/Text/Pandoc/Writers/Docbook.hs+5−4
@@ -80,7 +80,8 @@ writeDocbook opts (Pandoc meta blocks) =
8080 then Just $ writerColumns opts
8181 else Nothing
8282 render' = render colwidth
83− opts' = if ("/book>" `isSuffixOf` (trimr $ writerTemplate opts) &&
83+ opts' = if (maybe False (("/book>" `isSuffixOf`) . trimr)
84+ (writerTemplate opts) &&
8485 TopLevelDefault == writerTopLevelDivision opts)
8586 then opts{ writerTopLevelDivision = TopLevelChapter }
8687 else opts
@@ -103,9 +104,9 @@ writeDocbook opts (Pandoc meta blocks) =
103104 MathML _ -> True
104105 _ -> False)
105106 $ metadata
106− in if writerStandalone opts
107− then renderTemplate' (writerTemplate opts) context
108− else main
107+ in case writerTemplate opts of
108+ Nothing -> main
109+ Just tpl -> renderTemplate' tpl context
109110
110111-- | Convert an Element to Docbook.
111112elementToDocbook :: WriterOptions -> Int -> Element -> Doc
src/Text/Pandoc/Writers/DokuWiki.hs+3−4
@@ -42,7 +42,6 @@ module Text.Pandoc.Writers.DokuWiki ( writeDokuWiki ) where
4242import Text.Pandoc.Definition
4343import Text.Pandoc.Options ( WriterOptions(
4444 writerTableOfContents
45− , writerStandalone
4645 , writerTemplate
4746 , writerWrapText), WrapOption(..) )
4847import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting
@@ -102,9 +101,9 @@ pandocToDokuWiki opts (Pandoc meta blocks) = do
102101 let context = defField "body" main
103102 $ defField "toc" (writerTableOfContents opts)
104103 $ metadata
105− if writerStandalone opts
106− then return $ renderTemplate' (writerTemplate opts) context
107− else return main
104+ case writerTemplate opts of
105+ Nothing -> return main
106+ Just tpl -> return $ renderTemplate' tpl context
108107
109108-- | Escape special characters for DokuWiki.
110109escapeString :: String -> String
src/Text/Pandoc/Writers/EPUB.hs−1
@@ -342,7 +342,6 @@ writeEPUB opts doc@(Pandoc meta _) = do
342342 : ("css", "stylesheet.css")
343343 : writerVariables opts
344344 let opts' = opts{ writerEmailObfuscation = NoObfuscation
345− , writerStandalone = True
346345 , writerSectionDivs = True
347346 , writerHtml5 = epub3
348347 , writerVariables = vars
src/Text/Pandoc/Writers/FB2.hs+1−1
@@ -77,7 +77,7 @@ writeFB2 :: WriterOptions -- ^ conversion options
7777 -> Pandoc -- ^ document to convert
7878 -> IO String -- ^ FictionBook2 document (not encoded yet)
7979writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
80− modify (\s -> s { writerOptions = opts { writerStandalone = True } })
80+ modify (\s -> s { writerOptions = opts })
8181 desc <- description meta
8282 fp <- frontpage meta
8383 secs <- renderSections 1 blocks
src/Text/Pandoc/Writers/HTML.hs+8−14
@@ -102,17 +102,19 @@ nl opts = if writerWrapText opts == WrapNone
102102writeHtmlString :: WriterOptions -> Pandoc -> String
103103writeHtmlString opts d =
104104 let (body, context) = evalState (pandocToHtml opts d) defaultWriterState
105− in if writerStandalone opts
106− then inTemplate opts context body
107− else renderHtml body
105+ in case writerTemplate opts of
106+ Nothing -> renderHtml body
107+ Just tpl -> renderTemplate' tpl $
108+ defField "body" (renderHtml body) context
108109
109110-- | Convert Pandoc document to Html structure.
110111writeHtml :: WriterOptions -> Pandoc -> Html
111112writeHtml opts d =
112113 let (body, context) = evalState (pandocToHtml opts d) defaultWriterState
113− in if writerStandalone opts
114− then inTemplate opts context body
115− else body
114+ in case writerTemplate opts of
115+ Nothing -> body
116+ Just tpl -> renderTemplate' tpl $
117+ defField "body" (renderHtml body) context
116118
117119-- result is (title, authors, date, toc, body, new variables)
118120pandocToHtml :: WriterOptions
@@ -194,14 +196,6 @@ pandocToHtml opts (Pandoc meta blocks) = do
194196 metadata
195197 return (thebody, context)
196198
197−inTemplate :: TemplateTarget a
198− => WriterOptions
199− -> Value
200− -> Html
201− -> a
202−inTemplate opts context body = renderTemplate' (writerTemplate opts)
203− $ defField "body" (renderHtml body) context
204−
205199-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix
206200prefixedId :: WriterOptions -> String -> Attribute
207201prefixedId opts s =
src/Text/Pandoc/Writers/Haddock.hs+3−3
@@ -73,9 +73,9 @@ pandocToHaddock opts (Pandoc meta blocks) = do
7373 meta
7474 let context = defField "body" main
7575 $ metadata
76− if writerStandalone opts
77− then return $ renderTemplate' (writerTemplate opts) context
78− else return main
76+ case writerTemplate opts of
77+ Nothing -> return main
78+ Just tpl -> return $ renderTemplate' tpl context
7979
8080-- | Return haddock representation of notes.
8181notesToHaddock :: WriterOptions -> [[Block]] -> State WriterState Doc
src/Text/Pandoc/Writers/ICML.hs+3−3
@@ -141,9 +141,9 @@ writeICML opts (Pandoc meta blocks) = do
141141 $ defField "parStyles" (render' $ parStylesToDoc st)
142142 $ defField "hyperlinks" (render' $ hyperlinksToDoc $ links st)
143143 $ metadata
144− return $ if writerStandalone opts
145− then renderTemplate' (writerTemplate opts) context
146− else main
144+ return $ case writerTemplate opts of
145+ Nothing -> main
146+ Just tpl -> renderTemplate' tpl context
147147
148148-- | Auxilary functions for parStylesToDoc and charStylesToDoc.
149149contains :: String -> (String, (String, String)) -> [(String, String)]
src/Text/Pandoc/Writers/LaTeX.hs+4−4
@@ -109,7 +109,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
109109 let isInternalLink (Link _ _ ('#':xs,_)) = [xs]
110110 isInternalLink _ = []
111111 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
112− let template = writerTemplate options
112+ let template = maybe "" id $ writerTemplate options
113113 -- set stBook depending on documentclass
114114 let colwidth = if writerWrapText options == WrapAuto
115115 then Just $ writerColumns options
@@ -246,9 +246,9 @@ pandocToLaTeX options (Pandoc meta blocks) = do
246246 Just "rtl" -> True
247247 _ -> False)
248248 $ context
249− return $ if writerStandalone options
250− then renderTemplate' template context'
251− else main
249+ return $ case writerTemplate options of
250+ Nothing -> main
251+ Just tpl -> renderTemplate' tpl context'
252252
253253-- | Convert Elements to LaTeX
254254elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
src/Text/Pandoc/Writers/Man.hs+3−3
@@ -88,9 +88,9 @@ pandocToMan opts (Pandoc meta blocks) = do
8888 $ defField "hyphenate" True
8989 $ defField "pandoc-version" pandocVersion
9090 $ metadata
91− if writerStandalone opts
92− then return $ renderTemplate' (writerTemplate opts) context
93− else return main
91+ case writerTemplate opts of
92+ Nothing -> return main
93+ Just tpl -> return $ renderTemplate' tpl context
9494
9595-- | Return man representation of notes.
9696notesToMan :: WriterOptions -> [[Block]] -> State WriterState Doc
src/Text/Pandoc/Writers/Markdown.hs+14−14
@@ -184,17 +184,17 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
184184 let title' = maybe empty text $ getField "title" metadata
185185 let authors' = maybe [] (map text) $ getField "author" metadata
186186 let date' = maybe empty text $ getField "date" metadata
187− let titleblock = case writerStandalone opts of
188− True | isPlain ->
189− plainTitleBlock title' authors' date'
190− | isEnabled Ext_yaml_metadata_block opts ->
191− yamlMetadataBlock metadata
192− | isEnabled Ext_pandoc_title_block opts ->
193− pandocTitleBlock title' authors' date'
194− | isEnabled Ext_mmd_title_block opts ->
195− mmdTitleBlock metadata
196− | otherwise -> empty
197− False -> empty
187+ let titleblock = case writerTemplate opts of
188+ Just _ | isPlain ->
189+ plainTitleBlock title' authors' date'
190+ | isEnabled Ext_yaml_metadata_block opts ->
191+ yamlMetadataBlock metadata
192+ | isEnabled Ext_pandoc_title_block opts ->
193+ pandocTitleBlock title' authors' date'
194+ | isEnabled Ext_mmd_title_block opts ->
195+ mmdTitleBlock metadata
196+ | otherwise -> empty
197+ Nothing -> empty
198198 let headerBlocks = filter isHeaderBlock blocks
199199 let toc = if writerTableOfContents opts
200200 then tableOfContents opts headerBlocks
@@ -216,9 +216,9 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
216216 then id
217217 else defField "titleblock" (render' titleblock))
218218 $ metadata
219− if writerStandalone opts
220− then return $ renderTemplate' (writerTemplate opts) context
221− else return main
219+ case writerTemplate opts of
220+ Nothing -> return main
221+ Just tpl -> return $ renderTemplate' tpl context
222222
223223-- | Return markdown representation of reference key table.
224224refsToMarkdown :: WriterOptions -> Refs -> MD Doc
src/Text/Pandoc/Writers/MediaWiki.hs+3−3
@@ -79,9 +79,9 @@ pandocToMediaWiki (Pandoc meta blocks) = do
7979 let main = body ++ notes
8080 let context = defField "body" main
8181 $ defField "toc" (writerTableOfContents opts) metadata
82− return $ if writerStandalone opts
83− then renderTemplate' (writerTemplate opts) context
84− else main
82+ return $ case writerTemplate opts of
83+ Nothing -> main
84+ Just tpl -> renderTemplate' tpl context
8585
8686-- | Escape special characters for MediaWiki.
8787escapeString :: String -> String
src/Text/Pandoc/Writers/Native.hs+3−7
@@ -27,10 +27,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2727 Portability : portable
2828
2929Conversion of a 'Pandoc' document to a string representation.
30−
31−Note: If @writerStandalone@ is @False@, only the document body
32−is represented; otherwise, the full 'Pandoc' document, including the
33−metadata.
3430-}
3531module Text.Pandoc.Writers.Native ( writeNative )
3632where
@@ -75,8 +71,8 @@ writeNative opts (Pandoc meta blocks) =
7571 let colwidth = if writerWrapText opts == WrapAuto
7672 then Just $ writerColumns opts
7773 else Nothing
78− withHead = if writerStandalone opts
79− then \bs -> text ("Pandoc (" ++ show meta ++ ")") $$
74+ withHead = case writerTemplate opts of
75+ Just _ -> \bs -> text ("Pandoc (" ++ show meta ++ ")") $$
8076 bs $$ cr
81− else id
77+ Nothing -> id
8278 in render colwidth $ withHead $ prettyList $ map prettyBlock blocks
src/Text/Pandoc/Writers/OPML.hs+3−3
@@ -56,9 +56,9 @@ writeOPML opts (Pandoc meta blocks) =
5656 meta'
5757 main = render colwidth $ vcat (map (elementToOPML opts) elements)
5858 context = defField "body" main metadata
59− in if writerStandalone opts
60− then renderTemplate' (writerTemplate opts) context
61− else main
59+ in case writerTemplate opts of
60+ Nothing -> main
61+ Just tpl -> renderTemplate' tpl context
6262
6363writeHtmlInlines :: [Inline] -> String
6464writeHtmlInlines ils = trim $ writeHtmlString def
src/Text/Pandoc/Writers/OpenDocument.hs+3−3
@@ -196,9 +196,9 @@ writeOpenDocument opts (Pandoc meta blocks) =
196196 context = defField "body" body
197197 $ defField "automatic-styles" (render' automaticStyles)
198198 $ metadata
199− in if writerStandalone opts
200− then renderTemplate' (writerTemplate opts) context
201− else body
199+ in case writerTemplate opts of
200+ Nothing -> body
201+ Just tpl -> renderTemplate' tpl context
202202
203203withParagraphStyle :: WriterOptions -> String -> [Block] -> State WriterState Doc
204204withParagraphStyle o s (b:bs)
src/Text/Pandoc/Writers/Org.hs+3−3
@@ -78,9 +78,9 @@ pandocToOrg (Pandoc meta blocks) = do
7878 let context = defField "body" main
7979 $ defField "math" hasMath
8080 $ metadata
81− if writerStandalone opts
82− then return $ renderTemplate' (writerTemplate opts) context
83− else return main
81+ case writerTemplate opts of
82+ Nothing -> return main
83+ Just tpl -> return $ renderTemplate' tpl context
8484
8585-- | Return Org representation of notes.
8686notesToOrg :: [[Block]] -> State WriterState Doc
src/Text/Pandoc/Writers/RST.hs+6−6
@@ -81,9 +81,9 @@ pandocToRST (Pandoc meta blocks) = do
8181 (fmap (render colwidth) . blockListToRST)
8282 (fmap (trimr . render colwidth) . inlineListToRST)
8383 $ deleteMeta "title" $ deleteMeta "subtitle" meta
84− body <- blockListToRST' True $ if writerStandalone opts
85− then normalizeHeadings 1 blocks
86− else blocks
84+ body <- blockListToRST' True $ case writerTemplate opts of
85+ Just _ -> normalizeHeadings 1 blocks
86+ Nothing -> blocks
8787 notes <- liftM (reverse . stNotes) get >>= notesToRST
8888 -- note that the notes may contain refs, so we do them first
8989 refs <- liftM (reverse . stLinks) get >>= refsToRST
@@ -99,9 +99,9 @@ pandocToRST (Pandoc meta blocks) = do
9999 $ defField "math" hasMath
100100 $ defField "rawtex" rawTeX
101101 $ metadata
102− if writerStandalone opts
103− then return $ renderTemplate' (writerTemplate opts) context
104− else return main
102+ case writerTemplate opts of
103+ Nothing -> return main
104+ Just tpl -> return $ renderTemplate' tpl context
105105 where
106106 normalizeHeadings lev (Header l a i:bs) =
107107 Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
src/Text/Pandoc/Writers/RTF.hs+5−5
@@ -107,11 +107,11 @@ writeRTF options (Pandoc meta@(Meta metamap) blocks) =
107107 (tableOfContents $ filter isTOCHeader blocks)
108108 else id)
109109 $ metadata
110− in if writerStandalone options
111− then renderTemplate' (writerTemplate options) context
112− else case reverse body of
113− ('\n':_) -> body
114− _ -> body ++ "\n"
110+ in case writerTemplate options of
111+ Just tpl -> renderTemplate' tpl context
112+ Nothing -> case reverse body of
113+ ('\n':_) -> body
114+ _ -> body ++ "\n"
115115
116116-- | Construct table of contents from list of header blocks.
117117tableOfContents :: [Block] -> String
src/Text/Pandoc/Writers/Shared.hs+2−1
@@ -49,6 +49,7 @@ import Data.Aeson (FromJSON(..), fromJSON, ToJSON (..), Value(Object), Result(..
4949import Text.Pandoc.UTF8 (toStringLazy)
5050import qualified Data.Traversable as Traversable
5151import Data.List ( groupBy )
52+import Data.Maybe ( isJust )
5253
5354-- | Create JSON value for template from a 'Meta' and an association list
5455-- of variables, specified at the command line or in the writer.
@@ -62,7 +63,7 @@ metaToJSON :: Monad m
6263 -> Meta
6364 -> m Value
6465metaToJSON opts blockWriter inlineWriter (Meta metamap)
65− | writerStandalone opts = do
66+ | isJust (writerTemplate opts) = do
6667 let baseContext = foldl (\acc (x,y) -> setField x y acc) (Object H.empty)
6768 $ writerVariables opts
6869 renderedMap <- Traversable.mapM
src/Text/Pandoc/Writers/TEI.hs+3−3
@@ -78,9 +78,9 @@ writeTEI opts (Pandoc meta blocks) =
7878 MathML _ -> True
7979 _ -> False)
8080 $ metadata
81− in if writerStandalone opts
82− then renderTemplate' (writerTemplate opts) context
83− else main
81+ in case writerTemplate opts of
82+ Nothing -> main
83+ Just tpl -> renderTemplate' tpl context
8484
8585-- | Convert an Element to TEI.
8686elementToTEI :: WriterOptions -> Int -> Element -> Doc
src/Text/Pandoc/Writers/Texinfo.hs+3−3
@@ -93,9 +93,9 @@ pandocToTexinfo options (Pandoc meta blocks) = do
9393 $ defField "superscript" (stSuperscript st)
9494 $ defField "strikeout" (stStrikeout st)
9595 $ metadata
96− if writerStandalone options
97− then return $ renderTemplate' (writerTemplate options) context
98− else return body
96+ case writerTemplate options of
97+ Nothing -> return body
98+ Just tpl -> return $ renderTemplate' tpl context
9999
100100-- | Escape things as needed for Texinfo.
101101stringToTexinfo :: String -> String
src/Text/Pandoc/Writers/Textile.hs+3−3
@@ -65,9 +65,9 @@ pandocToTextile opts (Pandoc meta blocks) = do
6565 notes <- liftM (unlines . reverse . stNotes) get
6666 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
6767 let context = defField "body" main metadata
68− if writerStandalone opts
69− then return $ renderTemplate' (writerTemplate opts) context
70− else return main
68+ case writerTemplate opts of
69+ Nothing -> return main
70+ Just tpl -> return $ renderTemplate' tpl context
7171
7272withUseTags :: State WriterState a -> State WriterState a
7373withUseTags action = do
src/Text/Pandoc/Writers/ZimWiki.hs+4−4
@@ -32,7 +32,7 @@ http://zim-wiki.org/manual/Help/Wiki_Syntax.html
3232
3333module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
3434import Text.Pandoc.Definition
35−import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerStandalone, writerTemplate, writerWrapText), WrapOption(..) )
35+import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerTemplate, writerWrapText), WrapOption(..) )
3636import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting, trimr
3737 , substitute )
3838import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
@@ -71,9 +71,9 @@ pandocToZimWiki opts (Pandoc meta blocks) = do
7171 let context = defField "body" main
7272 $ defField "toc" (writerTableOfContents opts)
7373 $ metadata
74− if writerStandalone opts
75− then return $ renderTemplate' (writerTemplate opts) context
76− else return main
74+ case writerTemplate opts of
75+ Just tpl -> return $ renderTemplate' tpl context
76+ Nothing -> return main
7777
7878-- | Escape special characters for ZimWiki.
7979escapeString :: String -> String
tests/Tests/Helpers.hs+3−3
@@ -57,11 +57,11 @@ class ToString a where
5757 toString :: a -> String
5858
5959instance ToString Pandoc where
60− toString d = writeNative def{ writerStandalone = s } $ toPandoc d
60+ toString d = writeNative def{ writerTemplate = s } $ toPandoc d
6161 where s = case d of
6262 (Pandoc (Meta m) _)
63− | M.null m -> False
64− | otherwise -> True
63+ | M.null m -> Nothing
64+ | otherwise -> Just "" -- need this to get meta output
6565
6666instance ToString Blocks where
6767 toString = writeNative def . toPandoc
tests/Tests/Readers/Docx.hs+3−3
@@ -26,11 +26,11 @@ noNorm :: Pandoc -> NoNormPandoc
2626noNorm = NoNormPandoc
2727
2828instance ToString NoNormPandoc where
29− toString d = writeNative def{ writerStandalone = s } $ toPandoc d
29+ toString d = writeNative def{ writerTemplate = s } $ toPandoc d
3030 where s = case d of
3131 NoNormPandoc (Pandoc (Meta m) _)
32− | M.null m -> False
33− | otherwise -> True
32+ | M.null m -> Nothing
33+ | otherwise -> Just "" -- need this to get meta output
3434
3535instance ToPandoc NoNormPandoc where
3636 toPandoc = unNoNorm
tests/Tests/Readers/Odt.hs+3−3
@@ -41,11 +41,11 @@ newtype NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
4141 deriving ( Show )
4242
4343instance ToString NoNormPandoc where
44− toString d = writeNative def{ writerStandalone = s } $ toPandoc d
44+ toString d = writeNative def{ writerTemplate = s } $ toPandoc d
4545 where s = case d of
4646 NoNormPandoc (Pandoc (Meta m) _)
47− | M.null m -> False
48− | otherwise -> True
47+ | M.null m -> Nothing
48+ | otherwise -> Just "" -- need this for Meta output
4949
5050instance ToPandoc NoNormPandoc where
5151 toPandoc = unNoNorm
tests/Tests/Writers/Native.hs+1−1
@@ -8,7 +8,7 @@ import Text.Pandoc.Arbitrary()
88
99p_write_rt :: Pandoc -> Bool
1010p_write_rt d =
11− read (writeNative def{ writerStandalone = True } d) == d
11+ read (writeNative def{ writerTemplate = Just "" } d) == d
1212
1313p_write_blocks_rt :: [Block] -> Bool
1414p_write_blocks_rt bs = length bs > 20 ||
tests/Tests/Writers/RST.hs+2−4
@@ -47,8 +47,7 @@ tests = [ testGroup "rubrics"
4747 [ "foo"
4848 , "==="]
4949 -- note: heading normalization is only done in standalone mode
50− , test (writeRST def{ writerStandalone = True,
51− writerTemplate = "$body$\n" } . toPandoc)
50+ , test (writeRST def{ writerTemplate = Just "$body$\n" } . toPandoc)
5251 "heading levels" $
5352 header 1 (text "Header 1") <>
5453 header 3 (text "Header 2") <>
@@ -78,8 +77,7 @@ tests = [ testGroup "rubrics"
7877 , ""
7978 , "Header 2"
8079 , "--------"]
81− , test (writeRST def{ writerStandalone = True,
82− writerTemplate = "$body$\n" } . toPandoc)
80+ , test (writeRST def{ writerTemplate = Just "$body$\n" } . toPandoc)
8381 "minimal heading levels" $
8482 header 2 (text "Header 1") <>
8583 header 3 (text "Header 2") <>