aboutsummaryrefslogtreecommitdiff
path: root/Text/Pandoc/Readers
diff options
context:
space:
mode:
Diffstat (limited to 'Text/Pandoc/Readers')
-rw-r--r--Text/Pandoc/Readers/HTML.hs2
-rw-r--r--Text/Pandoc/Readers/LaTeX.hs4
-rw-r--r--Text/Pandoc/Readers/Markdown.hs45
-rw-r--r--Text/Pandoc/Readers/RST.hs2
4 files changed, 38 insertions, 15 deletions
diff --git a/Text/Pandoc/Readers/HTML.hs b/Text/Pandoc/Readers/HTML.hs
index 2528de7b7..359ff3021 100644
--- a/Text/Pandoc/Readers/HTML.hs
+++ b/Text/Pandoc/Readers/HTML.hs
@@ -407,7 +407,7 @@ codeBlock = try $ do
let result''' = if "\n" `isSuffixOf` result''
then init result''
else result''
- return $ CodeBlock "" $ decodeCharacterReferences result'''
+ return $ CodeBlock ("",[],[]) $ decodeCharacterReferences result'''
--
-- block quotes
diff --git a/Text/Pandoc/Readers/LaTeX.hs b/Text/Pandoc/Readers/LaTeX.hs
index aa1e73704..f162b9367 100644
--- a/Text/Pandoc/Readers/LaTeX.hs
+++ b/Text/Pandoc/Readers/LaTeX.hs
@@ -182,14 +182,14 @@ codeBlock1 = try $ do
-- leading space
contents <- manyTill anyChar (try (string "\\end{verbatim}"))
spaces
- return $ CodeBlock "" (stripTrailingNewlines contents)
+ return $ CodeBlock ("",[],[]) (stripTrailingNewlines contents)
codeBlock2 = try $ do
string "\\begin{Verbatim}" -- used by fancyvrb package
optional blanklines
contents <- manyTill anyChar (try (string "\\end{Verbatim}"))
spaces
- return $ CodeBlock "" (stripTrailingNewlines contents)
+ return $ CodeBlock ("",[],[]) (stripTrailingNewlines contents)
--
-- block quotes
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
diff --git a/Text/Pandoc/Readers/RST.hs b/Text/Pandoc/Readers/RST.hs
index 85bc95fa3..76cfc8aa0 100644
--- a/Text/Pandoc/Readers/RST.hs
+++ b/Text/Pandoc/Readers/RST.hs
@@ -304,7 +304,7 @@ indentedBlock = do
codeBlock = try $ do
codeBlockStart
result <- indentedBlock
- return $ CodeBlock "" $ stripTrailingNewlines result
+ return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result
--
-- raw html