git.iko.soy/typeable/pandoc
on master help sign in
Options: Removed writerStandalone, made writerTemplate a Maybe.
fb8a254John MacFarlane
pandoc.hs+4−5
@@ -1292,18 +1292,18 @@ convertWithOpts opts args = do
1292 let standalone' = standalone || not (isTextFormat format) || pdfOutput
1292 let standalone' = standalone || not (isTextFormat format) || pdfOutput
1293
1293
1294 templ <- case templatePath of
1294 templ <- case templatePath of
1295− _ | not standalone' -> return ""
1295+ _ | not standalone' -> return Nothing
1296 Nothing -> do
1296 Nothing -> do
1297 deftemp <- getDefaultTemplate datadir format
1297 deftemp <- getDefaultTemplate datadir format
1298 case deftemp of
1298 case deftemp of
1299 Left e -> throwIO e
1299 Left e -> throwIO e
1300− Right t -> return t
1300+ Right t -> return (Just t)
1301 Just tp -> do
1301 Just tp -> do
1302 -- strip off extensions
1302 -- strip off extensions
1303 let tp' = case takeExtension tp of
1303 let tp' = case takeExtension tp of
1304 "" -> tp <.> format
1304 "" -> tp <.> format
1305 _ -> tp
1305 _ -> tp
1306− E.catch (UTF8.readFile tp')
1306+ Just <$> E.catch (UTF8.readFile tp')
1307 (\e -> if isDoesNotExistError e
1307 (\e -> if isDoesNotExistError e
1308 then E.catch
1308 then E.catch
1309 (readDataFileUTF8 datadir
1309 (readDataFileUTF8 datadir
@@ -1416,8 +1416,7 @@ convertWithOpts opts args = do
1416 _ -> do pairs <- mapM (\s -> sourceToDoc [s]) sources
1416 _ -> do pairs <- mapM (\s -> sourceToDoc [s]) sources
1417 return (mconcat $ map fst pairs, mconcat $ map snd pairs)
1417 return (mconcat $ map fst pairs, mconcat $ map snd pairs)
1418
1418
1419− let writerOptions = def { writerStandalone = standalone',
1420− writerTemplate = templ,
1419+ let writerOptions = def { writerTemplate = templ,
1421 writerVariables = variables'',
1420 writerVariables = variables'',
1422 writerTabStop = tabStop,
1421 writerTabStop = tabStop,
1423 writerTableOfContents = toc,
1422 writerTableOfContents = toc,
src/Text/Pandoc/Options.hs+2−4
@@ -356,8 +356,7 @@ data ReferenceLocation = EndOfBlock -- ^ End of block
356
356
357-- | Options for writers
357-- | Options for writers
358data WriterOptions = WriterOptions
358data 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
361 , writerVariables :: [(String, String)] -- ^ Variables to set in template
360 , writerVariables :: [(String, String)] -- ^ Variables to set in template
362 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
361 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
363 , writerTableOfContents :: Bool -- ^ Include table of contents
362 , writerTableOfContents :: Bool -- ^ Include table of contents
@@ -405,8 +404,7 @@ data WriterOptions = WriterOptions
405 } deriving (Show, Data, Typeable, Generic)
404 } deriving (Show, Data, Typeable, Generic)
406
405
407instance Default WriterOptions where
406instance Default WriterOptions where
408− def = WriterOptions { writerStandalone = False
409− , writerTemplate = ""
407+ def = WriterOptions { writerTemplate = Nothing
410 , writerVariables = []
408 , writerVariables = []
411 , writerTabStop = 4
409 , writerTabStop = 4
412 , writerTableOfContents = False
410 , writerTableOfContents = False
src/Text/Pandoc/Writers/AsciiDoc.hs+5−4
@@ -92,12 +92,13 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
92 let main = render colwidth body
92 let main = render colwidth body
93 let context = defField "body" main
93 let context = defField "body" main
94 $ defField "toc"
94 $ defField "toc"
95− (writerTableOfContents opts && writerStandalone opts)
95+ (writerTableOfContents opts &&
96+ writerTemplate opts /= Nothing)
96 $ defField "titleblock" titleblock
97 $ defField "titleblock" titleblock
97 $ metadata'
98 $ metadata'
98− if writerStandalone opts
99+ case writerTemplate opts of
100+ Nothing -> return main
99− then return $ renderTemplate' (writerTemplate opts) context
101+ Just tpl -> return $ renderTemplate' tpl context
100− else return main
101
102
102-- | Escape special characters for AsciiDoc.
103-- | Escape special characters for AsciiDoc.
103escapeString :: String -> String
104escapeString :: String -> String
src/Text/Pandoc/Writers/CommonMark.hs+3−3
@@ -56,9 +56,9 @@ writeCommonMark opts (Pandoc meta blocks) = rendered
56 (inlinesToCommonMark opts)
56 (inlinesToCommonMark opts)
57 meta
57 meta
58 context = defField "body" main $ metadata
58 context = defField "body" main $ metadata
59− rendered = if writerStandalone opts
59+ rendered = case writerTemplate opts of
60+ Nothing -> main
60− then renderTemplate' (writerTemplate opts) context
61+ Just tpl -> renderTemplate' tpl context
61− else main
62
62
63processNotes :: Inline -> State [[Block]] Inline
63processNotes :: Inline -> State [[Block]] Inline
64processNotes (Note bs) = do
64processNotes (Note bs) = do
src/Text/Pandoc/Writers/ConTeXt.hs+3−3
@@ -98,9 +98,9 @@ pandocToConTeXt options (Pandoc meta blocks) = do
98 getField "lang" context)
98 getField "lang" context)
99 $ defField "context-dir" (toContextDir $ getField "dir" context)
99 $ defField "context-dir" (toContextDir $ getField "dir" context)
100 $ context
100 $ context
101− return $ if writerStandalone options
101+ return $ case writerTemplate options of
102+ Nothing -> main
102− then renderTemplate' (writerTemplate options) context'
103+ Just tpl -> renderTemplate' tpl context'
103− else main
104
104
105toContextDir :: Maybe String -> String
105toContextDir :: Maybe String -> String
106toContextDir (Just "rtl") = "r2l"
106toContextDir (Just "rtl") = "r2l"
src/Text/Pandoc/Writers/Custom.hs+3−5
@@ -202,11 +202,9 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
202 Lua.close lua
202 Lua.close lua
203 setForeignEncoding enc
203 setForeignEncoding enc
204 let body = rendered
204 let body = rendered
205− if writerStandalone opts
205+ case writerTemplate opts of
206− then do
206+ Nothing -> return body
207− let context' = setField "body" body context
207+ Just tpl -> return $ renderTemplate' tpl $ setField "body" body context
208− return $ renderTemplate' (writerTemplate opts) context'
209− else return body
210
208
211docToCustom :: LuaState -> WriterOptions -> Pandoc -> IO String
209docToCustom :: LuaState -> WriterOptions -> Pandoc -> IO String
212docToCustom lua opts (Pandoc (Meta metamap) blocks) = do
210docToCustom lua opts (Pandoc (Meta metamap) blocks) = do
src/Text/Pandoc/Writers/Docbook.hs+5−4
@@ -80,7 +80,8 @@ writeDocbook opts (Pandoc meta blocks) =
80 then Just $ writerColumns opts
80 then Just $ writerColumns opts
81 else Nothing
81 else Nothing
82 render' = render colwidth
82 render' = render colwidth
83− opts' = if ("/book>" `isSuffixOf` (trimr $ writerTemplate opts) &&
83+ opts' = if (maybe False (("/book>" `isSuffixOf`) . trimr)
84+ (writerTemplate opts) &&
84 TopLevelDefault == writerTopLevelDivision opts)
85 TopLevelDefault == writerTopLevelDivision opts)
85 then opts{ writerTopLevelDivision = TopLevelChapter }
86 then opts{ writerTopLevelDivision = TopLevelChapter }
86 else opts
87 else opts
@@ -103,9 +104,9 @@ writeDocbook opts (Pandoc meta blocks) =
103 MathML _ -> True
104 MathML _ -> True
104 _ -> False)
105 _ -> False)
105 $ metadata
106 $ metadata
106− in if writerStandalone opts
107+ in case writerTemplate opts of
108+ Nothing -> main
107− then renderTemplate' (writerTemplate opts) context
109+ Just tpl -> renderTemplate' tpl context
108− else main
109
110
110-- | Convert an Element to Docbook.
111-- | Convert an Element to Docbook.
111elementToDocbook :: WriterOptions -> Int -> Element -> Doc
112elementToDocbook :: WriterOptions -> Int -> Element -> Doc
src/Text/Pandoc/Writers/DokuWiki.hs+3−4
@@ -42,7 +42,6 @@ module Text.Pandoc.Writers.DokuWiki ( writeDokuWiki ) where
42import Text.Pandoc.Definition
42import Text.Pandoc.Definition
43import Text.Pandoc.Options ( WriterOptions(
43import Text.Pandoc.Options ( WriterOptions(
44 writerTableOfContents
44 writerTableOfContents
45− , writerStandalone
46 , writerTemplate
45 , writerTemplate
47 , writerWrapText), WrapOption(..) )
46 , writerWrapText), WrapOption(..) )
48import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting
47import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting
@@ -102,9 +101,9 @@ pandocToDokuWiki opts (Pandoc meta blocks) = do
102 let context = defField "body" main
101 let context = defField "body" main
103 $ defField "toc" (writerTableOfContents opts)
102 $ defField "toc" (writerTableOfContents opts)
104 $ metadata
103 $ metadata
105− if writerStandalone opts
104+ case writerTemplate opts of
105+ Nothing -> return main
106− then return $ renderTemplate' (writerTemplate opts) context
106+ Just tpl -> return $ renderTemplate' tpl context
107− else return main
108
107
109-- | Escape special characters for DokuWiki.
108-- | Escape special characters for DokuWiki.
110escapeString :: String -> String
109escapeString :: String -> String
src/Text/Pandoc/Writers/EPUB.hs−1
@@ -342,7 +342,6 @@ writeEPUB opts doc@(Pandoc meta _) = do
342 : ("css", "stylesheet.css")
342 : ("css", "stylesheet.css")
343 : writerVariables opts
343 : writerVariables opts
344 let opts' = opts{ writerEmailObfuscation = NoObfuscation
344 let opts' = opts{ writerEmailObfuscation = NoObfuscation
345− , writerStandalone = True
346 , writerSectionDivs = True
345 , writerSectionDivs = True
347 , writerHtml5 = epub3
346 , writerHtml5 = epub3
348 , writerVariables = vars
347 , writerVariables = vars
src/Text/Pandoc/Writers/FB2.hs+1−1
@@ -77,7 +77,7 @@ writeFB2 :: WriterOptions -- ^ conversion options
77 -> Pandoc -- ^ document to convert
77 -> Pandoc -- ^ document to convert
78 -> IO String -- ^ FictionBook2 document (not encoded yet)
78 -> IO String -- ^ FictionBook2 document (not encoded yet)
79writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
79writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
80− modify (\s -> s { writerOptions = opts { writerStandalone = True } })
80+ modify (\s -> s { writerOptions = opts })
81 desc <- description meta
81 desc <- description meta
82 fp <- frontpage meta
82 fp <- frontpage meta
83 secs <- renderSections 1 blocks
83 secs <- renderSections 1 blocks
src/Text/Pandoc/Writers/HTML.hs+8−14
@@ -102,17 +102,19 @@ nl opts = if writerWrapText opts == WrapNone
102writeHtmlString :: WriterOptions -> Pandoc -> String
102writeHtmlString :: WriterOptions -> Pandoc -> String
103writeHtmlString opts d =
103writeHtmlString opts d =
104 let (body, context) = evalState (pandocToHtml opts d) defaultWriterState
104 let (body, context) = evalState (pandocToHtml opts d) defaultWriterState
105− in if writerStandalone opts
105+ in case writerTemplate opts of
106− then inTemplate opts context body
106+ Nothing -> renderHtml body
107− else renderHtml body
107+ Just tpl -> renderTemplate' tpl $
108+ defField "body" (renderHtml body) context
108
109
109-- | Convert Pandoc document to Html structure.
110-- | Convert Pandoc document to Html structure.
110writeHtml :: WriterOptions -> Pandoc -> Html
111writeHtml :: WriterOptions -> Pandoc -> Html
111writeHtml opts d =
112writeHtml opts d =
112 let (body, context) = evalState (pandocToHtml opts d) defaultWriterState
113 let (body, context) = evalState (pandocToHtml opts d) defaultWriterState
113− in if writerStandalone opts
114+ in case writerTemplate opts of
114− then inTemplate opts context body
115+ Nothing -> body
115− else body
116+ Just tpl -> renderTemplate' tpl $
117+ defField "body" (renderHtml body) context
116
118
117-- result is (title, authors, date, toc, body, new variables)
119-- result is (title, authors, date, toc, body, new variables)
118pandocToHtml :: WriterOptions
120pandocToHtml :: WriterOptions
@@ -194,14 +196,6 @@ pandocToHtml opts (Pandoc meta blocks) = do
194 metadata
196 metadata
195 return (thebody, context)
197 return (thebody, context)
196
198
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−
205-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix
199-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix
206prefixedId :: WriterOptions -> String -> Attribute
200prefixedId :: WriterOptions -> String -> Attribute
207prefixedId opts s =
201prefixedId opts s =
src/Text/Pandoc/Writers/Haddock.hs+3−3
@@ -73,9 +73,9 @@ pandocToHaddock opts (Pandoc meta blocks) = do
73 meta
73 meta
74 let context = defField "body" main
74 let context = defField "body" main
75 $ metadata
75 $ metadata
76− if writerStandalone opts
76+ case writerTemplate opts of
77+ Nothing -> return main
77− then return $ renderTemplate' (writerTemplate opts) context
78+ Just tpl -> return $ renderTemplate' tpl context
78− else return main
79
79
80-- | Return haddock representation of notes.
80-- | Return haddock representation of notes.
81notesToHaddock :: WriterOptions -> [[Block]] -> State WriterState Doc
81notesToHaddock :: WriterOptions -> [[Block]] -> State WriterState Doc
src/Text/Pandoc/Writers/ICML.hs+3−3
@@ -141,9 +141,9 @@ writeICML opts (Pandoc meta blocks) = do
141 $ defField "parStyles" (render' $ parStylesToDoc st)
141 $ defField "parStyles" (render' $ parStylesToDoc st)
142 $ defField "hyperlinks" (render' $ hyperlinksToDoc $ links st)
142 $ defField "hyperlinks" (render' $ hyperlinksToDoc $ links st)
143 $ metadata
143 $ metadata
144− return $ if writerStandalone opts
144+ return $ case writerTemplate opts of
145+ Nothing -> main
145− then renderTemplate' (writerTemplate opts) context
146+ Just tpl -> renderTemplate' tpl context
146− else main
147
147
148-- | Auxilary functions for parStylesToDoc and charStylesToDoc.
148-- | Auxilary functions for parStylesToDoc and charStylesToDoc.
149contains :: String -> (String, (String, String)) -> [(String, String)]
149contains :: String -> (String, (String, String)) -> [(String, String)]
src/Text/Pandoc/Writers/LaTeX.hs+4−4
@@ -109,7 +109,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
109 let isInternalLink (Link _ _ ('#':xs,_)) = [xs]
109 let isInternalLink (Link _ _ ('#':xs,_)) = [xs]
110 isInternalLink _ = []
110 isInternalLink _ = []
111 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
111 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
112− let template = writerTemplate options
112+ let template = maybe "" id $ writerTemplate options
113 -- set stBook depending on documentclass
113 -- set stBook depending on documentclass
114 let colwidth = if writerWrapText options == WrapAuto
114 let colwidth = if writerWrapText options == WrapAuto
115 then Just $ writerColumns options
115 then Just $ writerColumns options
@@ -246,9 +246,9 @@ pandocToLaTeX options (Pandoc meta blocks) = do
246 Just "rtl" -> True
246 Just "rtl" -> True
247 _ -> False)
247 _ -> False)
248 $ context
248 $ context
249− return $ if writerStandalone options
249+ return $ case writerTemplate options of
250+ Nothing -> main
250− then renderTemplate' template context'
251+ Just tpl -> renderTemplate' tpl context'
251− else main
252
252
253-- | Convert Elements to LaTeX
253-- | Convert Elements to LaTeX
254elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
254elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
src/Text/Pandoc/Writers/Man.hs+3−3
@@ -88,9 +88,9 @@ pandocToMan opts (Pandoc meta blocks) = do
88 $ defField "hyphenate" True
88 $ defField "hyphenate" True
89 $ defField "pandoc-version" pandocVersion
89 $ defField "pandoc-version" pandocVersion
90 $ metadata
90 $ metadata
91− if writerStandalone opts
91+ case writerTemplate opts of
92+ Nothing -> return main
92− then return $ renderTemplate' (writerTemplate opts) context
93+ Just tpl -> return $ renderTemplate' tpl context
93− else return main
94
94
95-- | Return man representation of notes.
95-- | Return man representation of notes.
96notesToMan :: WriterOptions -> [[Block]] -> State WriterState Doc
96notesToMan :: WriterOptions -> [[Block]] -> State WriterState Doc
src/Text/Pandoc/Writers/Markdown.hs+14−14
@@ -184,17 +184,17 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
184 let title' = maybe empty text $ getField "title" metadata
184 let title' = maybe empty text $ getField "title" metadata
185 let authors' = maybe [] (map text) $ getField "author" metadata
185 let authors' = maybe [] (map text) $ getField "author" metadata
186 let date' = maybe empty text $ getField "date" metadata
186 let date' = maybe empty text $ getField "date" metadata
187− let titleblock = case writerStandalone opts of
187+ let titleblock = case writerTemplate opts of
188− True | isPlain ->
188+ Just _ | isPlain ->
189− plainTitleBlock title' authors' date'
189+ plainTitleBlock title' authors' date'
190− | isEnabled Ext_yaml_metadata_block opts ->
190+ | isEnabled Ext_yaml_metadata_block opts ->
191− yamlMetadataBlock metadata
191+ yamlMetadataBlock metadata
192− | isEnabled Ext_pandoc_title_block opts ->
192+ | isEnabled Ext_pandoc_title_block opts ->
193− pandocTitleBlock title' authors' date'
193+ pandocTitleBlock title' authors' date'
194− | isEnabled Ext_mmd_title_block opts ->
194+ | isEnabled Ext_mmd_title_block opts ->
195− mmdTitleBlock metadata
195+ mmdTitleBlock metadata
196− | otherwise -> empty
196+ | otherwise -> empty
197− False -> empty
197+ Nothing -> empty
198 let headerBlocks = filter isHeaderBlock blocks
198 let headerBlocks = filter isHeaderBlock blocks
199 let toc = if writerTableOfContents opts
199 let toc = if writerTableOfContents opts
200 then tableOfContents opts headerBlocks
200 then tableOfContents opts headerBlocks
@@ -216,9 +216,9 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
216 then id
216 then id
217 else defField "titleblock" (render' titleblock))
217 else defField "titleblock" (render' titleblock))
218 $ metadata
218 $ metadata
219− if writerStandalone opts
219+ case writerTemplate opts of
220+ Nothing -> return main
220− then return $ renderTemplate' (writerTemplate opts) context
221+ Just tpl -> return $ renderTemplate' tpl context
221− else return main
222
222
223-- | Return markdown representation of reference key table.
223-- | Return markdown representation of reference key table.
224refsToMarkdown :: WriterOptions -> Refs -> MD Doc
224refsToMarkdown :: WriterOptions -> Refs -> MD Doc
src/Text/Pandoc/Writers/MediaWiki.hs+3−3
@@ -79,9 +79,9 @@ pandocToMediaWiki (Pandoc meta blocks) = do
79 let main = body ++ notes
79 let main = body ++ notes
80 let context = defField "body" main
80 let context = defField "body" main
81 $ defField "toc" (writerTableOfContents opts) metadata
81 $ defField "toc" (writerTableOfContents opts) metadata
82− return $ if writerStandalone opts
82+ return $ case writerTemplate opts of
83+ Nothing -> main
83− then renderTemplate' (writerTemplate opts) context
84+ Just tpl -> renderTemplate' tpl context
84− else main
85
85
86-- | Escape special characters for MediaWiki.
86-- | Escape special characters for MediaWiki.
87escapeString :: String -> String
87escapeString :: 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
27 Portability : portable
27 Portability : portable
28
28
29Conversion of a 'Pandoc' document to a string representation.
29Conversion 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.
34-}
30-}
35module Text.Pandoc.Writers.Native ( writeNative )
31module Text.Pandoc.Writers.Native ( writeNative )
36where
32where
@@ -75,8 +71,8 @@ writeNative opts (Pandoc meta blocks) =
75 let colwidth = if writerWrapText opts == WrapAuto
71 let colwidth = if writerWrapText opts == WrapAuto
76 then Just $ writerColumns opts
72 then Just $ writerColumns opts
77 else Nothing
73 else Nothing
78− withHead = if writerStandalone opts
74+ withHead = case writerTemplate opts of
79− then \bs -> text ("Pandoc (" ++ show meta ++ ")") $$
75+ Just _ -> \bs -> text ("Pandoc (" ++ show meta ++ ")") $$
80 bs $$ cr
76 bs $$ cr
81− else id
77+ Nothing -> id
82 in render colwidth $ withHead $ prettyList $ map prettyBlock blocks
78 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) =
56 meta'
56 meta'
57 main = render colwidth $ vcat (map (elementToOPML opts) elements)
57 main = render colwidth $ vcat (map (elementToOPML opts) elements)
58 context = defField "body" main metadata
58 context = defField "body" main metadata
59− in if writerStandalone opts
59+ in case writerTemplate opts of
60+ Nothing -> main
60− then renderTemplate' (writerTemplate opts) context
61+ Just tpl -> renderTemplate' tpl context
61− else main
62
62
63writeHtmlInlines :: [Inline] -> String
63writeHtmlInlines :: [Inline] -> String
64writeHtmlInlines ils = trim $ writeHtmlString def
64writeHtmlInlines ils = trim $ writeHtmlString def
src/Text/Pandoc/Writers/OpenDocument.hs+3−3
@@ -196,9 +196,9 @@ writeOpenDocument opts (Pandoc meta blocks) =
196 context = defField "body" body
196 context = defField "body" body
197 $ defField "automatic-styles" (render' automaticStyles)
197 $ defField "automatic-styles" (render' automaticStyles)
198 $ metadata
198 $ metadata
199− in if writerStandalone opts
199+ in case writerTemplate opts of
200+ Nothing -> body
200− then renderTemplate' (writerTemplate opts) context
201+ Just tpl -> renderTemplate' tpl context
201− else body
202
202
203withParagraphStyle :: WriterOptions -> String -> [Block] -> State WriterState Doc
203withParagraphStyle :: WriterOptions -> String -> [Block] -> State WriterState Doc
204withParagraphStyle o s (b:bs)
204withParagraphStyle o s (b:bs)
src/Text/Pandoc/Writers/Org.hs+3−3
@@ -78,9 +78,9 @@ pandocToOrg (Pandoc meta blocks) = do
78 let context = defField "body" main
78 let context = defField "body" main
79 $ defField "math" hasMath
79 $ defField "math" hasMath
80 $ metadata
80 $ metadata
81− if writerStandalone opts
81+ case writerTemplate opts of
82+ Nothing -> return main
82− then return $ renderTemplate' (writerTemplate opts) context
83+ Just tpl -> return $ renderTemplate' tpl context
83− else return main
84
84
85-- | Return Org representation of notes.
85-- | Return Org representation of notes.
86notesToOrg :: [[Block]] -> State WriterState Doc
86notesToOrg :: [[Block]] -> State WriterState Doc
src/Text/Pandoc/Writers/RST.hs+6−6
@@ -81,9 +81,9 @@ pandocToRST (Pandoc meta blocks) = do
81 (fmap (render colwidth) . blockListToRST)
81 (fmap (render colwidth) . blockListToRST)
82 (fmap (trimr . render colwidth) . inlineListToRST)
82 (fmap (trimr . render colwidth) . inlineListToRST)
83 $ deleteMeta "title" $ deleteMeta "subtitle" meta
83 $ deleteMeta "title" $ deleteMeta "subtitle" meta
84− body <- blockListToRST' True $ if writerStandalone opts
84+ body <- blockListToRST' True $ case writerTemplate opts of
85− then normalizeHeadings 1 blocks
85+ Just _ -> normalizeHeadings 1 blocks
86− else blocks
86+ Nothing -> blocks
87 notes <- liftM (reverse . stNotes) get >>= notesToRST
87 notes <- liftM (reverse . stNotes) get >>= notesToRST
88 -- note that the notes may contain refs, so we do them first
88 -- note that the notes may contain refs, so we do them first
89 refs <- liftM (reverse . stLinks) get >>= refsToRST
89 refs <- liftM (reverse . stLinks) get >>= refsToRST
@@ -99,9 +99,9 @@ pandocToRST (Pandoc meta blocks) = do
99 $ defField "math" hasMath
99 $ defField "math" hasMath
100 $ defField "rawtex" rawTeX
100 $ defField "rawtex" rawTeX
101 $ metadata
101 $ metadata
102− if writerStandalone opts
102+ case writerTemplate opts of
103+ Nothing -> return main
103− then return $ renderTemplate' (writerTemplate opts) context
104+ Just tpl -> return $ renderTemplate' tpl context
104− else return main
105 where
105 where
106 normalizeHeadings lev (Header l a i:bs) =
106 normalizeHeadings lev (Header l a i:bs) =
107 Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
107 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) =
107 (tableOfContents $ filter isTOCHeader blocks)
107 (tableOfContents $ filter isTOCHeader blocks)
108 else id)
108 else id)
109 $ metadata
109 $ metadata
110− in if writerStandalone options
111− then renderTemplate' (writerTemplate options) context
110+ in case writerTemplate options of
111+ Just tpl -> renderTemplate' tpl context
112− else case reverse body of
112+ Nothing -> case reverse body of
113− ('\n':_) -> body
113+ ('\n':_) -> body
114− _ -> body ++ "\n"
114+ _ -> body ++ "\n"
115
115
116-- | Construct table of contents from list of header blocks.
116-- | Construct table of contents from list of header blocks.
117tableOfContents :: [Block] -> String
117tableOfContents :: [Block] -> String
src/Text/Pandoc/Writers/Shared.hs+2−1
@@ -49,6 +49,7 @@ import Data.Aeson (FromJSON(..), fromJSON, ToJSON (..), Value(Object), Result(..
49import Text.Pandoc.UTF8 (toStringLazy)
49import Text.Pandoc.UTF8 (toStringLazy)
50import qualified Data.Traversable as Traversable
50import qualified Data.Traversable as Traversable
51import Data.List ( groupBy )
51import Data.List ( groupBy )
52+import Data.Maybe ( isJust )
52
53
53-- | Create JSON value for template from a 'Meta' and an association list
54-- | Create JSON value for template from a 'Meta' and an association list
54-- of variables, specified at the command line or in the writer.
55-- of variables, specified at the command line or in the writer.
@@ -62,7 +63,7 @@ metaToJSON :: Monad m
62 -> Meta
63 -> Meta
63 -> m Value
64 -> m Value
64metaToJSON opts blockWriter inlineWriter (Meta metamap)
65metaToJSON opts blockWriter inlineWriter (Meta metamap)
65− | writerStandalone opts = do
66+ | isJust (writerTemplate opts) = do
66 let baseContext = foldl (\acc (x,y) -> setField x y acc) (Object H.empty)
67 let baseContext = foldl (\acc (x,y) -> setField x y acc) (Object H.empty)
67 $ writerVariables opts
68 $ writerVariables opts
68 renderedMap <- Traversable.mapM
69 renderedMap <- Traversable.mapM
src/Text/Pandoc/Writers/TEI.hs+3−3
@@ -78,9 +78,9 @@ writeTEI opts (Pandoc meta blocks) =
78 MathML _ -> True
78 MathML _ -> True
79 _ -> False)
79 _ -> False)
80 $ metadata
80 $ metadata
81− in if writerStandalone opts
81+ in case writerTemplate opts of
82+ Nothing -> main
82− then renderTemplate' (writerTemplate opts) context
83+ Just tpl -> renderTemplate' tpl context
83− else main
84
84
85-- | Convert an Element to TEI.
85-- | Convert an Element to TEI.
86elementToTEI :: WriterOptions -> Int -> Element -> Doc
86elementToTEI :: WriterOptions -> Int -> Element -> Doc
src/Text/Pandoc/Writers/Texinfo.hs+3−3
@@ -93,9 +93,9 @@ pandocToTexinfo options (Pandoc meta blocks) = do
93 $ defField "superscript" (stSuperscript st)
93 $ defField "superscript" (stSuperscript st)
94 $ defField "strikeout" (stStrikeout st)
94 $ defField "strikeout" (stStrikeout st)
95 $ metadata
95 $ metadata
96− if writerStandalone options
96+ case writerTemplate options of
97+ Nothing -> return body
97− then return $ renderTemplate' (writerTemplate options) context
98+ Just tpl -> return $ renderTemplate' tpl context
98− else return body
99
99
100-- | Escape things as needed for Texinfo.
100-- | Escape things as needed for Texinfo.
101stringToTexinfo :: String -> String
101stringToTexinfo :: String -> String
src/Text/Pandoc/Writers/Textile.hs+3−3
@@ -65,9 +65,9 @@ pandocToTextile opts (Pandoc meta blocks) = do
65 notes <- liftM (unlines . reverse . stNotes) get
65 notes <- liftM (unlines . reverse . stNotes) get
66 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
66 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
67 let context = defField "body" main metadata
67 let context = defField "body" main metadata
68− if writerStandalone opts
68+ case writerTemplate opts of
69+ Nothing -> return main
69− then return $ renderTemplate' (writerTemplate opts) context
70+ Just tpl -> return $ renderTemplate' tpl context
70− else return main
71
71
72withUseTags :: State WriterState a -> State WriterState a
72withUseTags :: State WriterState a -> State WriterState a
73withUseTags action = do
73withUseTags action = do
src/Text/Pandoc/Writers/ZimWiki.hs+4−4
@@ -32,7 +32,7 @@ http://zim-wiki.org/manual/Help/Wiki_Syntax.html
32
32
33module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
33module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
34import Text.Pandoc.Definition
34import Text.Pandoc.Definition
35−import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerStandalone, writerTemplate, writerWrapText), WrapOption(..) )
35+import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerTemplate, writerWrapText), WrapOption(..) )
36import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting, trimr
36import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting, trimr
37 , substitute )
37 , substitute )
38import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
38import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
@@ -71,9 +71,9 @@ pandocToZimWiki opts (Pandoc meta blocks) = do
71 let context = defField "body" main
71 let context = defField "body" main
72 $ defField "toc" (writerTableOfContents opts)
72 $ defField "toc" (writerTableOfContents opts)
73 $ metadata
73 $ metadata
74− if writerStandalone opts
74+ case writerTemplate opts of
75− then return $ renderTemplate' (writerTemplate opts) context
75+ Just tpl -> return $ renderTemplate' tpl context
76− else return main
76+ Nothing -> return main
77
77
78-- | Escape special characters for ZimWiki.
78-- | Escape special characters for ZimWiki.
79escapeString :: String -> String
79escapeString :: String -> String
tests/Tests/Helpers.hs+3−3
@@ -57,11 +57,11 @@ class ToString a where
57 toString :: a -> String
57 toString :: a -> String
58
58
59instance ToString Pandoc where
59instance ToString Pandoc where
60− toString d = writeNative def{ writerStandalone = s } $ toPandoc d
60+ toString d = writeNative def{ writerTemplate = s } $ toPandoc d
61 where s = case d of
61 where s = case d of
62 (Pandoc (Meta m) _)
62 (Pandoc (Meta m) _)
63− | M.null m -> False
63+ | M.null m -> Nothing
64− | otherwise -> True
64+ | otherwise -> Just "" -- need this to get meta output
65
65
66instance ToString Blocks where
66instance ToString Blocks where
67 toString = writeNative def . toPandoc
67 toString = writeNative def . toPandoc
tests/Tests/Readers/Docx.hs+3−3
@@ -26,11 +26,11 @@ noNorm :: Pandoc -> NoNormPandoc
26noNorm = NoNormPandoc
26noNorm = NoNormPandoc
27
27
28instance ToString NoNormPandoc where
28instance ToString NoNormPandoc where
29− toString d = writeNative def{ writerStandalone = s } $ toPandoc d
29+ toString d = writeNative def{ writerTemplate = s } $ toPandoc d
30 where s = case d of
30 where s = case d of
31 NoNormPandoc (Pandoc (Meta m) _)
31 NoNormPandoc (Pandoc (Meta m) _)
32− | M.null m -> False
32+ | M.null m -> Nothing
33− | otherwise -> True
33+ | otherwise -> Just "" -- need this to get meta output
34
34
35instance ToPandoc NoNormPandoc where
35instance ToPandoc NoNormPandoc where
36 toPandoc = unNoNorm
36 toPandoc = unNoNorm
tests/Tests/Readers/Odt.hs+3−3
@@ -41,11 +41,11 @@ newtype NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
41 deriving ( Show )
41 deriving ( Show )
42
42
43instance ToString NoNormPandoc where
43instance ToString NoNormPandoc where
44− toString d = writeNative def{ writerStandalone = s } $ toPandoc d
44+ toString d = writeNative def{ writerTemplate = s } $ toPandoc d
45 where s = case d of
45 where s = case d of
46 NoNormPandoc (Pandoc (Meta m) _)
46 NoNormPandoc (Pandoc (Meta m) _)
47− | M.null m -> False
47+ | M.null m -> Nothing
48− | otherwise -> True
48+ | otherwise -> Just "" -- need this for Meta output
49
49
50instance ToPandoc NoNormPandoc where
50instance ToPandoc NoNormPandoc where
51 toPandoc = unNoNorm
51 toPandoc = unNoNorm
tests/Tests/Writers/Native.hs+1−1
@@ -8,7 +8,7 @@ import Text.Pandoc.Arbitrary()
8
8
9p_write_rt :: Pandoc -> Bool
9p_write_rt :: Pandoc -> Bool
10p_write_rt d =
10p_write_rt d =
11− read (writeNative def{ writerStandalone = True } d) == d
11+ read (writeNative def{ writerTemplate = Just "" } d) == d
12
12
13p_write_blocks_rt :: [Block] -> Bool
13p_write_blocks_rt :: [Block] -> Bool
14p_write_blocks_rt bs = length bs > 20 ||
14p_write_blocks_rt bs = length bs > 20 ||
tests/Tests/Writers/RST.hs+2−4
@@ -47,8 +47,7 @@ tests = [ testGroup "rubrics"
47 [ "foo"
47 [ "foo"
48 , "==="]
48 , "==="]
49 -- note: heading normalization is only done in standalone mode
49 -- 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)
52 "heading levels" $
51 "heading levels" $
53 header 1 (text "Header 1") <>
52 header 1 (text "Header 1") <>
54 header 3 (text "Header 2") <>
53 header 3 (text "Header 2") <>
@@ -78,8 +77,7 @@ tests = [ testGroup "rubrics"
78 , ""
77 , ""
79 , "Header 2"
78 , "Header 2"
80 , "--------"]
79 , "--------"]
81− , test (writeRST def{ writerStandalone = True,
82− writerTemplate = "$body$\n" } . toPandoc)
80+ , test (writeRST def{ writerTemplate = Just "$body$\n" } . toPandoc)
83 "minimal heading levels" $
81 "minimal heading levels" $
84 header 2 (text "Header 1") <>
82 header 2 (text "Header 1") <>
85 header 3 (text "Header 2") <>
83 header 3 (text "Header 2") <>