@@ -36,9 +36,7 @@ Implemented and parsed:
3636 - Inlines : strong, emph, cite, code, deleted, superscript,
3737 subscript, links
3838 - footnotes
39−
40−Implemented but discarded:
41− - HTML-specific and CSS-specific attributes
39+ - HTML-specific and CSS-specific attributes on headers
4240
4341Left to be implemented:
4442 - dimension sign
@@ -171,19 +169,16 @@ header :: Parser [Char] ParserState Block
171169header = try $ do
172170 char 'h'
173171 level <- digitToInt <$> oneOf "123456"
174− attr <- option "" attributes
175− let ident = case attr of
176− '#':xs -> xs
177− _ -> ""
172+ attr <- attributes
178173 char '.'
179174 whitespace
180175 name <- normalizeSpaces <$> manyTill inline blockBreak
181− return $ Header level (ident,[],[]) name
176+ return $ Header level attr name
182177
183178-- | Blockquote of the form "bq. content"
184179blockQuote :: Parser [Char] ParserState Block
185180blockQuote = try $ do
186− string "bq" >> optional attributes >> char '.' >> whitespace
181+ string "bq" >> attributes >> char '.' >> whitespace
187182 BlockQuote . singleton <$> para
188183
189184-- Horizontal rule
@@ -237,7 +232,7 @@ orderedListItemAtDepth = genericListItemAtDepth '#'
237232-- | Common implementation of list items
238233genericListItemAtDepth :: Char -> Int -> Parser [Char] ParserState [Block]
239234genericListItemAtDepth c depth = try $ do
240− count depth (char c) >> optional attributes >> whitespace
235+ count depth (char c) >> attributes >> whitespace
241236 p <- many listInline
242237 newline
243238 sublist <- option [] (singleton <$> anyListAtDepth (depth + 1))
@@ -348,7 +343,7 @@ maybeExplicitBlock :: String -- ^ block tag name
348343 -> Parser [Char] ParserState Block -- ^ implicit block
349344 -> Parser [Char] ParserState Block
350345maybeExplicitBlock name blk = try $ do
351− optional $ try $ string name >> optional attributes >> char '.' >>
346+ optional $ try $ string name >> attributes >> char '.' >>
352347 optional whitespace >> optional endline
353348 blk
354349
@@ -553,10 +548,32 @@ code2 = do
553548 Code nullAttr <$> manyTill anyChar (try $ htmlTag $ tagClose (=="tt"))
554549
555550-- | Html / CSS attributes
556−attributes :: Parser [Char] ParserState String
557−attributes = choice [ enclosed (char '(') (char ')') anyChar,
558− enclosed (char '{') (char '}') anyChar,
559− enclosed (char '[') (char ']') anyChar]
551+attributes :: Parser [Char] ParserState Attr
552+attributes = (foldl (flip ($)) ("",[],[])) `fmap` many attribute
553+
554+attribute :: Parser [Char] ParserState (Attr -> Attr)
555+attribute = classIdAttr <|> styleAttr <|> langAttr
556+
557+classIdAttr :: Parser [Char] ParserState (Attr -> Attr)
558+classIdAttr = try $ do -- (class class #id)
559+ char '('
560+ ws <- words `fmap` manyTill anyChar (char ')')
561+ case reverse ws of
562+ [] -> return $ \(_,_,keyvals) -> ("",[],keyvals)
563+ (('#':ident'):classes') -> return $ \(_,_,keyvals) ->
564+ (ident',classes',keyvals)
565+ classes' -> return $ \(_,_,keyvals) ->
566+ ("",classes',keyvals)
567+
568+styleAttr :: Parser [Char] ParserState (Attr -> Attr)
569+styleAttr = do
570+ style <- try $ enclosed (char '{') (char '}') anyChar
571+ return $ \(id',classes,keyvals) -> (id',classes,("style",style):keyvals)
572+
573+langAttr :: Parser [Char] ParserState (Attr -> Attr)
574+langAttr = do
575+ lang <- try $ enclosed (char '[') (char ']') anyChar
576+ return $ \(id',classes,keyvals) -> (id',classes,("lang",lang):keyvals)
560577
561578-- | Parses material surrounded by a parser.
562579surrounded :: Parser [Char] st t -- ^ surrounding parser