The following _site.yml creates a website with an <html> tag that does not specify a language. (Accessibility checkers will throw a complaint about this.)
name: "My Website!"
output_dir: "docs"
include: [".nojekyll"]
output:
html_document:
lang: en
css: style.css
include:
in_header: header.html
after_body: footer.html
If within an individual .Rmd file a language is specified in the YAML, the correct HTML is created.
For example, within the .Rmd you use:
---
title: "Title of Page"
author: "Cool R Markdown User"
lang: en
---
The rendered document then contains: <html lang="en" xml:lang="en">
Is this a feature, or a bug? (Perhaps it's good practice to specify a language for each page specifically.)
You need to do exactly the same for Rmarkdown website as you do for a standard Rmarkdown file. lang: en must be passed at the first level of the YAML - this is how variables are passed to templates. (See for example : https://bookdown.org/yihui/rmarkdown-cookbook/html-template.html)
So in _site.yml, keep the same level as you did in your yaml header
name: "My Website!"
output_dir: "docs"
include: [".nojekyll"]
output:
html_document:
css: style.css
include:
in_header: header.html
after_body: footer.html
lang: en
lang is not an option of html_document, so you should not pass it under output specificication. For example using your Rmd example, adding output format and options would be this way
---
title: "Title of Page"
author: "Cool R Markdown User"
output:
html_document:
toc: true
lang: en
---
Perhaps I'm missing something, but I had tried that before posting originally, and now again, but that has no effect.
In an attempt to replicate, I fired up RStudio, created a new project using the "Simple R Markdown Website" project type, and only modified the project to add the lang line to the YAML like so:
name: "my-website"
lang: en
navbar:
title: "My Website"
left:
- text: "Home"
href: index.html
- text: "About"
href: about.html
The resulting HTML does not include the language information in the <html> tag.
Yes you're right. It does not set for all the page. Thank you for the GH reprex and Sorry...
I had a lang: en in the Rmd file directly so I was mislead.
Currently, it seems this need to be set in all pages. I'll reopen the GH issue to verify is this is on purpose. it could work that way curently if pandoc variable are passed only at the document base.
But know that you can pass pandoc argurments through the pandoc_args argument in output format function. That means variables can be set this way though this argument. You can define the output globally in _site.yml. This should work: