git.iko.soy/typeable/pandoc
on master help sign in
Use Text.Pandoc.Templates instead of Text.Pandoc.DefaultTemplates.

(in pandoc.hs and Text.Pandoc) git-svn-id: https://pandoc.googlecode.com/svn/trunk@1689 788f1e2b-df1e-0410-8736-df70ead52e1b

commitecbf3388d4bf00649a47d11360be1065a67ff0b3 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:10 (17 years ago) parent2b1c010
3 files changed+41−32
src/Text/Pandoc.hs+3−3 src/Text/Pandoc/Templates.hs+5−2 src/pandoc.hs+33−27
src/Text/Pandoc.hs+3−3
@@ -88,8 +88,8 @@ module Text.Pandoc
8888 , WriterOptions (..)
8989 , HTMLMathMethod (..)
9090 , defaultWriterOptions
91− -- * Default headers for various output formats
92− , module Text.Pandoc.DefaultTemplates
91+ -- * Rendering templates and default templates
92+ , module Text.Pandoc.Templates
9393 -- * Version
9494 , pandocVersion
9595 ) where
@@ -111,7 +111,7 @@ import Text.Pandoc.Writers.OpenDocument
111111import Text.Pandoc.Writers.Man
112112import Text.Pandoc.Writers.RTF
113113import Text.Pandoc.Writers.MediaWiki
114−import Text.Pandoc.DefaultTemplates
114+import Text.Pandoc.Templates
115115import Text.Pandoc.Shared
116116import Data.Version (showVersion)
117117import Paths_pandoc (version)
src/Text/Pandoc/Templates.hs+5−2
@@ -57,11 +57,14 @@ import Paths_pandoc
5757-- | Get the default template, either from the application's user data
5858-- directory (~/.pandoc on unix) or from the cabal data directory.
5959getDefaultTemplate :: String -> IO (Either E.IOException String)
60+getDefaultTemplate "native" = return $ Right ""
61+getDefaultTemplate "odt" = getDefaultTemplate "opendocument"
6062getDefaultTemplate format = do
61− ut <- getTemplateFromUserDataDirectory format
63+ let format' = takeWhile (/='+') format -- strip off "+lhs" if present
64+ ut <- getTemplateFromUserDataDirectory format'
6265 case ut of
6366 Right t -> return $ Right t
64− Left _ -> getTemplateFromCabalDataDirectory format
67+ Left _ -> getTemplateFromCabalDataDirectory format'
6568
6669getTemplateFromUserDataDirectory :: String -> IO (Either E.IOException String)
6770getTemplateFromUserDataDirectory format = E.try $ do
src/pandoc.hs+33−27
@@ -32,6 +32,7 @@ writers.
3232module Main where
3333import Text.Pandoc
3434import Text.Pandoc.ODT
35+import Text.Pandoc.Templates (getDefaultTemplate)
3536import Text.Pandoc.Shared ( HTMLMathMethod (..), tabFilter, ObfuscationMethod (..) )
3637#ifdef _HIGHLIGHTING
3738import Text.Pandoc.Highlighting ( languages )
@@ -96,26 +97,26 @@ readers = [("native" , readPandoc)
9697readPandoc :: ParserState -> String -> Pandoc
9798readPandoc _ = read
9899
99−-- | Association list of formats and pairs of writers and default headers.
100−writers :: [ ( String, ( WriterOptions -> Pandoc -> String, String ) ) ]
101−writers = [("native" , (writeDoc, ""))
102− ,("html" , (writeHtmlString, ""))
103− ,("html+lhs" , (writeHtmlString, ""))
104− ,("s5" , (writeS5String, defaultS5Template))
105− ,("docbook" , (writeDocbook, defaultDocbookTemplate))
106− ,("opendocument" , (writeOpenDocument, defaultOpenDocumentTemplate))
107− ,("odt" , (writeOpenDocument, defaultOpenDocumentTemplate))
108− ,("latex" , (writeLaTeX, defaultLaTeXTemplate))
109− ,("latex+lhs" , (writeLaTeX, defaultLaTeXTemplate))
110− ,("context" , (writeConTeXt, defaultConTeXtTemplate))
111− ,("texinfo" , (writeTexinfo, ""))
112− ,("man" , (writeMan, ""))
113− ,("markdown" , (writeMarkdown, ""))
114− ,("markdown+lhs" , (writeMarkdown, ""))
115− ,("rst" , (writeRST, ""))
116− ,("rst+lhs" , (writeRST, ""))
117− ,("mediawiki" , (writeMediaWiki, ""))
118− ,("rtf" , (writeRTF, defaultRTFTemplate))
100+-- | Association list of formats and writers.
101+writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
102+writers = [("native" , writeDoc)
103+ ,("html" , writeHtmlString)
104+ ,("html+lhs" , writeHtmlString)
105+ ,("s5" , writeS5String)
106+ ,("docbook" , writeDocbook)
107+ ,("opendocument" , writeOpenDocument)
108+ ,("odt" , writeOpenDocument)
109+ ,("latex" , writeLaTeX)
110+ ,("latex+lhs" , writeLaTeX)
111+ ,("context" , writeConTeXt)
112+ ,("texinfo" , writeTexinfo)
113+ ,("man" , writeMan)
114+ ,("markdown" , writeMarkdown)
115+ ,("markdown+lhs" , writeMarkdown)
116+ ,("rst" , writeRST)
117+ ,("rst+lhs" , writeRST)
118+ ,("mediawiki" , writeMediaWiki)
119+ ,("rtf" , writeRTF)
119120 ]
120121
121122isNonTextOutput :: String -> Bool
@@ -427,10 +428,10 @@ options =
427428 , Option "D" ["print-default-template"]
428429 (ReqArg
429430 (\arg _ -> do
430− let template = case (lookup arg writers) of
431− Just (_, h) -> h
432− Nothing -> error ("Unknown reader: " ++ arg)
433− hPutStr stdout template
431+ templ <- getDefaultTemplate arg
432+ case templ of
433+ Right t -> hPutStr stdout t
434+ Left e -> error $ show e
434435 exitWith ExitSuccess)
435436 "FORMAT")
436437 "" -- "Print default template for FORMAT"
@@ -610,9 +611,14 @@ main = do
610611 Just r -> return r
611612 Nothing -> error ("Unknown reader: " ++ readerName')
612613
613− (writer, defaultTemplate) <- case (lookup writerName' writers) of
614− Just (w,h) -> return (w, h)
615− Nothing -> error ("Unknown writer: " ++ writerName')
614+ writer <- case (lookup writerName' writers) of
615+ Just r -> return r
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)
616622
617623 environment <- getEnvironment
618624 let columns = case lookup "COLUMNS" environment of