summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-01-01 09:22:37 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-01-01 09:22:37 -0800
commitf3ee82373b4ad8e955db12d3c2c2159a2bea53a0 (patch)
tree47e96d389717b60c5aa465aa359ecab7c0107bdf
parentd6ec6cf9cf5731977fa0f476cabef4786edd5665 (diff)
HTML reader: Parse name/content pairs from meta tags as metadata.
Closes #1106.
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs11
-rw-r--r--tests/html-reader.native2
2 files changed, 11 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index 4b44a3a21..506fe7770 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -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
diff --git a/tests/html-reader.native b/tests/html-reader.native
index 794512426..e80905729 100644
--- a/tests/html-reader.native
+++ b/tests/html-reader.native
@@ -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"]