git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Use the lang value of <html> to set the lang meta value. (#3765)

* HTML reader: Use the lang value of <html> to set the lang meta value. * Fix for pre-AMP environments.

commit460b6c470bae26f31d7c0d72b85aef8eb254b7f7 authorbucklereed <horridimpfoobarbaz@chammy.info> dateTue 27 Jun 2017, 09:19 (9 years ago) parent19d9482
2 files changed+15
src/Text/Pandoc/Readers/HTML.hs+9 test/Tests/Readers/HTML.hs+6
src/Text/Pandoc/Readers/HTML.hs+9
@@ -53,6 +53,7 @@ import Text.Pandoc.Logging
5353import Text.Pandoc.Parsing hiding ((<|>))
5454import Text.Pandoc.Walk
5555import qualified Data.Map as M
56+import Data.Foldable ( for_ )
5657import Data.Maybe ( fromMaybe, isJust)
5758import Data.List ( intercalate, isPrefixOf )
5859import Data.Char ( isDigit, isLetter, isAlphaNum )
@@ -134,6 +135,13 @@ type HTMLParser m s = ParserT s HTMLState (ReaderT HTMLLocal m)
134135
135136type TagParser m = HTMLParser m [Tag Text]
136137
138+pHtml :: PandocMonad m => TagParser m Blocks
139+pHtml = try $ do
140+ (TagOpen "html" attr) <- lookAhead $ pAnyTag
141+ for_ (lookup "lang" attr) $
142+ updateState . B.setMeta "lang" . B.text . T.unpack
143+ pInTags "html" block
144+
137145pBody :: PandocMonad m => TagParser m Blocks
138146pBody = pInTags "body" block
139147
@@ -175,6 +183,7 @@ block = do
175183 , pList
176184 , pHrule
177185 , pTable
186+ , pHtml
178187 , pHead
179188 , pBody
180189 , pDiv
test/Tests/Readers/HTML.hs+6
@@ -30,4 +30,10 @@ tests = [ testGroup "base tag"
3030 [ test html "anchor without href" $ "<a name=\"anchor\"/>" =?>
3131 plain (spanWith ("anchor",[],[]) mempty)
3232 ]
33+ , testGroup "lang"
34+ [ test html "lang on <html>" $ "<html lang=\"es\">hola" =?>
35+ setMeta "lang" (text "es") (doc (plain (text "hola")))
36+ , test html "xml:lang on <html>" $ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"es\"><head></head><body>hola</body></html>" =?>
37+ setMeta "lang" (text "es") (doc (plain (text "hola")))
38+ ]
3339 ]