git.iko.soy/typeable/pandoc
on master help sign in
Fix behavior of `markdown_attribute` extension.

It now works as in PHP markdown extra. Setting `markdown="1"` on an outer tag affects all contained tags until it is reversed with `markdown="0"`. Closes #1378. Added `stateMarkdownAttribute` to `ParserState`.

commitb6c769084eff0fe865c13590dee0737e41ba4e43 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 20 Jul 2014, 17:44 (12 years ago) parenta243afb
2 files changed+17−4
src/Text/Pandoc/Parsing.hs+2 src/Text/Pandoc/Readers/Markdown.hs+15−4
src/Text/Pandoc/Parsing.hs+2
@@ -879,6 +879,7 @@ data ParserState = ParserState
879879 -- annotate role classes too).
880880 stateCaption :: Maybe Inlines, -- ^ Caption in current environment
881881 stateInHtmlBlock :: Maybe String, -- ^ Tag type of HTML block being parsed
882+ stateMarkdownAttribute :: Bool, -- ^ True if in markdown=1 context
882883 stateWarnings :: [String] -- ^ Warnings generated by the parser
883884 }
884885
@@ -958,6 +959,7 @@ defaultParserState =
958959 stateRstCustomRoles = M.empty,
959960 stateCaption = Nothing,
960961 stateInHtmlBlock = Nothing,
962+ stateMarkdownAttribute = False,
961963 stateWarnings = []}
962964
963965-- | Succeed only if the extension is enabled.
src/Text/Pandoc/Readers/Markdown.hs+15−4
@@ -939,10 +939,21 @@ htmlBlock = do
939939 (TagOpen t attrs) <- lookAhead $ fst <$> htmlTag isBlockTag
940940 (guard (t `elem` ["pre","style","script"]) >>
941941 (return . B.rawBlock "html") <$> rawVerbatimBlock)
942− <|> (guardEnabled Ext_markdown_attribute >>
943− case lookup "markdown" attrs of
944− Just "1" -> rawHtmlBlocks
945− _ -> htmlBlock')
942+ <|> (do guardEnabled Ext_markdown_attribute
943+ oldMarkdownAttribute <- stateMarkdownAttribute <$> getState
944+ markdownAttribute <-
945+ case lookup "markdown" attrs of
946+ Just "0" -> False <$ updateState (\st -> st{
947+ stateMarkdownAttribute = False })
948+ Just _ -> True <$ updateState (\st -> st{
949+ stateMarkdownAttribute = True })
950+ Nothing -> return oldMarkdownAttribute
951+ res <- if markdownAttribute
952+ then rawHtmlBlocks
953+ else htmlBlock'
954+ updateState $ \st -> st{ stateMarkdownAttribute =
955+ oldMarkdownAttribute }
956+ return res)
946957 <|> (guardEnabled Ext_markdown_in_html_blocks >> rawHtmlBlocks))
947958 <|> htmlBlock'
948959