git.iko.soy/typeable/pandoc
on master help sign in
Moved 'readers' and 'writers' to Text.Pandoc.

This allows library users to avoid repetitive case statements...

commit9602f73f2a943c21a5d1593e99cdbcbde08f6dcb authorJohn MacFarlane <jgm@berkeley.edu> dateFri 10 Dec 2010, 17:30 (16 years ago) parentde6452c
2 files changed+47−49
src/Text/Pandoc.hs+42 src/pandoc.hs+5−49
src/Text/Pandoc.hs+42
@@ -57,6 +57,9 @@ module Text.Pandoc
5757 (
5858 -- * Definitions
5959 module Text.Pandoc.Definition
60+ -- * Lists of readers and writers
61+ , readers
62+ , writers
6063 -- * Readers: converting /to/ Pandoc format
6164 , readMarkdown
6265 , readRST
@@ -132,3 +135,42 @@ import Paths_pandoc (version)
132135-- | Version number of pandoc library.
133136pandocVersion :: String
134137pandocVersion = showVersion version
138+
139+-- | Association list of formats and readers.
140+readers :: [(String, ParserState -> String -> Pandoc)]
141+readers = [("native" , \_ -> read)
142+ ,("markdown" , readMarkdown)
143+ ,("markdown+lhs" , readMarkdown)
144+ ,("rst" , readRST)
145+ ,("textile" , readTextile) -- TODO : textile+lhs
146+ ,("rst+lhs" , readRST)
147+ ,("html" , readHtml)
148+ ,("latex" , readLaTeX)
149+ ,("latex+lhs" , readLaTeX)
150+ ]
151+
152+-- | Association list of formats and writers (omitting the
153+-- binary writers, odt and epub).
154+writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
155+writers = [("native" , writeNative)
156+ ,("html" , writeHtmlString)
157+ ,("html+lhs" , writeHtmlString)
158+ ,("s5" , writeHtmlString)
159+ ,("slidy" , writeHtmlString)
160+ ,("docbook" , writeDocbook)
161+ ,("opendocument" , writeOpenDocument)
162+ ,("latex" , writeLaTeX)
163+ ,("latex+lhs" , writeLaTeX)
164+ ,("context" , writeConTeXt)
165+ ,("texinfo" , writeTexinfo)
166+ ,("man" , writeMan)
167+ ,("markdown" , writeMarkdown)
168+ ,("markdown+lhs" , writeMarkdown)
169+ ,("plain" , writePlain)
170+ ,("rst" , writeRST)
171+ ,("rst+lhs" , writeRST)
172+ ,("mediawiki" , writeMediaWiki)
173+ ,("textile" , writeTextile)
174+ ,("rtf" , writeRTF)
175+ ,("org" , writeOrg)
176+ ]
src/pandoc.hs+5−49
@@ -80,50 +80,6 @@ wrapWords c = wrap' c c where
8080 then ",\n" ++ x ++ wrap' cols (cols - length x) xs
8181 else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
8282
83−-- | Association list of formats and readers.
84−readers :: [(String, ParserState -> String -> Pandoc)]
85−readers = [("native" , readPandoc)
86− ,("markdown" , readMarkdown)
87− ,("markdown+lhs" , readMarkdown)
88− ,("rst" , readRST)
89− ,("textile" , readTextile) -- TODO : textile+lhs
90− ,("rst+lhs" , readRST)
91− ,("html" , readHtml)
92− ,("latex" , readLaTeX)
93− ,("latex+lhs" , readLaTeX)
94− ]
95−
96−-- | Reader for native Pandoc format.
97−readPandoc :: ParserState -> String -> Pandoc
98−readPandoc _ = read
99−
100−-- | Association list of formats and writers.
101−writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
102−writers = [("native" , writeNative)
103− ,("html" , writeHtmlString)
104− ,("html+lhs" , writeHtmlString)
105− ,("s5" , writeHtmlString)
106− ,("slidy" , writeHtmlString)
107− ,("docbook" , writeDocbook)
108− ,("opendocument" , writeOpenDocument)
109− ,("odt" , \_ _ -> "")
110− ,("epub" , \_ _ -> "")
111− ,("latex" , writeLaTeX)
112− ,("latex+lhs" , writeLaTeX)
113− ,("context" , writeConTeXt)
114− ,("texinfo" , writeTexinfo)
115− ,("man" , writeMan)
116− ,("markdown" , writeMarkdown)
117− ,("markdown+lhs" , writeMarkdown)
118− ,("plain" , writePlain)
119− ,("rst" , writeRST)
120− ,("rst+lhs" , writeRST)
121− ,("mediawiki" , writeMediaWiki)
122− ,("textile" , writeTextile)
123− ,("rtf" , writeRTF)
124− ,("org" , writeOrg)
125− ]
126−
12783isNonTextOutput :: String -> Bool
12884isNonTextOutput = (`elem` ["odt","epub"])
12985
@@ -210,13 +166,13 @@ options =
210166 (ReqArg
211167 (\arg opt -> return opt { optReader = map toLower arg })
212168 "FORMAT")
213− "" -- ("(" ++ (intercalate ", " $ map fst readers) ++ ")")
169+ ""
214170
215171 , Option "tw" ["to","write"]
216172 (ReqArg
217173 (\arg opt -> return opt { optWriter = map toLower arg })
218174 "FORMAT")
219− "" -- ("(" ++ (intercalate ", " $ map fst writers) ++ ")")
175+ ""
220176
221177 , Option "s" ["standalone"]
222178 (NoArg
@@ -561,7 +517,7 @@ usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
561517usageMessage programName = usageInfo
562518 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
563519 (intercalate ", " $ map fst readers) ++ "\nOutput formats: " ++
564− (intercalate ", " $ map fst writers) ++ "\nOptions:")
520+ (intercalate ", " $ map fst writers ++ ["odt","epub"]) ++ "\nOptions:")
565521
566522-- Determine default reader based on source file extensions
567523defaultReaderName :: String -> [FilePath] -> String
@@ -711,8 +667,8 @@ main = do
711667 Nothing -> error ("Unknown reader: " ++ readerName')
712668
713669 let writer = case lookup writerName' writers of
714− Just _ | writerName' == "epub" -> writeEPUB epubStylesheet
715− Just _ | writerName' == "odt" -> writeODT referenceODT
670+ Nothing | writerName' == "epub" -> writeEPUB epubStylesheet
671+ Nothing | writerName' == "odt" -> writeODT referenceODT
716672 Just r -> \o ->
717673 return . fromString . r o
718674 Nothing -> error $ "Unknown writer: " ++