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`.
This commit is contained in:
John MacFarlane 2014-07-20 17:44:28 -07:00
parent a243afb551
commit b6c769084e
2 changed files with 17 additions and 4 deletions

View file

@ -879,6 +879,7 @@ data ParserState = ParserState
-- annotate role classes too).
stateCaption :: Maybe Inlines, -- ^ Caption in current environment
stateInHtmlBlock :: Maybe String, -- ^ Tag type of HTML block being parsed
stateMarkdownAttribute :: Bool, -- ^ True if in markdown=1 context
stateWarnings :: [String] -- ^ Warnings generated by the parser
}
@ -958,6 +959,7 @@ defaultParserState =
stateRstCustomRoles = M.empty,
stateCaption = Nothing,
stateInHtmlBlock = Nothing,
stateMarkdownAttribute = False,
stateWarnings = []}
-- | Succeed only if the extension is enabled.

View file

@ -939,10 +939,21 @@ htmlBlock = do
(TagOpen t attrs) <- lookAhead $ fst <$> htmlTag isBlockTag
(guard (t `elem` ["pre","style","script"]) >>
(return . B.rawBlock "html") <$> rawVerbatimBlock)
<|> (guardEnabled Ext_markdown_attribute >>
case lookup "markdown" attrs of
Just "1" -> rawHtmlBlocks
_ -> htmlBlock')
<|> (do guardEnabled Ext_markdown_attribute
oldMarkdownAttribute <- stateMarkdownAttribute <$> getState
markdownAttribute <-
case lookup "markdown" attrs of
Just "0" -> False <$ updateState (\st -> st{
stateMarkdownAttribute = False })
Just _ -> True <$ updateState (\st -> st{
stateMarkdownAttribute = True })
Nothing -> return oldMarkdownAttribute
res <- if markdownAttribute
then rawHtmlBlocks
else htmlBlock'
updateState $ \st -> st{ stateMarkdownAttribute =
oldMarkdownAttribute }
return res)
<|> (guardEnabled Ext_markdown_in_html_blocks >> rawHtmlBlocks))
<|> htmlBlock'