git.iko.soy/typeable/pandoc
on master help sign in
Use Text.Pandoc.Templates instead of Text.Pandoc.DefaultTemplates.
ecbf338fiddlosopher
src/Text/Pandoc.hs+3−3
@@ -88,8 +88,8 @@ module Text.Pandoc
88 , WriterOptions (..)
88 , WriterOptions (..)
89 , HTMLMathMethod (..)
89 , HTMLMathMethod (..)
90 , defaultWriterOptions
90 , defaultWriterOptions
91− -- * Default headers for various output formats
91+ -- * Rendering templates and default templates
92− , module Text.Pandoc.DefaultTemplates
92+ , module Text.Pandoc.Templates
93 -- * Version
93 -- * Version
94 , pandocVersion
94 , pandocVersion
95 ) where
95 ) where
@@ -111,7 +111,7 @@ import Text.Pandoc.Writers.OpenDocument
111import Text.Pandoc.Writers.Man
111import Text.Pandoc.Writers.Man
112import Text.Pandoc.Writers.RTF
112import Text.Pandoc.Writers.RTF
113import Text.Pandoc.Writers.MediaWiki
113import Text.Pandoc.Writers.MediaWiki
114−import Text.Pandoc.DefaultTemplates
114+import Text.Pandoc.Templates
115import Text.Pandoc.Shared
115import Text.Pandoc.Shared
116import Data.Version (showVersion)
116import Data.Version (showVersion)
117import Paths_pandoc (version)
117import Paths_pandoc (version)
src/Text/Pandoc/Templates.hs+5−2
@@ -57,11 +57,14 @@ import Paths_pandoc
57-- | Get the default template, either from the application's user data
57-- | Get the default template, either from the application's user data
58-- directory (~/.pandoc on unix) or from the cabal data directory.
58-- directory (~/.pandoc on unix) or from the cabal data directory.
59getDefaultTemplate :: String -> IO (Either E.IOException String)
59getDefaultTemplate :: String -> IO (Either E.IOException String)
60+getDefaultTemplate "native" = return $ Right ""
61+getDefaultTemplate "odt" = getDefaultTemplate "opendocument"
60getDefaultTemplate format = do
62getDefaultTemplate format = do
63+ let format' = takeWhile (/='+') format -- strip off "+lhs" if present
61− ut <- getTemplateFromUserDataDirectory format
64+ ut <- getTemplateFromUserDataDirectory format'
62 case ut of
65 case ut of
63 Right t -> return $ Right t
66 Right t -> return $ Right t
64− Left _ -> getTemplateFromCabalDataDirectory format
67+ Left _ -> getTemplateFromCabalDataDirectory format'
65
68
66getTemplateFromUserDataDirectory :: String -> IO (Either E.IOException String)
69getTemplateFromUserDataDirectory :: String -> IO (Either E.IOException String)
67getTemplateFromUserDataDirectory format = E.try $ do
70getTemplateFromUserDataDirectory format = E.try $ do
src/pandoc.hs+33−27
@@ -32,6 +32,7 @@ writers.
32module Main where
32module Main where
33import Text.Pandoc
33import Text.Pandoc
34import Text.Pandoc.ODT
34import Text.Pandoc.ODT
35+import Text.Pandoc.Templates (getDefaultTemplate)
35import Text.Pandoc.Shared ( HTMLMathMethod (..), tabFilter, ObfuscationMethod (..) )
36import Text.Pandoc.Shared ( HTMLMathMethod (..), tabFilter, ObfuscationMethod (..) )
36#ifdef _HIGHLIGHTING
37#ifdef _HIGHLIGHTING
37import Text.Pandoc.Highlighting ( languages )
38import Text.Pandoc.Highlighting ( languages )
@@ -96,26 +97,26 @@ readers = [("native" , readPandoc)
96readPandoc :: ParserState -> String -> Pandoc
97readPandoc :: ParserState -> String -> Pandoc
97readPandoc _ = read
98readPandoc _ = read
98
99
99−-- | Association list of formats and pairs of writers and default headers.
100+-- | Association list of formats and writers.
100−writers :: [ ( String, ( WriterOptions -> Pandoc -> String, String ) ) ]
101+writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
101−writers = [("native" , (writeDoc, ""))
102+writers = [("native" , writeDoc)
102− ,("html" , (writeHtmlString, ""))
103+ ,("html" , writeHtmlString)
103− ,("html+lhs" , (writeHtmlString, ""))
104+ ,("html+lhs" , writeHtmlString)
104− ,("s5" , (writeS5String, defaultS5Template))
105+ ,("s5" , writeS5String)
105− ,("docbook" , (writeDocbook, defaultDocbookTemplate))
106+ ,("docbook" , writeDocbook)
106− ,("opendocument" , (writeOpenDocument, defaultOpenDocumentTemplate))
107+ ,("opendocument" , writeOpenDocument)
107− ,("odt" , (writeOpenDocument, defaultOpenDocumentTemplate))
108+ ,("odt" , writeOpenDocument)
108− ,("latex" , (writeLaTeX, defaultLaTeXTemplate))
109+ ,("latex" , writeLaTeX)
109− ,("latex+lhs" , (writeLaTeX, defaultLaTeXTemplate))
110+ ,("latex+lhs" , writeLaTeX)
110− ,("context" , (writeConTeXt, defaultConTeXtTemplate))
111+ ,("context" , writeConTeXt)
111− ,("texinfo" , (writeTexinfo, ""))
112+ ,("texinfo" , writeTexinfo)
112− ,("man" , (writeMan, ""))
113+ ,("man" , writeMan)
113− ,("markdown" , (writeMarkdown, ""))
114+ ,("markdown" , writeMarkdown)
114− ,("markdown+lhs" , (writeMarkdown, ""))
115+ ,("markdown+lhs" , writeMarkdown)
115− ,("rst" , (writeRST, ""))
116+ ,("rst" , writeRST)
116− ,("rst+lhs" , (writeRST, ""))
117+ ,("rst+lhs" , writeRST)
117− ,("mediawiki" , (writeMediaWiki, ""))
118+ ,("mediawiki" , writeMediaWiki)
118− ,("rtf" , (writeRTF, defaultRTFTemplate))
119+ ,("rtf" , writeRTF)
119 ]
120 ]
120
121
121isNonTextOutput :: String -> Bool
122isNonTextOutput :: String -> Bool
@@ -427,10 +428,10 @@ options =
427 , Option "D" ["print-default-template"]
428 , Option "D" ["print-default-template"]
428 (ReqArg
429 (ReqArg
429 (\arg _ -> do
430 (\arg _ -> do
430− let template = case (lookup arg writers) of
431+ templ <- getDefaultTemplate arg
431− Just (_, h) -> h
432+ case templ of
432− Nothing -> error ("Unknown reader: " ++ arg)
433− hPutStr stdout template
433+ Right t -> hPutStr stdout t
434+ Left e -> error $ show e
434 exitWith ExitSuccess)
435 exitWith ExitSuccess)
435 "FORMAT")
436 "FORMAT")
436 "" -- "Print default template for FORMAT"
437 "" -- "Print default template for FORMAT"
@@ -610,9 +611,14 @@ main = do
610 Just r -> return r
611 Just r -> return r
611 Nothing -> error ("Unknown reader: " ++ readerName')
612 Nothing -> error ("Unknown reader: " ++ readerName')
612
613
613− (writer, defaultTemplate) <- case (lookup writerName' writers) of
614+ writer <- case (lookup writerName' writers) of
614− Just (w,h) -> return (w, h)
615+ Just r -> return r
615− Nothing -> error ("Unknown writer: " ++ writerName')
616+ Nothing -> error ("Unknown writer: " ++ writerName')
617+
618+ templ <- getDefaultTemplate writerName'
619+ let defaultTemplate = case templ of
620+ Right t -> t
621+ Left e -> error (show e)
616
622
617 environment <- getEnvironment
623 environment <- getEnvironment
618 let columns = case lookup "COLUMNS" environment of
624 let columns = case lookup "COLUMNS" environment of