Simplified HTML attribute parsing (HTML reader).
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1016 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
parent
28c2ee396c
commit
d5b7257d7f
1 changed files with 5 additions and 10 deletions
|
@ -105,13 +105,14 @@ anyHtmlTag = try $ do
|
||||||
char '<'
|
char '<'
|
||||||
spaces
|
spaces
|
||||||
tag <- many1 alphaNum
|
tag <- many1 alphaNum
|
||||||
attribs <- htmlAttributes
|
attribs <- many htmlAttribute
|
||||||
spaces
|
spaces
|
||||||
ender <- option "" (string "/")
|
ender <- option "" (string "/")
|
||||||
let ender' = if null ender then "" else " /"
|
let ender' = if null ender then "" else " /"
|
||||||
spaces
|
spaces
|
||||||
char '>'
|
char '>'
|
||||||
return $ "<" ++ tag ++ attribs ++ ender' ++ ">"
|
return $ "<" ++ tag ++
|
||||||
|
concatMap (\(_, _, raw) -> (' ':raw)) attribs ++ ender' ++ ">"
|
||||||
|
|
||||||
anyHtmlEndTag = try $ do
|
anyHtmlEndTag = try $ do
|
||||||
char '<'
|
char '<'
|
||||||
|
@ -141,19 +142,13 @@ quoted quoteChar = do
|
||||||
(many (noneOf [quoteChar]))
|
(many (noneOf [quoteChar]))
|
||||||
return (result, [quoteChar])
|
return (result, [quoteChar])
|
||||||
|
|
||||||
htmlAttributes = do
|
|
||||||
attrList <- many htmlAttribute
|
|
||||||
return $ concatMap (\(name, content, raw) -> raw) attrList
|
|
||||||
|
|
||||||
htmlAttribute = htmlRegularAttribute <|> htmlMinimizedAttribute
|
htmlAttribute = htmlRegularAttribute <|> htmlMinimizedAttribute
|
||||||
|
|
||||||
-- minimized boolean attribute
|
-- minimized boolean attribute
|
||||||
htmlMinimizedAttribute = try $ do
|
htmlMinimizedAttribute = try $ do
|
||||||
many1 space
|
many1 space
|
||||||
name <- many1 (choice [letter, oneOf ".-_:"])
|
name <- many1 (choice [letter, oneOf ".-_:"])
|
||||||
notFollowedBy (spaces >> char '=')
|
return (name, name, name)
|
||||||
let content = name
|
|
||||||
return (name, content, (" " ++ name))
|
|
||||||
|
|
||||||
htmlRegularAttribute = try $ do
|
htmlRegularAttribute = try $ do
|
||||||
many1 space
|
many1 space
|
||||||
|
@ -167,7 +162,7 @@ htmlRegularAttribute = try $ do
|
||||||
a <- many (alphaNum <|> (oneOf "-._:"))
|
a <- many (alphaNum <|> (oneOf "-._:"))
|
||||||
return (a,"")) ]
|
return (a,"")) ]
|
||||||
return (name, content,
|
return (name, content,
|
||||||
(" " ++ name ++ "=" ++ quoteStr ++ content ++ quoteStr))
|
(name ++ "=" ++ quoteStr ++ content ++ quoteStr))
|
||||||
|
|
||||||
-- | Parse an end tag of type 'tag'
|
-- | Parse an end tag of type 'tag'
|
||||||
htmlEndTag tag = try $ do
|
htmlEndTag tag = try $ do
|
||||||
|
|
Loading…
Reference in a new issue