HTML reader: Parse name/content pairs from meta tags as metadata.
Closes #1106.
This commit is contained in:
parent
d6ec6cf9cf
commit
f3ee82373b
2 changed files with 11 additions and 2 deletions
|
@ -76,9 +76,18 @@ pBody :: TagParser [Block]
|
|||
pBody = pInTags "body" block
|
||||
|
||||
pHead :: TagParser [Block]
|
||||
pHead = pInTags "head" $ pTitle <|> ([] <$ pAnyTag)
|
||||
pHead = pInTags "head" $ pTitle <|> pMetaTag <|> ([] <$ pAnyTag)
|
||||
where pTitle = pInTags "title" inline >>= setTitle . normalizeSpaces
|
||||
setTitle t = [] <$ (updateState $ B.setMeta "title" (B.fromList t))
|
||||
pMetaTag = do
|
||||
mt <- pSatisfy (~== TagOpen "meta" [])
|
||||
let name = fromAttrib "name" mt
|
||||
if null name
|
||||
then return []
|
||||
else do
|
||||
let content = fromAttrib "content" mt
|
||||
updateState $ B.setMeta name (B.text content)
|
||||
return []
|
||||
|
||||
block :: TagParser [Block]
|
||||
block = choice
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Pandoc (Meta {unMeta = fromList [("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
|
||||
Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
|
||||
[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc",Str ".",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber",Str "'",Str "s",Space,Str "markdown",Space,Str "test",Space,Str "suite",Str "."]
|
||||
,HorizontalRule
|
||||
,Header 1 ("",[],[]) [Str "Headers"]
|
||||
|
|
Loading…
Reference in a new issue