From b06ddad4bca82c4215bcdbd601566f7f1b1eb45d Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 9 Feb 2008 03:18:54 +0000 Subject: Initial support for delimited code blocks in markdown reader. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1203 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Readers/Markdown.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'Text/Pandoc') 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 -- cgit v1.2.3