git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Parse name/content pairs from meta tags as metadata.

Closes #1106.

commitf3ee82373b4ad8e955db12d3c2c2159a2bea53a0 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 1 Jan 2014, 09:22 (13 years ago) parentd6ec6cf
2 files changed+11−2
src/Text/Pandoc/Readers/HTML.hs+10−1 tests/html-reader.native+1−1
src/Text/Pandoc/Readers/HTML.hs+10−1
@@ -76,9 +76,18 @@ pBody :: TagParser [Block]
7676pBody = pInTags "body" block
7777
7878pHead :: TagParser [Block]
79−pHead = pInTags "head" $ pTitle <|> ([] <$ pAnyTag)
79+pHead = pInTags "head" $ pTitle <|> pMetaTag <|> ([] <$ pAnyTag)
8080 where pTitle = pInTags "title" inline >>= setTitle . normalizeSpaces
8181 setTitle t = [] <$ (updateState $ B.setMeta "title" (B.fromList t))
82+ pMetaTag = do
83+ mt <- pSatisfy (~== TagOpen "meta" [])
84+ let name = fromAttrib "name" mt
85+ if null name
86+ then return []
87+ else do
88+ let content = fromAttrib "content" mt
89+ updateState $ B.setMeta name (B.text content)
90+ return []
8291
8392block :: TagParser [Block]
8493block = choice
tests/html-reader.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta {unMeta = fromList [("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
1+Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
22[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 "."]
33,HorizontalRule
44,Header 1 ("",[],[]) [Str "Headers"]