git.iko.soy/typeable/pandoc
on master help sign in
Moved ParseRaw from ParserState to ReaderOptions.
commitef0619cc6d576061ba7e93b7ecf16f72021c6f68 authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 25 Jul 2012, 11:43 (14 years ago) parent8b380a4
7 files changed+28−24
src/Text/Pandoc/Options.hs+5−3 src/Text/Pandoc/Parsing.hs−2 src/Text/Pandoc/Readers/HTML.hs+4−4 src/Text/Pandoc/Readers/LaTeX.hs+6−5 src/Text/Pandoc/Readers/Markdown.hs+3−1 src/Text/Pandoc/Readers/Textile.hs+3−3 src/pandoc.hs+7−6
src/Text/Pandoc/Options.hs+5−3
@@ -51,9 +51,10 @@ data Extension = Footnotes
5151 deriving (Show, Read, Enum, Eq, Ord, Bounded)
5252
5353data ReaderOptions = ReaderOptions{
54− readerExtensions :: Set Extension
55− , readerSmart :: Bool
56− , readerStrict :: Bool -- FOR TRANSITION ONLY
54+ readerExtensions :: Set Extension -- ^ Syntax extensions
55+ , readerSmart :: Bool -- ^ Smart punctuation
56+ , readerStrict :: Bool -- ^ FOR TRANSITION ONLY
57+ , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
5758 } deriving (Show, Read)
5859
5960instance Default ReaderOptions
@@ -61,4 +62,5 @@ instance Default ReaderOptions
6162 readerExtensions = Set.fromList [minBound..maxBound]
6263 , readerSmart = False
6364 , readerStrict = False
65+ , readerParseRaw = False
6466 }
src/Text/Pandoc/Parsing.hs−2
@@ -689,7 +689,6 @@ testStringWith parser str = UTF8.putStrLn $ show $
689689-- | Parsing options.
690690data ParserState = ParserState
691691 { stateOptions :: ReaderOptions, -- ^ User options
692− stateParseRaw :: Bool, -- ^ Parse raw HTML and LaTeX?
693692 stateParserContext :: ParserContext, -- ^ Inside list?
694693 stateQuoteContext :: QuoteContext, -- ^ Inside quoted environment?
695694 stateMaxNestingLevel :: Int, -- ^ Max # of nested Strong/Emph
@@ -724,7 +723,6 @@ instance Default ParserState where
724723defaultParserState :: ParserState
725724defaultParserState =
726725 ParserState { stateOptions = def,
727− stateParseRaw = False,
728726 stateParserContext = NullState,
729727 stateQuoteContext = NoQuote,
730728 stateMaxNestingLevel = 6,
src/Text/Pandoc/Readers/HTML.hs+4−4
@@ -195,8 +195,8 @@ pRawTag = do
195195pRawHtmlBlock :: TagParser [Block]
196196pRawHtmlBlock = do
197197 raw <- pHtmlBlock "script" <|> pHtmlBlock "style" <|> pRawTag
198− state <- getState
199− if stateParseRaw state && not (null raw)
198+ parseRaw <- getOption readerParseRaw
199+ if parseRaw && not (null raw)
200200 then return [RawBlock "html" raw]
201201 else return []
202202
@@ -380,8 +380,8 @@ pCode = try $ do
380380pRawHtmlInline :: TagParser [Inline]
381381pRawHtmlInline = do
382382 result <- pSatisfy (tagComment (const True)) <|> pSatisfy isInlineTag
383− state <- getState
384− if stateParseRaw state
383+ parseRaw <- getOption readerParseRaw
384+ if parseRaw
385385 then return [RawInline "html" $ renderTags' [result]]
386386 else return []
387387
src/Text/Pandoc/Readers/LaTeX.hs+6−5
@@ -35,6 +35,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
3535
3636import Text.Pandoc.Definition
3737import Text.Pandoc.Shared
38+import Text.Pandoc.Options
3839import Text.Pandoc.Parsing hiding ((<|>), many, optional, space)
3940import qualified Text.Pandoc.UTF8 as UTF8
4041import Data.Char ( chr, ord )
@@ -230,14 +231,14 @@ ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
230231 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
231232 contseq = '\\':name
232233 doraw = (rawInline "latex" . (contseq ++) . snd) <$>
233− (getState >>= guard . stateParseRaw >> (withRaw optargs))
234+ (getOption readerParseRaw >>= guard >> (withRaw optargs))
234235
235236ignoreBlocks :: String -> (String, LP Blocks)
236237ignoreBlocks name = (name, doraw <|> (mempty <$ optargs))
237238 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
238239 contseq = '\\':name
239240 doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
240− (getState >>= guard . stateParseRaw >> (withRaw optargs))
241+ (getOption readerParseRaw >>= guard >> (withRaw optargs))
241242
242243blockCommands :: M.Map String (LP Blocks)
243244blockCommands = M.fromList $
@@ -321,7 +322,7 @@ inlineCommand :: LP Inlines
321322inlineCommand = try $ do
322323 name <- anyControlSeq
323324 guard $ not $ isBlockCommand name
324− parseRaw <- stateParseRaw `fmap` getState
325+ parseRaw <- getOption readerParseRaw
325326 star <- option "" (string "*")
326327 let name' = name ++ star
327328 let rawargs = withRaw (skipopts *> option "" dimenarg
@@ -336,7 +337,7 @@ inlineCommand = try $ do
336337 Nothing -> raw
337338
338339unlessParseRaw :: LP ()
339−unlessParseRaw = getState >>= guard . not . stateParseRaw
340+unlessParseRaw = getOption readerParseRaw >>= guard . not
340341
341342isBlockCommand :: String -> Bool
342343isBlockCommand s = maybe False (const True) $ M.lookup s blockCommands
@@ -660,7 +661,7 @@ environment = do
660661rawEnv :: String -> LP Blocks
661662rawEnv name = do
662663 let addBegin x = "\\begin{" ++ name ++ "}" ++ x
663− parseRaw <- stateParseRaw `fmap` getState
664+ parseRaw <- getOption readerParseRaw
664665 if parseRaw
665666 then (rawBlock "latex" . addBegin) <$>
666667 (withRaw (env name blocks) >>= applyMacros' . snd)
src/Text/Pandoc/Readers/Markdown.hs+3−1
@@ -176,7 +176,9 @@ titleBlock = try $ do
176176parseMarkdown :: Parser [Char] ParserState Pandoc
177177parseMarkdown = do
178178 -- markdown allows raw HTML
179− updateState (\state -> state { stateParseRaw = True })
179+ updateState $ \state -> state { stateOptions =
180+ let oldOpts = stateOptions state in
181+ oldOpts{ readerParseRaw = True } }
180182 startPos <- getPosition
181183 -- go through once just to get list of reference keys and notes
182184 -- docMinusKeys is the raw document with blanks where the keys/notes were...
src/Text/Pandoc/Readers/Textile.hs+3−3
@@ -79,9 +79,9 @@ parseTextile :: Parser [Char] ParserState Pandoc
7979parseTextile = do
8080 -- textile allows raw HTML and does smart punctuation by default
8181 oldOpts <- stateOptions `fmap` getState
82− updateState $ \state -> state { stateParseRaw = True
83− , stateOptions = oldOpts{ readerSmart = True }
84− }
82+ updateState $ \state -> state{ stateOptions = oldOpts{ readerSmart = True
83+ , readerParseRaw = True
84+ } }
8585 many blankline
8686 startPos <- getPosition
8787 -- go through once just to get list of reference keys and notes
src/pandoc.hs+7−6
@@ -936,18 +936,19 @@ main = do
936936 then "."
937937 else takeDirectory (head sources)
938938
939− let startParserState = def{ stateParseRaw = parseRaw,
940− stateTabStop = tabStop,
939+ let startParserState = def{ stateTabStop = tabStop,
941940 stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
942941 lhsExtension sources,
943942 stateStandalone = standalone',
944943 stateCitations = map CSL.refId refs,
945944 stateOldDashes = oldDashes,
946945 stateColumns = columns,
947− stateOptions = def{ readerStrict = strict
948− , readerSmart = smart ||
949− (texLigatures &&
950− (laTeXOutput || writerName' == "context")) },
946+ stateOptions = def{
947+ readerStrict = strict
948+ , readerSmart = smart || (texLigatures &&
949+ (laTeXOutput || writerName' == "context"))
950+ , readerParseRaw = parseRaw
951+ },
951952 stateIndentedCodeClasses = codeBlockClasses,
952953 stateApplyMacros = not laTeXOutput
953954 }