git.iko.soy/typeable/pandoc
on master help sign in
Moved ParseRaw from ParserState to ReaderOptions.
ef0619cJohn MacFarlane
src/Text/Pandoc/Options.hs+5−3
@@ -51,9 +51,10 @@ data Extension = Footnotes
51 deriving (Show, Read, Enum, Eq, Ord, Bounded)
51 deriving (Show, Read, Enum, Eq, Ord, Bounded)
52
52
53data ReaderOptions = ReaderOptions{
53data ReaderOptions = ReaderOptions{
54− readerExtensions :: Set Extension
54+ readerExtensions :: Set Extension -- ^ Syntax extensions
55− , readerSmart :: Bool
55+ , readerSmart :: Bool -- ^ Smart punctuation
56− , readerStrict :: Bool -- FOR TRANSITION ONLY
56+ , readerStrict :: Bool -- ^ FOR TRANSITION ONLY
57+ , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
57 } deriving (Show, Read)
58 } deriving (Show, Read)
58
59
59instance Default ReaderOptions
60instance Default ReaderOptions
@@ -61,4 +62,5 @@ instance Default ReaderOptions
61 readerExtensions = Set.fromList [minBound..maxBound]
62 readerExtensions = Set.fromList [minBound..maxBound]
62 , readerSmart = False
63 , readerSmart = False
63 , readerStrict = False
64 , readerStrict = False
65+ , readerParseRaw = False
64 }
66 }
src/Text/Pandoc/Parsing.hs−2
@@ -689,7 +689,6 @@ testStringWith parser str = UTF8.putStrLn $ show $
689-- | Parsing options.
689-- | Parsing options.
690data ParserState = ParserState
690data ParserState = ParserState
691 { stateOptions :: ReaderOptions, -- ^ User options
691 { stateOptions :: ReaderOptions, -- ^ User options
692− stateParseRaw :: Bool, -- ^ Parse raw HTML and LaTeX?
693 stateParserContext :: ParserContext, -- ^ Inside list?
692 stateParserContext :: ParserContext, -- ^ Inside list?
694 stateQuoteContext :: QuoteContext, -- ^ Inside quoted environment?
693 stateQuoteContext :: QuoteContext, -- ^ Inside quoted environment?
695 stateMaxNestingLevel :: Int, -- ^ Max # of nested Strong/Emph
694 stateMaxNestingLevel :: Int, -- ^ Max # of nested Strong/Emph
@@ -724,7 +723,6 @@ instance Default ParserState where
724defaultParserState :: ParserState
723defaultParserState :: ParserState
725defaultParserState =
724defaultParserState =
726 ParserState { stateOptions = def,
725 ParserState { stateOptions = def,
727− stateParseRaw = False,
728 stateParserContext = NullState,
726 stateParserContext = NullState,
729 stateQuoteContext = NoQuote,
727 stateQuoteContext = NoQuote,
730 stateMaxNestingLevel = 6,
728 stateMaxNestingLevel = 6,
src/Text/Pandoc/Readers/HTML.hs+4−4
@@ -195,8 +195,8 @@ pRawTag = do
195pRawHtmlBlock :: TagParser [Block]
195pRawHtmlBlock :: TagParser [Block]
196pRawHtmlBlock = do
196pRawHtmlBlock = do
197 raw <- pHtmlBlock "script" <|> pHtmlBlock "style" <|> pRawTag
197 raw <- pHtmlBlock "script" <|> pHtmlBlock "style" <|> pRawTag
198− state <- getState
198+ parseRaw <- getOption readerParseRaw
199− if stateParseRaw state && not (null raw)
199+ if parseRaw && not (null raw)
200 then return [RawBlock "html" raw]
200 then return [RawBlock "html" raw]
201 else return []
201 else return []
202
202
@@ -380,8 +380,8 @@ pCode = try $ do
380pRawHtmlInline :: TagParser [Inline]
380pRawHtmlInline :: TagParser [Inline]
381pRawHtmlInline = do
381pRawHtmlInline = do
382 result <- pSatisfy (tagComment (const True)) <|> pSatisfy isInlineTag
382 result <- pSatisfy (tagComment (const True)) <|> pSatisfy isInlineTag
383− state <- getState
383+ parseRaw <- getOption readerParseRaw
384− if stateParseRaw state
384+ if parseRaw
385 then return [RawInline "html" $ renderTags' [result]]
385 then return [RawInline "html" $ renderTags' [result]]
386 else return []
386 else return []
387
387
src/Text/Pandoc/Readers/LaTeX.hs+6−5
@@ -35,6 +35,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
35
35
36import Text.Pandoc.Definition
36import Text.Pandoc.Definition
37import Text.Pandoc.Shared
37import Text.Pandoc.Shared
38+import Text.Pandoc.Options
38import Text.Pandoc.Parsing hiding ((<|>), many, optional, space)
39import Text.Pandoc.Parsing hiding ((<|>), many, optional, space)
39import qualified Text.Pandoc.UTF8 as UTF8
40import qualified Text.Pandoc.UTF8 as UTF8
40import Data.Char ( chr, ord )
41import Data.Char ( chr, ord )
@@ -230,14 +231,14 @@ ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
230 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
231 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
231 contseq = '\\':name
232 contseq = '\\':name
232 doraw = (rawInline "latex" . (contseq ++) . snd) <$>
233 doraw = (rawInline "latex" . (contseq ++) . snd) <$>
233− (getState >>= guard . stateParseRaw >> (withRaw optargs))
234+ (getOption readerParseRaw >>= guard >> (withRaw optargs))
234
235
235ignoreBlocks :: String -> (String, LP Blocks)
236ignoreBlocks :: String -> (String, LP Blocks)
236ignoreBlocks name = (name, doraw <|> (mempty <$ optargs))
237ignoreBlocks name = (name, doraw <|> (mempty <$ optargs))
237 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
238 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
238 contseq = '\\':name
239 contseq = '\\':name
239 doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
240 doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
240− (getState >>= guard . stateParseRaw >> (withRaw optargs))
241+ (getOption readerParseRaw >>= guard >> (withRaw optargs))
241
242
242blockCommands :: M.Map String (LP Blocks)
243blockCommands :: M.Map String (LP Blocks)
243blockCommands = M.fromList $
244blockCommands = M.fromList $
@@ -321,7 +322,7 @@ inlineCommand :: LP Inlines
321inlineCommand = try $ do
322inlineCommand = try $ do
322 name <- anyControlSeq
323 name <- anyControlSeq
323 guard $ not $ isBlockCommand name
324 guard $ not $ isBlockCommand name
324− parseRaw <- stateParseRaw `fmap` getState
325+ parseRaw <- getOption readerParseRaw
325 star <- option "" (string "*")
326 star <- option "" (string "*")
326 let name' = name ++ star
327 let name' = name ++ star
327 let rawargs = withRaw (skipopts *> option "" dimenarg
328 let rawargs = withRaw (skipopts *> option "" dimenarg
@@ -336,7 +337,7 @@ inlineCommand = try $ do
336 Nothing -> raw
337 Nothing -> raw
337
338
338unlessParseRaw :: LP ()
339unlessParseRaw :: LP ()
339−unlessParseRaw = getState >>= guard . not . stateParseRaw
340+unlessParseRaw = getOption readerParseRaw >>= guard . not
340
341
341isBlockCommand :: String -> Bool
342isBlockCommand :: String -> Bool
342isBlockCommand s = maybe False (const True) $ M.lookup s blockCommands
343isBlockCommand s = maybe False (const True) $ M.lookup s blockCommands
@@ -660,7 +661,7 @@ environment = do
660rawEnv :: String -> LP Blocks
661rawEnv :: String -> LP Blocks
661rawEnv name = do
662rawEnv name = do
662 let addBegin x = "\\begin{" ++ name ++ "}" ++ x
663 let addBegin x = "\\begin{" ++ name ++ "}" ++ x
663− parseRaw <- stateParseRaw `fmap` getState
664+ parseRaw <- getOption readerParseRaw
664 if parseRaw
665 if parseRaw
665 then (rawBlock "latex" . addBegin) <$>
666 then (rawBlock "latex" . addBegin) <$>
666 (withRaw (env name blocks) >>= applyMacros' . snd)
667 (withRaw (env name blocks) >>= applyMacros' . snd)
src/Text/Pandoc/Readers/Markdown.hs+3−1
@@ -176,7 +176,9 @@ titleBlock = try $ do
176parseMarkdown :: Parser [Char] ParserState Pandoc
176parseMarkdown :: Parser [Char] ParserState Pandoc
177parseMarkdown = do
177parseMarkdown = do
178 -- markdown allows raw HTML
178 -- 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 } }
180 startPos <- getPosition
182 startPos <- getPosition
181 -- go through once just to get list of reference keys and notes
183 -- go through once just to get list of reference keys and notes
182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
184 -- 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
79parseTextile = do
79parseTextile = do
80 -- textile allows raw HTML and does smart punctuation by default
80 -- textile allows raw HTML and does smart punctuation by default
81 oldOpts <- stateOptions `fmap` getState
81 oldOpts <- stateOptions `fmap` getState
82− updateState $ \state -> state { stateParseRaw = True
83− , stateOptions = oldOpts{ readerSmart = True }
82+ updateState $ \state -> state{ stateOptions = oldOpts{ readerSmart = True
83+ , readerParseRaw = True
84− }
84+ } }
85 many blankline
85 many blankline
86 startPos <- getPosition
86 startPos <- getPosition
87 -- go through once just to get list of reference keys and notes
87 -- go through once just to get list of reference keys and notes
src/pandoc.hs+7−6
@@ -936,18 +936,19 @@ main = do
936 then "."
936 then "."
937 else takeDirectory (head sources)
937 else takeDirectory (head sources)
938
938
939− let startParserState = def{ stateParseRaw = parseRaw,
940− stateTabStop = tabStop,
939+ let startParserState = def{ stateTabStop = tabStop,
941 stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
940 stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
942 lhsExtension sources,
941 lhsExtension sources,
943 stateStandalone = standalone',
942 stateStandalone = standalone',
944 stateCitations = map CSL.refId refs,
943 stateCitations = map CSL.refId refs,
945 stateOldDashes = oldDashes,
944 stateOldDashes = oldDashes,
946 stateColumns = columns,
945 stateColumns = columns,
946+ stateOptions = def{
947− stateOptions = def{ readerStrict = strict
947+ readerStrict = strict
948− , readerSmart = smart ||
948+ , readerSmart = smart || (texLigatures &&
949− (texLigatures &&
950− (laTeXOutput || writerName' == "context")) },
949+ (laTeXOutput || writerName' == "context"))
950+ , readerParseRaw = parseRaw
951+ },
951 stateIndentedCodeClasses = codeBlockClasses,
952 stateIndentedCodeClasses = codeBlockClasses,
952 stateApplyMacros = not laTeXOutput
953 stateApplyMacros = not laTeXOutput
953 }
954 }