git.iko.soy/typeable/pandoc
on master help sign in
Changed reader parameters from ParserState to ReaderOptions.
acde1e8John MacFarlane
src/Tests/Readers/LaTeX.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
9import Text.Pandoc
9import Text.Pandoc
10
10
11latex :: String -> Pandoc
11latex :: String -> Pandoc
12−latex = readLaTeX defaultParserState
12+latex = readLaTeX def
13
13
14infix 4 =:
14infix 4 =:
15(=:) :: ToString c
15(=:) :: ToString c
src/Tests/Readers/Markdown.hs+4−7
@@ -10,12 +10,10 @@ import Text.Pandoc.Builder
10import Text.Pandoc
10import Text.Pandoc
11
11
12markdown :: String -> Pandoc
12markdown :: String -> Pandoc
13−markdown = readMarkdown defaultParserState
13+markdown = readMarkdown def
14
14
15markdownSmart :: String -> Pandoc
15markdownSmart :: String -> Pandoc
16−markdownSmart = readMarkdown defaultParserState{ stateOptions =
16+markdownSmart = readMarkdown def { readerSmart = True }
17− let oldOpts = stateOptions defaultParserState in
18− oldOpts { readerSmart = True } }
19
17
20infix 4 =:
18infix 4 =:
21(=:) :: ToString c
19(=:) :: ToString c
@@ -27,7 +25,7 @@ p_markdown_round_trip :: Block -> Bool
27p_markdown_round_trip b = matches d' d''
25p_markdown_round_trip b = matches d' d''
28 where d' = normalize $ Pandoc (Meta [] [] []) [b]
26 where d' = normalize $ Pandoc (Meta [] [] []) [b]
29 d'' = normalize
27 d'' = normalize
30− $ readMarkdown defaultParserState{ stateSmart = True }
28+ $ readMarkdown def { readerSmart = True }
31 $ writeMarkdown defaultWriterOptions d'
29 $ writeMarkdown defaultWriterOptions d'
32 matches (Pandoc _ [Plain []]) (Pandoc _ []) = True
30 matches (Pandoc _ [Plain []]) (Pandoc _ []) = True
33 matches (Pandoc _ [Para []]) (Pandoc _ []) = True
31 matches (Pandoc _ [Para []]) (Pandoc _ []) = True
@@ -93,8 +91,7 @@ tests = [ testGroup "inline code"
93 =?> para (note (para "See [^1]"))
91 =?> para (note (para "See [^1]"))
94 ]
92 ]
95 , testGroup "lhs"
93 , testGroup "lhs"
96− [ test (readMarkdown def{stateOptions =
97− def{readerLiterateHaskell = True}})
94+ [ test (readMarkdown def{ readerLiterateHaskell = True })
98 "inverse bird tracks and html" $
95 "inverse bird tracks and html" $
99 "> a\n\n< b\n\n<div>\n"
96 "> a\n\n< b\n\n<div>\n"
100 =?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
97 =?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
src/Tests/Readers/RST.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
9import Text.Pandoc
9import Text.Pandoc
10
10
11rst :: String -> Pandoc
11rst :: String -> Pandoc
12−rst = readRST defaultParserState
12+rst = readRST def
13
13
14infix 4 =:
14infix 4 =:
15(=:) :: ToString c
15(=:) :: ToString c
src/Text/Pandoc.hs+8−27
@@ -43,8 +43,7 @@ inline links:
43>
43>
44> markdownToRST :: String -> String
44> markdownToRST :: String -> String
45> markdownToRST =
45> markdownToRST =
46−> (writeRST defaultWriterOptions {writerReferenceLinks = True}) .
46+> (writeRST def {writerReferenceLinks = True}) . readMarkdown def
47−> readMarkdown defaultParserState
48>
47>
49> main = getContents >>= putStrLn . markdownToRST
48> main = getContents >>= putStrLn . markdownToRST
50
49
@@ -73,14 +72,6 @@ module Text.Pandoc
73 , readTextile
72 , readTextile
74 , readDocBook
73 , readDocBook
75 , readNative
74 , readNative
76− -- * Parser state used in readers
77− , ParserState (..)
78− , defaultParserState
79− , ParserContext (..)
80− , QuoteContext (..)
81− , KeyTable
82− , NoteTable
83− , HeaderType (..)
84 -- * Writers: converting /from/ Pandoc format
75 -- * Writers: converting /from/ Pandoc format
85 , Writer (..)
76 , Writer (..)
86 , writeNative
77 , writeNative
@@ -118,8 +109,6 @@ module Text.Pandoc
118 , rtfEmbedImage
109 , rtfEmbedImage
119 , jsonFilter
110 , jsonFilter
120 , ToJsonFilter(..)
111 , ToJsonFilter(..)
121− -- * From Data.Default
122− , def
123 ) where
112 ) where
124
113
125import Text.Pandoc.Definition
114import Text.Pandoc.Definition
@@ -151,41 +140,33 @@ import Text.Pandoc.Writers.Textile
151import Text.Pandoc.Writers.Org
140import Text.Pandoc.Writers.Org
152import Text.Pandoc.Writers.AsciiDoc
141import Text.Pandoc.Writers.AsciiDoc
153import Text.Pandoc.Templates
142import Text.Pandoc.Templates
154−import Text.Pandoc.Parsing
155import Text.Pandoc.Shared
143import Text.Pandoc.Shared
156import Text.Pandoc.Options
144import Text.Pandoc.Options
157import Data.ByteString.Lazy (ByteString)
145import Data.ByteString.Lazy (ByteString)
158import Data.Version (showVersion)
146import Data.Version (showVersion)
159import Text.JSON.Generic
147import Text.JSON.Generic
160import Paths_pandoc (version)
148import Paths_pandoc (version)
161−import Data.Default
162
149
163-- | Version number of pandoc library.
150-- | Version number of pandoc library.
164pandocVersion :: String
151pandocVersion :: String
165pandocVersion = showVersion version
152pandocVersion = showVersion version
166
153
167-- | Association list of formats and readers.
154-- | Association list of formats and readers.
168−readers :: [(String, ParserState -> String -> Pandoc)]
155+readers :: [(String, ReaderOptions -> String -> Pandoc)]
169readers = [("native" , \_ -> readNative)
156readers = [("native" , \_ -> readNative)
170 ,("json" , \_ -> decodeJSON)
157 ,("json" , \_ -> decodeJSON)
171 ,("markdown" , readMarkdown)
158 ,("markdown" , readMarkdown)
172− ,("markdown+lhs" , \st ->
159+ ,("markdown+lhs" , \opt ->
173− readMarkdown st{ stateOptions =
174− let oldopts = stateOptions st
175− in oldopts{ readerLiterateHaskell = True} })
160+ readMarkdown opt{ readerLiterateHaskell = True })
176 ,("rst" , readRST)
161 ,("rst" , readRST)
177− ,("rst+lhs" , \st ->
162+ ,("rst+lhs" , \opt ->
178− readRST st{ stateOptions =
179− let oldopts = stateOptions st
180− in oldopts{ readerLiterateHaskell = True} })
163+ readRST opt{ readerLiterateHaskell = True })
181 ,("docbook" , readDocBook)
164 ,("docbook" , readDocBook)
182 ,("textile" , readTextile) -- TODO : textile+lhs
165 ,("textile" , readTextile) -- TODO : textile+lhs
183 ,("html" , readHtml)
166 ,("html" , readHtml)
184 ,("latex" , readLaTeX)
167 ,("latex" , readLaTeX)
185− ,("latex+lhs" , \st ->
168+ ,("latex+lhs" , \opt ->
186− readLaTeX st{ stateOptions =
187− let oldopts = stateOptions st
188− in oldopts{ readerLiterateHaskell = True} })
169+ readLaTeX opt{ readerLiterateHaskell = True })
189 ]
170 ]
190
171
191data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
172data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
src/Text/Pandoc/Options.hs+1
@@ -30,6 +30,7 @@ options.
30-}
30-}
31module Text.Pandoc.Options ( Extension(..)
31module Text.Pandoc.Options ( Extension(..)
32 , ReaderOptions(..)
32 , ReaderOptions(..)
33+ , def
33 ) where
34 ) where
34import Data.Set (Set)
35import Data.Set (Set)
35import qualified Data.Set as Set
36import qualified Data.Set as Set
src/Text/Pandoc/Readers/DocBook.hs+2−2
@@ -1,6 +1,6 @@
1module Text.Pandoc.Readers.DocBook ( readDocBook ) where
1module Text.Pandoc.Readers.DocBook ( readDocBook ) where
2import Data.Char (toUpper, isDigit)
2import Data.Char (toUpper, isDigit)
3−import Text.Pandoc.Parsing (ParserState(..))
3+import Text.Pandoc.Options
4import Text.Pandoc.Definition
4import Text.Pandoc.Definition
5import Text.Pandoc.Builder
5import Text.Pandoc.Builder
6import Text.XML.Light
6import Text.XML.Light
@@ -503,7 +503,7 @@ data DBState = DBState{ dbSectionLevel :: Int
503 , dbBook :: Bool
503 , dbBook :: Bool
504 } deriving Show
504 } deriving Show
505
505
506−readDocBook :: ParserState -> String -> Pandoc
506+readDocBook :: ReaderOptions -> String -> Pandoc
507readDocBook _ inp = setTitle (dbDocTitle st')
507readDocBook _ inp = setTitle (dbDocTitle st')
508 $ setAuthors (dbDocAuthors st')
508 $ setAuthors (dbDocAuthors st')
509 $ setDate (dbDocDate st')
509 $ setDate (dbDocDate st')
src/Text/Pandoc/Readers/HTML.hs+3−3
@@ -55,11 +55,11 @@ isSpace '\n' = True
55isSpace _ = False
55isSpace _ = False
56
56
57-- | Convert HTML-formatted string to 'Pandoc' document.
57-- | Convert HTML-formatted string to 'Pandoc' document.
58−readHtml :: ParserState -- ^ Parser state
58+readHtml :: ReaderOptions -- ^ Reader options
59 -> String -- ^ String to parse (assumes @'\n'@ line endings)
59 -> String -- ^ String to parse (assumes @'\n'@ line endings)
60 -> Pandoc
60 -> Pandoc
61−readHtml st inp = Pandoc meta blocks
61+readHtml opts inp = Pandoc meta blocks
62− where blocks = readWith parseBody st rest
62+ where blocks = readWith parseBody def{ stateOptions = opts } rest
63 tags = canonicalizeTags $
63 tags = canonicalizeTags $
64 parseTagsOptions parseOptions{ optTagPosition = True } inp
64 parseTagsOptions parseOptions{ optTagPosition = True } inp
65 hasHeader = any (~== TagOpen "head" []) tags
65 hasHeader = any (~== TagOpen "head" []) tags
src/Text/Pandoc/Readers/LaTeX.hs+2−2
@@ -50,10 +50,10 @@ import qualified Data.Map as M
50import qualified Control.Exception as E
50import qualified Control.Exception as E
51
51
52-- | Parse LaTeX from string and return 'Pandoc' document.
52-- | Parse LaTeX from string and return 'Pandoc' document.
53−readLaTeX :: ParserState -- ^ Parser state, including options for parser
53+readLaTeX :: ReaderOptions -- ^ Reader options
54 -> String -- ^ String to parse (assumes @'\n'@ line endings)
54 -> String -- ^ String to parse (assumes @'\n'@ line endings)
55 -> Pandoc
55 -> Pandoc
56−readLaTeX = readWith parseLaTeX
56+readLaTeX opts = readWith parseLaTeX def{ stateOptions = opts }
57
57
58parseLaTeX :: LP Pandoc
58parseLaTeX :: LP Pandoc
59parseLaTeX = do
59parseLaTeX = do
src/Text/Pandoc/Readers/Markdown.hs+4−3
@@ -49,10 +49,11 @@ import Text.HTML.TagSoup
49import Text.HTML.TagSoup.Match (tagOpen)
49import Text.HTML.TagSoup.Match (tagOpen)
50
50
51-- | Read markdown from an input string and return a Pandoc document.
51-- | Read markdown from an input string and return a Pandoc document.
52−readMarkdown :: ParserState -- ^ Parser state, including options for parser
52+readMarkdown :: ReaderOptions -- ^ Reader options
53− -> String -- ^ String to parse (assuming @'\n'@ line endings)
53+ -> String -- ^ String to parse (assuming @'\n'@ line endings)
54 -> Pandoc
54 -> Pandoc
55+readMarkdown opts s =
55−readMarkdown state s = (readWith parseMarkdown) state (s ++ "\n\n")
56+ (readWith parseMarkdown) def{ stateOptions = opts } (s ++ "\n\n")
56
57
57--
58--
58-- Constants and data structure definitions
59-- 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
27
27
28Conversion from reStructuredText to 'Pandoc' document.
28Conversion from reStructuredText to 'Pandoc' document.
29-}
29-}
30−module Text.Pandoc.Readers.RST (
30+module Text.Pandoc.Readers.RST (
31 readRST
31 readRST
32 ) where
32 ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
@@ -41,10 +41,10 @@ import Text.Printf ( printf )
41import Data.Maybe ( catMaybes )
41import Data.Maybe ( catMaybes )
42
42
43-- | Parse reStructuredText string and return Pandoc document.
43-- | Parse reStructuredText string and return Pandoc document.
44−readRST :: ParserState -- ^ Parser state, including options for parser
44+readRST :: ReaderOptions -- ^ Reader options
45− -> String -- ^ String to parse (assuming @'\n'@ line endings)
45+ -> String -- ^ String to parse (assuming @'\n'@ line endings)
46 -> Pandoc
46 -> Pandoc
47−readRST state s = (readWith parseRST) state (s ++ "\n\n")
47+readRST opts s = (readWith parseRST) def{ stateOptions = opts } (s ++ "\n\n")
48
48
49--
49--
50-- Constants and data structure definitions
50-- Constants and data structure definitions
src/Text/Pandoc/Readers/Textile.hs+8−8
@@ -56,7 +56,7 @@ TODO : refactor common patterns across readers :
56module Text.Pandoc.Readers.Textile ( readTextile) where
56module Text.Pandoc.Readers.Textile ( readTextile) where
57
57
58import Text.Pandoc.Definition
58import Text.Pandoc.Definition
59−import Text.Pandoc.Shared
59+import Text.Pandoc.Shared
60import Text.Pandoc.Options
60import Text.Pandoc.Options
61import Text.Pandoc.Parsing
61import Text.Pandoc.Parsing
62import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
62import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
@@ -67,11 +67,11 @@ import Control.Monad ( guard, liftM )
67import Control.Applicative ((<$>), (*>), (<*))
67import Control.Applicative ((<$>), (*>), (<*))
68
68
69-- | Parse a Textile text and return a Pandoc document.
69-- | Parse a Textile text and return a Pandoc document.
70−readTextile :: ParserState -- ^ Parser state, including options for parser
70+readTextile :: ReaderOptions -- ^ Reader options
71− -> String -- ^ String to parse (assuming @'\n'@ line endings)
71+ -> String -- ^ String to parse (assuming @'\n'@ line endings)
72− -> Pandoc
72+ -> Pandoc
73−readTextile state s =
73+readTextile opts s =
74− (readWith parseTextile) state (s ++ "\n\n")
74+ (readWith parseTextile) def{ stateOptions = opts } (s ++ "\n\n")
75
75
76
76
77-- | Generate a Pandoc ADT from a textile document
77-- | Generate a Pandoc ADT from a textile document
@@ -243,8 +243,8 @@ definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
243definitionListItem = try $ do
243definitionListItem = try $ do
244 string "- "
244 string "- "
245 term <- many1Till inline (try (whitespace >> string ":="))
245 term <- many1Till inline (try (whitespace >> string ":="))
246− def <- inlineDef <|> multilineDef
246+ def' <- inlineDef <|> multilineDef
247− return (term, def)
247+ return (term, def')
248 where inlineDef :: Parser [Char] ParserState [[Block]]
248 where inlineDef :: Parser [Char] ParserState [[Block]]
249 inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
249 inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
250 multilineDef :: Parser [Char] ParserState [[Block]]
250 multilineDef :: Parser [Char] ParserState [[Block]]
src/pandoc.hs+16−18
@@ -936,23 +936,21 @@ main = do
936 then "."
936 then "."
937 else takeDirectory (head sources)
937 else takeDirectory (head sources)
938
938
939− let startParserState = def{ stateOptions = def{
940− readerStrict = strict
939+ let readerOpts = def{ readerStrict = strict
941− , readerSmart = smart || (texLigatures &&
940+ , readerSmart = smart || (texLigatures &&
942− (laTeXOutput || writerName' == "context"))
941+ (laTeXOutput || writerName' == "context"))
943− , readerStandalone = standalone'
942+ , readerStandalone = standalone'
944− , readerParseRaw = parseRaw
943+ , readerParseRaw = parseRaw
945− , readerColumns = columns
944+ , readerColumns = columns
946− , readerTabStop = tabStop
945+ , readerTabStop = tabStop
947− , readerOldDashes = oldDashes
946+ , readerOldDashes = oldDashes
948− , readerLiterateHaskell =
947+ , readerLiterateHaskell =
949− "+lhs" `isSuffixOf` readerName' ||
948+ "+lhs" `isSuffixOf` readerName' ||
950− lhsExtension sources
949+ lhsExtension sources
951− , readerCitations = map CSL.refId refs
950+ , readerCitations = map CSL.refId refs
952− , readerIndentedCodeClasses = codeBlockClasses
951+ , readerIndentedCodeClasses = codeBlockClasses
953− , readerApplyMacros = not laTeXOutput
952+ , readerApplyMacros = not laTeXOutput
954− }
955− }
953+ }
956
954
957 let writerOptions = def { writerStandalone = standalone',
955 let writerOptions = def { writerStandalone = standalone',
958 writerTemplate = templ,
956 writerTemplate = templ,
@@ -1013,7 +1011,7 @@ main = do
1013 then handleIncludes
1011 then handleIncludes
1014 else return
1012 else return
1015
1013
1016− doc <- (reader startParserState) `fmap` (readSources sources >>=
1014+ doc <- (reader readerOpts) `fmap` (readSources sources >>=
1017 handleIncludes' . convertTabs . intercalate "\n")
1015 handleIncludes' . convertTabs . intercalate "\n")
1018
1016
1019 let doc0 = foldr ($) doc transforms
1017 let doc0 = foldr ($) doc transforms