From 7a0062a8d5d6f3ea8b754b23eb6af6f8e07a8102 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 23 Jan 2013 13:07:07 -0800 Subject: Fixed regressions in fenced code blocks. * Tilde code fences can again take bare language. So ~~~ haskell is okay, not just ~~~ {.haskell} * Backtick code blocks can take the bracketed attributes. * Backtick code blocks don't require a language. * Consolidated code for the two kinds of fenced code blocks. Closes #722. --- src/Text/Pandoc/Readers/Markdown.hs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 4eb17c16b..0708690d4 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -355,7 +355,6 @@ parseBlocks = mconcat <$> manyTill block eof block :: MarkdownParser (F Blocks) block = choice [ codeBlockFenced - , codeBlockBackticks , guardEnabled Ext_latex_macros *> (mempty <$ macro) , header , lhsCodeBlock @@ -520,27 +519,18 @@ keyValAttr = try $ do codeBlockFenced :: MarkdownParser (F Blocks) codeBlockFenced = try $ do - guardEnabled Ext_fenced_code_blocks - size <- blockDelimiter (=='~') Nothing + c <- try (guardEnabled Ext_fenced_code_blocks >> lookAhead (char '~')) + <|> (guardEnabled Ext_backtick_code_blocks >> lookAhead (char '`')) + size <- blockDelimiter (== c) Nothing skipMany spaceChar attr <- option ([],[],[]) $ - guardEnabled Ext_fenced_code_attributes >> attributes + try (guardEnabled Ext_fenced_code_attributes >> attributes) + <|> ((\x -> ("",[x],[])) <$> identifier) blankline - contents <- manyTill anyLine (blockDelimiter (=='~') (Just size)) + contents <- manyTill anyLine (blockDelimiter (== c) (Just size)) blanklines return $ return $ B.codeBlockWith attr $ intercalate "\n" contents -codeBlockBackticks :: MarkdownParser (F Blocks) -codeBlockBackticks = try $ do - guardEnabled Ext_backtick_code_blocks - blockDelimiter (=='`') (Just 3) - skipMany spaceChar - cls <- many1 alphaNum - blankline - contents <- manyTill anyLine $ blockDelimiter (=='`') (Just 3) - blanklines - return $ return $ B.codeBlockWith ("",[cls],[]) $ intercalate "\n" contents - codeBlockIndented :: MarkdownParser (F Blocks) codeBlockIndented = do contents <- many1 (indentedLine <|> -- cgit v1.2.3