git.iko.soy/typeable/pandoc
on master help sign in
Use generic attributes type, not a string, for CodeBlocks.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1209 788f1e2b-df1e-0410-8736-df70ead52e1b

commit614547b38eff096d5bcdd1fc97eadc8eab89028a authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 9 Feb 2008, 03:19 (19 years ago) parent7053408
6 files changed+45−19
Text/Pandoc/Definition.hs+5−2 Text/Pandoc/Readers/HTML.hs+1−1 Text/Pandoc/Readers/LaTeX.hs+2−2 Text/Pandoc/Readers/Markdown.hs+34−11 Text/Pandoc/Readers/RST.hs+1−1 Text/Pandoc/Writers/HTML.hs+2−2
Text/Pandoc/Definition.hs+5−2
@@ -61,12 +61,15 @@ data ListNumberDelim = DefaultDelim
6161 | Period
6262 | OneParen
6363 | TwoParens deriving (Eq, Show, Read)
64−
64+
65+-- | Attributes.
66+type Attr = (String, [String], [(String, String)]) -- ^ Identifier, classes, key-value pairs
67+
6568-- | Block element.
6669data Block
6770 = Plain [Inline] -- ^ Plain text, not a paragraph
6871 | Para [Inline] -- ^ Paragraph
69− | CodeBlock String String -- ^ Code block (literal) with class
72+ | CodeBlock Attr String -- ^ Code block (literal) with attributes
7073 | RawHtml String -- ^ Raw HTML block (literal)
7174 | BlockQuote [Block] -- ^ Block quote (list of blocks)
7275 | OrderedList ListAttributes [[Block]] -- ^ Ordered list (attributes
Text/Pandoc/Readers/HTML.hs+1−1
@@ -407,7 +407,7 @@ codeBlock = try $ do
407407 let result''' = if "\n" `isSuffixOf` result''
408408 then init result''
409409 else result''
410− return $ CodeBlock "" $ decodeCharacterReferences result'''
410+ return $ CodeBlock ("",[],[]) $ decodeCharacterReferences result'''
411411
412412--
413413-- block quotes
Text/Pandoc/Readers/LaTeX.hs+2−2
@@ -182,14 +182,14 @@ codeBlock1 = try $ do
182182 -- leading space
183183 contents <- manyTill anyChar (try (string "\\end{verbatim}"))
184184 spaces
185− return $ CodeBlock "" (stripTrailingNewlines contents)
185+ return $ CodeBlock ("",[],[]) (stripTrailingNewlines contents)
186186
187187codeBlock2 = try $ do
188188 string "\\begin{Verbatim}" -- used by fancyvrb package
189189 optional blanklines
190190 contents <- manyTill anyChar (try (string "\\end{Verbatim}"))
191191 spaces
192− return $ CodeBlock "" (stripTrailingNewlines contents)
192+ return $ CodeBlock ("",[],[]) (stripTrailingNewlines contents)
193193
194194--
195195-- block quotes
Text/Pandoc/Readers/Markdown.hs+34−11
@@ -303,25 +303,48 @@ codeBlockDelimiter len = try $ do
303303 Nothing -> count 3 (char '~') >> many (char '~') >>=
304304 return . (+ 3) . length
305305 many spaceChar
306− lang <- option "" classAttributes
306+ attr <- option ([],[],[]) attributes
307307 blankline
308− return (size, lang)
308+ return (size, attr)
309309
310−classAttributes = try $ do
310+attributes = try $ do
311311 char '{'
312312 many spaceChar
313− attrs <- many $ try $ do char '.'
314− attr <- many1 alphaNum
315− many spaceChar
316− return attr
313+ attrs <- many (attribute >>~ many spaceChar)
317314 char '}'
318− return $ unwords attrs
315+ let (ids, classes, keyvals) = unzip3 attrs
316+ let id = if null ids then "" else head ids
317+ return (id, concat classes, concat keyvals)
318+
319+attribute = identifierAttr <|> classAttr <|> keyValAttr
320+
321+identifier = do
322+ first <- letter
323+ rest <- many alphaNum
324+ return (first:rest)
325+
326+identifierAttr = try $ do
327+ char '#'
328+ result <- identifier
329+ return (result,[],[])
330+
331+classAttr = try $ do
332+ char '.'
333+ result <- identifier
334+ return ("",[result],[])
335+
336+keyValAttr = try $ do
337+ key <- identifier
338+ char '='
339+ char '"'
340+ val <- manyTill (noneOf "\n") (char '"')
341+ return ("",[],[(key,val)])
319342
320343codeBlockDelimited = try $ do
321− (size, lang) <- codeBlockDelimiter Nothing
344+ (size, attr) <- codeBlockDelimiter Nothing
322345 contents <- manyTill anyLine (codeBlockDelimiter (Just size))
323346 blanklines
324− return $ CodeBlock lang $ joinWithSep "\n" contents
347+ return $ CodeBlock attr $ joinWithSep "\n" contents
325348
326349codeBlockIndented = do
327350 contents <- many1 (indentedLine <|>
@@ -329,7 +352,7 @@ codeBlockIndented = do
329352 l <- indentedLine
330353 return $ b ++ l))
331354 optional blanklines
332− return $ CodeBlock "" $ stripTrailingNewlines $ concat contents
355+ return $ CodeBlock ("",[],[]) $ stripTrailingNewlines $ concat contents
333356
334357--
335358-- block quotes
Text/Pandoc/Readers/RST.hs+1−1
@@ -304,7 +304,7 @@ indentedBlock = do
304304codeBlock = try $ do
305305 codeBlockStart
306306 result <- indentedBlock
307− return $ CodeBlock "" $ stripTrailingNewlines result
307+ return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result
308308
309309--
310310-- raw html
Text/Pandoc/Writers/HTML.hs+2−2
@@ -263,8 +263,8 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
263263blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
264264blockToHtml opts (RawHtml str) = return $ primHtml str
265265blockToHtml opts (HorizontalRule) = return $ hr
266−blockToHtml opts (CodeBlock lang str) = return $
267− pre ! (if null lang then [] else [theclass lang]) $
266+blockToHtml opts (CodeBlock (_,classes,_) str) = return $
267+ pre ! (if null classes then [] else [theclass $ unwords classes]) $
268268 thecode << (str ++ "\n") -- the final \n for consistency with Markdown.pl
269269blockToHtml opts (BlockQuote blocks) =
270270 -- in S5, treat list in blockquote specially