File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -273,6 +273,7 @@ def get_meta_value(key):
273273 self .analyze_a_tags (soup_unmodified )
274274 self .analyze_img_tags (soup_lower )
275275 self .analyze_h1_tags (soup_lower )
276+ self .analyze_html_lang (soup_lower )
276277
277278 if self .analyze_headings :
278279 self .analyze_heading_tags (soup_unmodified )
@@ -449,6 +450,14 @@ def analyze_h1_tags(self, bs):
449450 if len (htags ) == 0 :
450451 self .warn ("Each page should have at least one h1 tag" )
451452
453+ def analyze_html_lang (self , bs ):
454+ """
455+ Make sure the HTML tag has a lang attribute
456+ """
457+ html_tag = bs .find ("html" )
458+ if html_tag is not None and not html_tag .get ("lang" ):
459+ self .warn ("Missing lang attribute on <html> tag" )
460+
452461 def analyze_a_tags (self , bs ):
453462 """
454463 Add any new links (that we didn't find in the sitemap)
Original file line number Diff line number Diff line change @@ -30,6 +30,31 @@ def test_analyze():
3030 assert "seth" in p .title .lower ()
3131
3232
33+ def test_analyze_html_lang_missing ():
34+ from bs4 import BeautifulSoup
35+
36+ p = page .Page (url = "https://example.com/" , base_domain = "https://example.com/" )
37+ soup = BeautifulSoup (
38+ "<html><head><title>Test</title></head><body><p>Hello</p></body></html>" ,
39+ "html.parser" ,
40+ )
41+ p .analyze_html_lang (soup )
42+ assert len (p .warnings ) == 1
43+ assert "lang" in p .warnings [0 ].lower ()
44+
45+
46+ def test_analyze_html_lang_present ():
47+ from bs4 import BeautifulSoup
48+
49+ p = page .Page (url = "https://example.com/" , base_domain = "https://example.com/" )
50+ soup = BeautifulSoup (
51+ '<html lang="en"><head><title>Test</title></head><body><p>Hello</p></body></html>' ,
52+ "html.parser" ,
53+ )
54+ p .analyze_html_lang (soup )
55+ assert len (p .warnings ) == 0
56+
57+
3358def test_analyze_with_llm ():
3459 p = page .Page (
3560 url = "https://www.sethserver.com/" ,
You can’t perform that action at this time.
0 commit comments