aboutsummaryrefslogtreecommitdiff
path: root/Text/Pandoc/Readers/Markdown.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-02-09 03:19:43 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-02-09 03:19:43 +0000
commit614547b38eff096d5bcdd1fc97eadc8eab89028a (patch)
treeeff9841eb7ec72bae9fb54cdf53fd292a42479c5 /Text/Pandoc/Readers/Markdown.hs
parent705340824d1523262f2c32e9821b1f035937bec8 (diff)
downloadpandoc-614547b38eff096d5bcdd1fc97eadc8eab89028a.tar.gz
Use generic attributes type, not a string, for CodeBlocks.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1209 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Text/Pandoc/Readers/Markdown.hs')
-rw-r--r--Text/Pandoc/Readers/Markdown.hs45
1 files changed, 34 insertions, 11 deletions
diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs
index c4d8778aa..7ac78f2af 100644
--- a/Text/Pandoc/Readers/Markdown.hs
+++ b/Text/Pandoc/Readers/Markdown.hs
@@ -303,25 +303,48 @@ codeBlockDelimiter len = try $ do
Nothing -> count 3 (char '~') >> many (char '~') >>=
return . (+ 3) . length
many spaceChar
- lang <- option "" classAttributes
+ attr <- option ([],[],[]) attributes
blankline
- return (size, lang)
+ return (size, attr)
-classAttributes = try $ do
+attributes = try $ do
char '{'
many spaceChar
- attrs <- many $ try $ do char '.'
- attr <- many1 alphaNum
- many spaceChar
- return attr
+ attrs <- many (attribute >>~ many spaceChar)
char '}'
- return $ unwords attrs
+ let (ids, classes, keyvals) = unzip3 attrs
+ let id = if null ids then "" else head ids
+ return (id, concat classes, concat keyvals)
+
+attribute = identifierAttr <|> classAttr <|> keyValAttr
+
+identifier = do
+ first <- letter
+ rest <- many alphaNum
+ return (first:rest)
+
+identifierAttr = try $ do
+ char '#'
+ result <- identifier
+ return (result,[],[])
+
+classAttr = try $ do
+ char '.'
+ result <- identifier
+ return ("",[result],[])
+
+keyValAttr = try $ do
+ key <- identifier
+ char '='
+ char '"'
+ val <- manyTill (noneOf "\n") (char '"')
+ return ("",[],[(key,val)])
codeBlockDelimited = try $ do
- (size, lang) <- codeBlockDelimiter Nothing
+ (size, attr) <- codeBlockDelimiter Nothing
contents <- manyTill anyLine (codeBlockDelimiter (Just size))
blanklines
- return $ CodeBlock lang $ joinWithSep "\n" contents
+ return $ CodeBlock attr $ joinWithSep "\n" contents
codeBlockIndented = do
contents <- many1 (indentedLine <|>
@@ -329,7 +352,7 @@ codeBlockIndented = do
l <- indentedLine
return $ b ++ l))
optional blanklines
- return $ CodeBlock "" $ stripTrailingNewlines $ concat contents
+ return $ CodeBlock ("",[],[]) $ stripTrailingNewlines $ concat contents
--
-- block quotes