git.iko.soy/typeable/pandoc
on master help sign in
Changed reader parameters from ParserState to ReaderOptions.
commitacde1e82d2f070ceab8d0fd01ad3677c6c9e078c authorJohn MacFarlane <jgm@berkeley.edu> dateWed 25 Jul 2012, 22:35 (14 years ago) parent9b5d203
12 files changed+54−76
src/Tests/Readers/LaTeX.hs+1−1 src/Tests/Readers/Markdown.hs+4−7 src/Tests/Readers/RST.hs+1−1 src/Text/Pandoc.hs+8−27 src/Text/Pandoc/Options.hs+1 src/Text/Pandoc/Readers/DocBook.hs+2−2 src/Text/Pandoc/Readers/HTML.hs+3−3 src/Text/Pandoc/Readers/LaTeX.hs+2−2 src/Text/Pandoc/Readers/Markdown.hs+4−3 src/Text/Pandoc/Readers/RST.hs+4−4 src/Text/Pandoc/Readers/Textile.hs+8−8 src/pandoc.hs+16−18
src/Tests/Readers/LaTeX.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
99import Text.Pandoc
1010
1111latex :: String -> Pandoc
12−latex = readLaTeX defaultParserState
12+latex = readLaTeX def
1313
1414infix 4 =:
1515(=:) :: ToString c
src/Tests/Readers/Markdown.hs+4−7
@@ -10,12 +10,10 @@ import Text.Pandoc.Builder
1010import Text.Pandoc
1111
1212markdown :: String -> Pandoc
13−markdown = readMarkdown defaultParserState
13+markdown = readMarkdown def
1414
1515markdownSmart :: String -> Pandoc
16−markdownSmart = readMarkdown defaultParserState{ stateOptions =
17− let oldOpts = stateOptions defaultParserState in
18− oldOpts { readerSmart = True } }
16+markdownSmart = readMarkdown def { readerSmart = True }
1917
2018infix 4 =:
2119(=:) :: ToString c
@@ -27,7 +25,7 @@ p_markdown_round_trip :: Block -> Bool
2725p_markdown_round_trip b = matches d' d''
2826 where d' = normalize $ Pandoc (Meta [] [] []) [b]
2927 d'' = normalize
30− $ readMarkdown defaultParserState{ stateSmart = True }
28+ $ readMarkdown def { readerSmart = True }
3129 $ writeMarkdown defaultWriterOptions d'
3230 matches (Pandoc _ [Plain []]) (Pandoc _ []) = True
3331 matches (Pandoc _ [Para []]) (Pandoc _ []) = True
@@ -93,8 +91,7 @@ tests = [ testGroup "inline code"
9391 =?> para (note (para "See [^1]"))
9492 ]
9593 , testGroup "lhs"
96− [ test (readMarkdown def{stateOptions =
97− def{readerLiterateHaskell = True}})
94+ [ test (readMarkdown def{ readerLiterateHaskell = True })
9895 "inverse bird tracks and html" $
9996 "> a\n\n< b\n\n<div>\n"
10097 =?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
src/Tests/Readers/RST.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
99import Text.Pandoc
1010
1111rst :: String -> Pandoc
12−rst = readRST defaultParserState
12+rst = readRST def
1313
1414infix 4 =:
1515(=:) :: ToString c
src/Text/Pandoc.hs+8−27
@@ -43,8 +43,7 @@ inline links:
4343>
4444> markdownToRST :: String -> String
4545> markdownToRST =
46−> (writeRST defaultWriterOptions {writerReferenceLinks = True}) .
47−> readMarkdown defaultParserState
46+> (writeRST def {writerReferenceLinks = True}) . readMarkdown def
4847>
4948> main = getContents >>= putStrLn . markdownToRST
5049
@@ -73,14 +72,6 @@ module Text.Pandoc
7372 , readTextile
7473 , readDocBook
7574 , readNative
76− -- * Parser state used in readers
77− , ParserState (..)
78− , defaultParserState
79− , ParserContext (..)
80− , QuoteContext (..)
81− , KeyTable
82− , NoteTable
83− , HeaderType (..)
8475 -- * Writers: converting /from/ Pandoc format
8576 , Writer (..)
8677 , writeNative
@@ -118,8 +109,6 @@ module Text.Pandoc
118109 , rtfEmbedImage
119110 , jsonFilter
120111 , ToJsonFilter(..)
121− -- * From Data.Default
122− , def
123112 ) where
124113
125114import Text.Pandoc.Definition
@@ -151,41 +140,33 @@ import Text.Pandoc.Writers.Textile
151140import Text.Pandoc.Writers.Org
152141import Text.Pandoc.Writers.AsciiDoc
153142import Text.Pandoc.Templates
154−import Text.Pandoc.Parsing
155143import Text.Pandoc.Shared
156144import Text.Pandoc.Options
157145import Data.ByteString.Lazy (ByteString)
158146import Data.Version (showVersion)
159147import Text.JSON.Generic
160148import Paths_pandoc (version)
161−import Data.Default
162149
163150-- | Version number of pandoc library.
164151pandocVersion :: String
165152pandocVersion = showVersion version
166153
167154-- | Association list of formats and readers.
168−readers :: [(String, ParserState -> String -> Pandoc)]
155+readers :: [(String, ReaderOptions -> String -> Pandoc)]
169156readers = [("native" , \_ -> readNative)
170157 ,("json" , \_ -> decodeJSON)
171158 ,("markdown" , readMarkdown)
172− ,("markdown+lhs" , \st ->
173− readMarkdown st{ stateOptions =
174− let oldopts = stateOptions st
175− in oldopts{ readerLiterateHaskell = True} })
159+ ,("markdown+lhs" , \opt ->
160+ readMarkdown opt{ readerLiterateHaskell = True })
176161 ,("rst" , readRST)
177− ,("rst+lhs" , \st ->
178− readRST st{ stateOptions =
179− let oldopts = stateOptions st
180− in oldopts{ readerLiterateHaskell = True} })
162+ ,("rst+lhs" , \opt ->
163+ readRST opt{ readerLiterateHaskell = True })
181164 ,("docbook" , readDocBook)
182165 ,("textile" , readTextile) -- TODO : textile+lhs
183166 ,("html" , readHtml)
184167 ,("latex" , readLaTeX)
185− ,("latex+lhs" , \st ->
186− readLaTeX st{ stateOptions =
187− let oldopts = stateOptions st
188− in oldopts{ readerLiterateHaskell = True} })
168+ ,("latex+lhs" , \opt ->
169+ readLaTeX opt{ readerLiterateHaskell = True })
189170 ]
190171
191172data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
src/Text/Pandoc/Options.hs+1
@@ -30,6 +30,7 @@ options.
3030-}
3131module Text.Pandoc.Options ( Extension(..)
3232 , ReaderOptions(..)
33+ , def
3334 ) where
3435import Data.Set (Set)
3536import qualified Data.Set as Set
src/Text/Pandoc/Readers/DocBook.hs+2−2
@@ -1,6 +1,6 @@
11module Text.Pandoc.Readers.DocBook ( readDocBook ) where
22import Data.Char (toUpper, isDigit)
3−import Text.Pandoc.Parsing (ParserState(..))
3+import Text.Pandoc.Options
44import Text.Pandoc.Definition
55import Text.Pandoc.Builder
66import Text.XML.Light
@@ -503,7 +503,7 @@ data DBState = DBState{ dbSectionLevel :: Int
503503 , dbBook :: Bool
504504 } deriving Show
505505
506−readDocBook :: ParserState -> String -> Pandoc
506+readDocBook :: ReaderOptions -> String -> Pandoc
507507readDocBook _ inp = setTitle (dbDocTitle st')
508508 $ setAuthors (dbDocAuthors st')
509509 $ setDate (dbDocDate st')
src/Text/Pandoc/Readers/HTML.hs+3−3
@@ -55,11 +55,11 @@ isSpace '\n' = True
5555isSpace _ = False
5656
5757-- | Convert HTML-formatted string to 'Pandoc' document.
58−readHtml :: ParserState -- ^ Parser state
58+readHtml :: ReaderOptions -- ^ Reader options
5959 -> String -- ^ String to parse (assumes @'\n'@ line endings)
6060 -> Pandoc
61−readHtml st inp = Pandoc meta blocks
62− where blocks = readWith parseBody st rest
61+readHtml opts inp = Pandoc meta blocks
62+ where blocks = readWith parseBody def{ stateOptions = opts } rest
6363 tags = canonicalizeTags $
6464 parseTagsOptions parseOptions{ optTagPosition = True } inp
6565 hasHeader = any (~== TagOpen "head" []) tags
src/Text/Pandoc/Readers/LaTeX.hs+2−2
@@ -50,10 +50,10 @@ import qualified Data.Map as M
5050import qualified Control.Exception as E
5151
5252-- | Parse LaTeX from string and return 'Pandoc' document.
53−readLaTeX :: ParserState -- ^ Parser state, including options for parser
53+readLaTeX :: ReaderOptions -- ^ Reader options
5454 -> String -- ^ String to parse (assumes @'\n'@ line endings)
5555 -> Pandoc
56−readLaTeX = readWith parseLaTeX
56+readLaTeX opts = readWith parseLaTeX def{ stateOptions = opts }
5757
5858parseLaTeX :: LP Pandoc
5959parseLaTeX = do
src/Text/Pandoc/Readers/Markdown.hs+4−3
@@ -49,10 +49,11 @@ import Text.HTML.TagSoup
4949import Text.HTML.TagSoup.Match (tagOpen)
5050
5151-- | Read markdown from an input string and return a Pandoc document.
52−readMarkdown :: ParserState -- ^ Parser state, including options for parser
53− -> String -- ^ String to parse (assuming @'\n'@ line endings)
52+readMarkdown :: ReaderOptions -- ^ Reader options
53+ -> String -- ^ String to parse (assuming @'\n'@ line endings)
5454 -> Pandoc
55−readMarkdown state s = (readWith parseMarkdown) state (s ++ "\n\n")
55+readMarkdown opts s =
56+ (readWith parseMarkdown) def{ stateOptions = opts } (s ++ "\n\n")
5657
5758--
5859-- Constants and data structure definitions
src/Text/Pandoc/Readers/RST.hs+4−4
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2727
2828Conversion from reStructuredText to 'Pandoc' document.
2929-}
30−module Text.Pandoc.Readers.RST (
30+module Text.Pandoc.Readers.RST (
3131 readRST
3232 ) where
3333import Text.Pandoc.Definition
@@ -41,10 +41,10 @@ import Text.Printf ( printf )
4141import Data.Maybe ( catMaybes )
4242
4343-- | Parse reStructuredText string and return Pandoc document.
44−readRST :: ParserState -- ^ Parser state, including options for parser
45− -> String -- ^ String to parse (assuming @'\n'@ line endings)
44+readRST :: ReaderOptions -- ^ Reader options
45+ -> String -- ^ String to parse (assuming @'\n'@ line endings)
4646 -> Pandoc
47−readRST state s = (readWith parseRST) state (s ++ "\n\n")
47+readRST opts s = (readWith parseRST) def{ stateOptions = opts } (s ++ "\n\n")
4848
4949--
5050-- Constants and data structure definitions
src/Text/Pandoc/Readers/Textile.hs+8−8
@@ -56,7 +56,7 @@ TODO : refactor common patterns across readers :
5656module Text.Pandoc.Readers.Textile ( readTextile) where
5757
5858import Text.Pandoc.Definition
59−import Text.Pandoc.Shared
59+import Text.Pandoc.Shared
6060import Text.Pandoc.Options
6161import Text.Pandoc.Parsing
6262import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
@@ -67,11 +67,11 @@ import Control.Monad ( guard, liftM )
6767import Control.Applicative ((<$>), (*>), (<*))
6868
6969-- | Parse a Textile text and return a Pandoc document.
70−readTextile :: ParserState -- ^ Parser state, including options for parser
71− -> String -- ^ String to parse (assuming @'\n'@ line endings)
72− -> Pandoc
73−readTextile state s =
74− (readWith parseTextile) state (s ++ "\n\n")
70+readTextile :: ReaderOptions -- ^ Reader options
71+ -> String -- ^ String to parse (assuming @'\n'@ line endings)
72+ -> Pandoc
73+readTextile opts s =
74+ (readWith parseTextile) def{ stateOptions = opts } (s ++ "\n\n")
7575
7676
7777-- | Generate a Pandoc ADT from a textile document
@@ -243,8 +243,8 @@ definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
243243definitionListItem = try $ do
244244 string "- "
245245 term <- many1Till inline (try (whitespace >> string ":="))
246− def <- inlineDef <|> multilineDef
247− return (term, def)
246+ def' <- inlineDef <|> multilineDef
247+ return (term, def')
248248 where inlineDef :: Parser [Char] ParserState [[Block]]
249249 inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
250250 multilineDef :: Parser [Char] ParserState [[Block]]
src/pandoc.hs+16−18
@@ -936,23 +936,21 @@ main = do
936936 then "."
937937 else takeDirectory (head sources)
938938
939− let startParserState = def{ stateOptions = def{
940− readerStrict = strict
941− , readerSmart = smart || (texLigatures &&
942− (laTeXOutput || writerName' == "context"))
943− , readerStandalone = standalone'
944− , readerParseRaw = parseRaw
945− , readerColumns = columns
946− , readerTabStop = tabStop
947− , readerOldDashes = oldDashes
948− , readerLiterateHaskell =
949− "+lhs" `isSuffixOf` readerName' ||
950− lhsExtension sources
951− , readerCitations = map CSL.refId refs
952− , readerIndentedCodeClasses = codeBlockClasses
953− , readerApplyMacros = not laTeXOutput
954− }
955− }
939+ let readerOpts = def{ readerStrict = strict
940+ , readerSmart = smart || (texLigatures &&
941+ (laTeXOutput || writerName' == "context"))
942+ , readerStandalone = standalone'
943+ , readerParseRaw = parseRaw
944+ , readerColumns = columns
945+ , readerTabStop = tabStop
946+ , readerOldDashes = oldDashes
947+ , readerLiterateHaskell =
948+ "+lhs" `isSuffixOf` readerName' ||
949+ lhsExtension sources
950+ , readerCitations = map CSL.refId refs
951+ , readerIndentedCodeClasses = codeBlockClasses
952+ , readerApplyMacros = not laTeXOutput
953+ }
956954
957955 let writerOptions = def { writerStandalone = standalone',
958956 writerTemplate = templ,
@@ -1013,7 +1011,7 @@ main = do
10131011 then handleIncludes
10141012 else return
10151013
1016− doc <- (reader startParserState) `fmap` (readSources sources >>=
1014+ doc <- (reader readerOpts) `fmap` (readSources sources >>=
10171015 handleIncludes' . convertTabs . intercalate "\n")
10181016
10191017 let doc0 = foldr ($) doc transforms