aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-02-09 03:18:54 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-02-09 03:18:54 +0000
commitb06ddad4bca82c4215bcdbd601566f7f1b1eb45d (patch)
tree2d08448cb74347897212013c80074ff641351c26
parent769e2f3cf591c4f03fc6991482a406275ea57085 (diff)
downloadpandoc-b06ddad4bca82c4215bcdbd601566f7f1b1eb45d.tar.gz
Initial support for delimited code blocks in markdown reader.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1203 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--Text/Pandoc/Readers/Markdown.hs28
1 files changed, 27 insertions, 1 deletions
diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs
index 8d7a274bf..e58a80b99 100644
--- a/Text/Pandoc/Readers/Markdown.hs
+++ b/Text/Pandoc/Readers/Markdown.hs
@@ -295,7 +295,33 @@ hrule = try $ do
indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
-codeBlock = do
+codeBlock = codeBlockIndented <|> codeBlockDelimited
+
+codeBlockDelimiter len = try $ do
+ size <- case len of
+ Just l -> count l (char '~') >> return l
+ Nothing -> count 3 (char '~') >> many (char '~') >>=
+ return . (+ 3) . length
+ many spaceChar
+ lang <- option "" classAttribute
+ blankline
+ return (size, lang)
+
+classAttribute = try $ do
+ char '{'
+ many spaceChar
+ char '.'
+ attr <- many1 alphaNum
+ many spaceChar
+ char '}'
+ return attr
+
+codeBlockDelimited = try $ do
+ (size, lang) <- codeBlockDelimiter Nothing
+ contents <- manyTill anyLine (codeBlockDelimiter (Just size))
+ return $ CodeBlock lang $ concat contents
+
+codeBlockIndented = do
contents <- many1 (indentedLine <|>
try (do b <- blanklines
l <- indentedLine