diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-08-21 20:11:10 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-08-21 20:11:10 -0700 |
commit | dc8e5970bfeb6bc760bf57b87b5d99f1a2c2ad38 (patch) | |
tree | 7f7576a399f01692ca135a8c06e9ffa1dfe68ecf /src/Text/Pandoc/Readers | |
parent | dc6a133dbfdfcae670ee64e86700fd8234540643 (diff) | |
download | pandoc-dc8e5970bfeb6bc760bf57b87b5d99f1a2c2ad38.tar.gz |
Implemented Ext_backtick_code_blocks.
This is the variant github prefers.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index df3e7687b..2407e137c 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -307,6 +307,7 @@ parseBlocks = mconcat <$> manyTill block eof block :: Parser [Char] ParserState (F Blocks) block = choice [ codeBlockFenced + , codeBlockBackticks , guardEnabled Ext_latex_macros *> (mempty <$ macro) , header , rawTeXBlock @@ -379,21 +380,13 @@ indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n") blockDelimiter :: (Char -> Bool) -> Maybe Int - -> Parser [Char] ParserState (Int, (String, [String], [(String, String)]), Char) + -> Parser [Char] st Int blockDelimiter f len = try $ do c <- lookAhead (satisfy f) - size <- case len of - Just l -> count l (char c) >> many (char c) >> return l - Nothing -> count 3 (char c) >> many (char c) >>= - return . (+ 3) . length - many spaceChar - attr <- option ([],[],[]) $ do - guardEnabled Ext_fenced_code_attributes - attributes -- ~~~ {.ruby} - <|> (many1 alphaNum >>= \x -> - return ([],[x],[])) -- github variant ```ruby - blankline - return (size, attr, c) + case len of + Just l -> count l (char c) >> many (char c) >> return l + Nothing -> count 3 (char c) >> many (char c) >>= + return . (+ 3) . length attributes :: Parser [Char] st (String, [String], [(String, String)]) attributes = try $ do @@ -440,11 +433,26 @@ keyValAttr = try $ do codeBlockFenced :: Parser [Char] ParserState (F Blocks) codeBlockFenced = try $ do guardEnabled Ext_fenced_code_blocks - (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing - contents <- manyTill anyLine (blockDelimiter (== c) (Just size)) + size <- blockDelimiter (=='~') Nothing + skipMany spaceChar + attr <- option ([],[],[]) $ + guardEnabled Ext_fenced_code_attributes >> attributes + blankline + contents <- manyTill anyLine (blockDelimiter (=='~') (Just size)) blanklines return $ return $ B.codeBlockWith attr $ intercalate "\n" contents +codeBlockBackticks :: Parser [Char] ParserState (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 :: Parser [Char] ParserState (F Blocks) codeBlockIndented = do contents <- many1 (indentedLine <|> |