aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-01-28 12:25:24 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-01-28 12:25:24 -0800
commitd1ded4b0260b32550ac45329d7c43a82a7e7e911 (patch)
tree64bac0f8d21e85649cafc58ebb1319e90a62cbfe /src/Text/Pandoc
parentd0e70cbc29ac856b92914111ca46842aafe4b961 (diff)
downloadpandoc-d1ded4b0260b32550ac45329d7c43a82a7e7e911.tar.gz
Support github syntax for fenced code blocks.
You can now write ```ruby x = 2 ``` instead of ~~~ {.ruby} x = 2 ~~~~
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 1fd99a3ab..fb04e88fe 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -371,17 +371,21 @@ hrule = try $ do
indentedLine :: GenParser Char ParserState [Char]
indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
-codeBlockDelimiter :: Maybe Int
- -> GenParser Char st (Int, ([Char], [[Char]], [([Char], [Char])]))
-codeBlockDelimiter len = try $ do
+blockDelimiter :: (Char -> Bool)
+ -> Maybe Int
+ -> GenParser Char st (Int, (String, [String], [(String, String)]), Char)
+blockDelimiter f len = try $ do
+ c <- lookAhead (satisfy f)
size <- case len of
- Just l -> count l (char '~') >> many (char '~') >> return l
- Nothing -> count 3 (char '~') >> many (char '~') >>=
- return . (+ 3) . length
+ 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 ([],[],[]) attributes
+ attr <- option ([],[],[])
+ $ (try $ many spaceChar >> attributes) -- ~~~ {.ruby}
+ <|> (many1 alphaNum >>= \x -> return ([],[x],[])) -- github variant ```ruby
blankline
- return (size, attr)
+ return (size, attr, c)
attributes :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
attributes = try $ do
@@ -425,8 +429,8 @@ keyValAttr = try $ do
codeBlockDelimited :: GenParser Char st Block
codeBlockDelimited = try $ do
- (size, attr) <- codeBlockDelimiter Nothing
- contents <- manyTill anyLine (codeBlockDelimiter (Just size))
+ (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
+ contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
blanklines
return $ CodeBlock attr $ intercalate "\n" contents