@@ -36,9 +36,7 @@ Implemented and parsed:
36 - Inlines : strong, emph, cite, code, deleted, superscript,
36 - Inlines : strong, emph, cite, code, deleted, superscript,
37 subscript, links
37 subscript, links
38 - footnotes
38 - footnotes
40−Implemented but discarded:
41− - HTML-specific and CSS-specific attributes
39+ - HTML-specific and CSS-specific attributes on headers
43Left to be implemented:
41Left to be implemented:
44 - dimension sign
42 - dimension sign
@@ -171,19 +169,16 @@ header :: Parser [Char] ParserState Block
171header = try $ do
169header = try $ do
173 level <- digitToInt <$> oneOf "123456"
171 level <- digitToInt <$> oneOf "123456"
174− attr <- option "" attributes
172+ attr <- attributes
175− let ident = case attr of
179 whitespace
174 whitespace
180 name <- normalizeSpaces <$> manyTill inline blockBreak
175 name <- normalizeSpaces <$> manyTill inline blockBreak
181− return $ Header level (ident,[],[]) name
176+ return $ Header level attr name
183-- | Blockquote of the form "bq. content"
178-- | Blockquote of the form "bq. content"
184blockQuote :: Parser [Char] ParserState Block
179blockQuote :: Parser [Char] ParserState Block
185blockQuote = try $ do
180blockQuote = try $ do
186− string "bq" >> optional attributes >> char '.' >> whitespace
181+ string "bq" >> attributes >> char '.' >> whitespace
187 BlockQuote . singleton <$> para
182 BlockQuote . singleton <$> para
189-- Horizontal rule
184-- Horizontal rule
@@ -237,7 +232,7 @@ orderedListItemAtDepth = genericListItemAtDepth '#'
237-- | Common implementation of list items
232-- | Common implementation of list items
238genericListItemAtDepth :: Char -> Int -> Parser [Char] ParserState [Block]
233genericListItemAtDepth :: Char -> Int -> Parser [Char] ParserState [Block]
239genericListItemAtDepth c depth = try $ do
234genericListItemAtDepth c depth = try $ do
240− count depth (char c) >> optional attributes >> whitespace
235+ count depth (char c) >> attributes >> whitespace
241 p <- many listInline
236 p <- many listInline
243 sublist <- option [] (singleton <$> anyListAtDepth (depth + 1))
238 sublist <- option [] (singleton <$> anyListAtDepth (depth + 1))
@@ -348,7 +343,7 @@ maybeExplicitBlock :: String -- ^ block tag name
348 -> Parser [Char] ParserState Block -- ^ implicit block
343 -> Parser [Char] ParserState Block -- ^ implicit block
349 -> Parser [Char] ParserState Block
344 -> Parser [Char] ParserState Block
350maybeExplicitBlock name blk = try $ do
345maybeExplicitBlock name blk = try $ do
351− optional $ try $ string name >> optional attributes >> char '.' >>
346+ optional $ try $ string name >> attributes >> char '.' >>
352 optional whitespace >> optional endline
347 optional whitespace >> optional endline
@@ -553,10 +548,32 @@ code2 = do
553 Code nullAttr <$> manyTill anyChar (try $ htmlTag $ tagClose (=="tt"))
548 Code nullAttr <$> manyTill anyChar (try $ htmlTag $ tagClose (=="tt"))
555-- | Html / CSS attributes
550-- | Html / CSS attributes
556−attributes :: Parser [Char] ParserState String
551+attributes :: Parser [Char] ParserState Attr
557−attributes = choice [ enclosed (char '(') (char ')') anyChar,
552+attributes = (foldl (flip ($)) ("",[],[])) `fmap` many attribute
554+attribute :: Parser [Char] ParserState (Attr -> Attr)
555+attribute = classIdAttr <|> styleAttr <|> langAttr
557+classIdAttr :: Parser [Char] ParserState (Attr -> Attr)
558+classIdAttr = try $ do -- (class class #id)
560+ ws <- words `fmap` manyTill anyChar (char ')')
562+ [] -> return $ \(_,_,keyvals) -> ("",[],keyvals)
563+ (('#':ident'):classes') -> return $ \(_,_,keyvals) ->
564+ (ident',classes',keyvals)
565+ classes' -> return $ \(_,_,keyvals) ->
566+ ("",classes',keyvals)
568+styleAttr :: Parser [Char] ParserState (Attr -> Attr)
558− enclosed (char '{') (char '}') anyChar,
570+ style <- try $ enclosed (char '{') (char '}') anyChar
571+ return $ \(id',classes,keyvals) -> (id',classes,("style",style):keyvals)
573+langAttr :: Parser [Char] ParserState (Attr -> Attr)
559− enclosed (char '[') (char ']') anyChar]
575+ lang <- try $ enclosed (char '[') (char ']') anyChar
576+ return $ \(id',classes,keyvals) -> (id',classes,("lang",lang):keyvals)
561-- | Parses material surrounded by a parser.
578-- | Parses material surrounded by a parser.
562surrounded :: Parser [Char] st t -- ^ surrounding parser
579surrounded :: Parser [Char] st t -- ^ surrounding parser