Skip to content

Commit cb61f10

Browse files
committed
Set language in HTML
Setting the language helps with search engines, screen readers and text rendering. The language defaults to `en` as that is probably most common (it's also the default for navigation in Darkfish). Setting the `locale` option will override the language to the locale.
1 parent fdaa5a6 commit cb61f10

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rdoc/generator/darkfish.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def assemble_template(body_file)
595595
<<-TEMPLATE
596596
<!DOCTYPE html>
597597
598-
<html>
598+
<html lang="#{@options.locale || 'en'}">
599599
<head>
600600
#{head_file.read}
601601

test/rdoc/test_rdoc_generator_darkfish.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ def test_template_stylesheets
388388
assert_include File.binread('index.html'), %Q[href="./#{base}"]
389389
end
390390

391+
def test_html_lang
392+
@g.generate
393+
394+
content = File.binread("index.html")
395+
assert_include(content, '<html lang="en">')
396+
end
397+
398+
def test_html_lang_from_locale
399+
@options.locale = RDoc::I18n::Locale.new 'ja'
400+
@g.generate
401+
402+
content = File.binread("index.html")
403+
assert_include(content, '<html lang="ja">')
404+
end
405+
391406
def test_title
392407
title = "RDoc Test".freeze
393408
@options.title = title

0 commit comments

Comments
 (0)