git.iko.soy/typeable/pandoc
on master help sign in
Options -> ReaderOptions.

Better to keep reader and writer options separate.

commitdfa19061abc24a3e95b9b37e4f9484d902110899 authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 25 Jul 2012, 11:08 (14 years ago) parentda37023
7 files changed+29−29
src/Tests/Readers/Markdown.hs+1−1 src/Text/Pandoc/Options.hs+10−10 src/Text/Pandoc/Parsing.hs+3−3 src/Text/Pandoc/Readers/HTML.hs+2−2 src/Text/Pandoc/Readers/Markdown.hs+10−10 src/Text/Pandoc/Readers/Textile.hs+1−1 src/pandoc.hs+2−2
src/Tests/Readers/Markdown.hs+1−1
@@ -15,7 +15,7 @@ markdown = readMarkdown defaultParserState{ stateStandalone = True }
1515markdownSmart :: String -> Pandoc
1616markdownSmart = readMarkdown defaultParserState{ stateOptions =
1717 let oldOpts = stateOptions defaultParserState in
18− oldOpts { optionSmart = True } }
18+ oldOpts { readerSmart = True } }
1919
2020infix 4 =:
2121(=:) :: ToString c
src/Text/Pandoc/Options.hs+10−10
@@ -29,7 +29,7 @@ Data structures and functions for representing parser and writer
2929options.
3030-}
3131module Text.Pandoc.Options ( Extension(..)
32− , Options(..)
32+ , ReaderOptions(..)
3333 ) where
3434import Data.Set (Set)
3535import qualified Data.Set as Set
@@ -50,15 +50,15 @@ data Extension = Footnotes
5050 | Significant_bullets
5151 deriving (Show, Read, Enum, Eq, Ord, Bounded)
5252
53−data Options = Options{
54− optionExtensions :: Set Extension
55− , optionSmart :: Bool
56− , optionStrict :: Bool -- FOR TRANSITION ONLY
53+data ReaderOptions = ReaderOptions{
54+ readerExtensions :: Set Extension
55+ , readerSmart :: Bool
56+ , readerStrict :: Bool -- FOR TRANSITION ONLY
5757 } deriving (Show, Read)
5858
59−instance Default Options
60− where def = Options{
61− optionExtensions = Set.fromList [minBound..maxBound]
62− , optionSmart = False
63− , optionStrict = False
59+instance Default ReaderOptions
60+ where def = ReaderOptions{
61+ readerExtensions = Set.fromList [minBound..maxBound]
62+ , readerSmart = False
63+ , readerStrict = False
6464 }
src/Text/Pandoc/Parsing.hs+3−3
@@ -392,7 +392,7 @@ nullBlock = anyChar >> return Null
392392failIfStrict :: Parsec [a] ParserState ()
393393failIfStrict = do
394394 state <- getState
395− if optionStrict (stateOptions state) then fail "strict mode" else return ()
395+ if readerStrict (stateOptions state) then fail "strict mode" else return ()
396396
397397-- | Fail unless we're in literate haskell mode.
398398failUnlessLHS :: Parsec [tok] ParserState ()
@@ -689,7 +689,7 @@ testStringWith parser str = UTF8.putStrLn $ show $
689689
690690-- | Parsing options.
691691data ParserState = ParserState
692− { stateOptions :: Options, -- ^ User options
692+ { stateOptions :: ReaderOptions, -- ^ User options
693693 stateParseRaw :: Bool, -- ^ Parse raw HTML and LaTeX?
694694 stateParserContext :: ParserContext, -- ^ Inside list?
695695 stateQuoteContext :: QuoteContext, -- ^ Inside quoted environment?
@@ -795,7 +795,7 @@ lookupKeySrc table key = case M.lookup key table of
795795
796796-- | Fail unless we're in "smart typography" mode.
797797failUnlessSmart :: Parsec [tok] ParserState ()
798−failUnlessSmart = getState >>= guard . optionSmart . stateOptions
798+failUnlessSmart = getState >>= guard . readerSmart . stateOptions
799799
800800smartPunctuation :: Parsec [Char] ParserState Inline
801801 -> Parsec [Char] ParserState Inline
src/Text/Pandoc/Readers/HTML.hs+2−2
@@ -126,7 +126,7 @@ pOrderedList :: TagParser [Block]
126126pOrderedList = try $ do
127127 TagOpen _ attribs <- pSatisfy (~== TagOpen "ol" [])
128128 st <- getState
129− let (start, style) = if optionStrict (stateOptions st)
129+ let (start, style) = if readerStrict (stateOptions st)
130130 then (1, DefaultStyle)
131131 else (sta', sty')
132132 where sta = fromMaybe "1" $
@@ -281,7 +281,7 @@ pCodeBlock = try $ do
281281 let attribsClasses = words $ fromMaybe "" $ lookup "class" attr
282282 let attribsKV = filter (\(k,_) -> k /= "class" && k /= "id") attr
283283 st <- getState
284− let attribs = if optionStrict (stateOptions st)
284+ let attribs = if readerStrict (stateOptions st)
285285 then ("",[],[])
286286 else (attribsId, attribsClasses, attribsKV)
287287 return [CodeBlock attribs result]
src/Text/Pandoc/Readers/Markdown.hs+10−10
@@ -182,7 +182,7 @@ parseMarkdown = do
182182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
183183 st <- getState
184184 let firstPassParser = referenceKey
185− <|> (if optionStrict (stateOptions st) then mzero else noteBlock)
185+ <|> (if readerStrict (stateOptions st) then mzero else noteBlock)
186186 <|> liftM snd (withRaw codeBlockDelimited)
187187 <|> lineClump
188188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
@@ -293,7 +293,7 @@ parseBlocks = manyTill block eof
293293block :: Parser [Char] ParserState Block
294294block = do
295295 st <- getState
296− choice (if optionStrict (stateOptions st)
296+ choice (if readerStrict (stateOptions st)
297297 then [ header
298298 , codeBlockIndented
299299 , blockQuote
@@ -534,7 +534,7 @@ anyOrderedListStart = try $ do
534534 skipNonindentSpaces
535535 notFollowedBy $ string "p." >> spaceChar >> digit -- page number
536536 state <- getState
537− if optionStrict (stateOptions state)
537+ if readerStrict (stateOptions state)
538538 then do many1 digit
539539 char '.'
540540 spaceChar
@@ -695,7 +695,7 @@ para = try $ do
695695 option (Plain result) $ try $ do
696696 newline
697697 blanklines <|>
698− (getState >>= guard . optionStrict . stateOptions >>
698+ (getState >>= guard . readerStrict . stateOptions >>
699699 lookAhead (blockQuote <|> header) >> return "")
700700 return $ Para result
701701
@@ -1009,7 +1009,7 @@ escapedChar' :: Parser [Char] ParserState Char
10091009escapedChar' = try $ do
10101010 char '\\'
10111011 state <- getState
1012− if optionStrict (stateOptions state)
1012+ if readerStrict (stateOptions state)
10131013 then oneOf "\\`*_{}[]()>#+-.!~"
10141014 else satisfy (not . isAlphaNum)
10151015
@@ -1024,7 +1024,7 @@ escapedChar = do
10241024ltSign :: Parser [Char] ParserState Inline
10251025ltSign = do
10261026 st <- getState
1027− if optionStrict (stateOptions st)
1027+ if readerStrict (stateOptions st)
10281028 then char '<'
10291029 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
10301030 return $ Str ['<']
@@ -1160,7 +1160,7 @@ nonEndline = satisfy (/='\n')
11601160
11611161str :: Parser [Char] ParserState Inline
11621162str = do
1163− smart <- (optionSmart . stateOptions) `fmap` getState
1163+ smart <- (readerSmart . stateOptions) `fmap` getState
11641164 a <- alphaNum
11651165 as <- many $ alphaNum
11661166 <|> (try $ char '_' >>~ lookAhead alphaNum)
@@ -1201,7 +1201,7 @@ endline = try $ do
12011201 newline
12021202 notFollowedBy blankline
12031203 st <- getState
1204− when (optionStrict (stateOptions st)) $ do
1204+ when (readerStrict (stateOptions st)) $ do
12051205 notFollowedBy emailBlockQuoteStart
12061206 notFollowedBy (char '#') -- atx header
12071207 -- parse potential list-starts differently if in a list:
@@ -1283,7 +1283,7 @@ autoLink = try $ do
12831283 (orig, src) <- uri <|> emailAddress
12841284 char '>'
12851285 st <- getState
1286− return $ if optionStrict (stateOptions st)
1286+ return $ if readerStrict (stateOptions st)
12871287 then Link [Str orig] (src, "")
12881288 else Link [Code ("",["url"],[]) orig] (src, "")
12891289
@@ -1344,7 +1344,7 @@ inBrackets parser = do
13441344rawHtmlInline :: Parser [Char] ParserState Inline
13451345rawHtmlInline = do
13461346 st <- getState
1347− (_,result) <- if optionStrict (stateOptions st)
1347+ (_,result) <- if readerStrict (stateOptions st)
13481348 then htmlTag (not . isTextTag)
13491349 else htmlTag isInlineTag
13501350 return $ RawInline "html" result
src/Text/Pandoc/Readers/Textile.hs+1−1
@@ -80,7 +80,7 @@ parseTextile = do
8080 -- textile allows raw HTML and does smart punctuation by default
8181 oldOpts <- stateOptions `fmap` getState
8282 updateState $ \state -> state { stateParseRaw = True
83− , stateOptions = oldOpts{ optionSmart = True }
83+ , stateOptions = oldOpts{ readerSmart = True }
8484 }
8585 many blankline
8686 startPos <- getPosition
src/pandoc.hs+2−2
@@ -944,8 +944,8 @@ main = do
944944 stateCitations = map CSL.refId refs,
945945 stateOldDashes = oldDashes,
946946 stateColumns = columns,
947− stateOptions = def{ optionStrict = strict
948− , optionSmart = smart ||
947+ stateOptions = def{ readerStrict = strict
948+ , readerSmart = smart ||
949949 (texLigatures &&
950950 (laTeXOutput || writerName' == "context")) },
951951 stateIndentedCodeClasses = codeBlockClasses,