5

I'm trying to add the following tag

 <meta http-equiv="X-UA-Compatible" content="IE=edge" />

as the first one after <header> in the output of rmkardown HTML document. This is necessary for Internet Explorer, as explained in this MSDN article.

This answer does not work for me because the tag is added at the end of <head> and is ignored. My HTML output has some script embedded that is written before the X-UA-Compatible meta tag.

Is there a way to add the tag as the first one automatically in rmarkdown?

Community
  • 1
  • 1
Leonardo Motta
  • 101
  • 1
  • 5
  • you'll have to use your custom template file... not sure about knitr, but for standalone pandoc see http://pandoc.org/MANUAL.html#templates – mb21 May 17 '17 at 14:04
  • Thanks, I found the tamplate being used by rmarkdown and added the necessary meta tag. In order to make it independent of the user I will try to change the default template used by rmarkdown::render. – Leonardo Motta May 17 '17 at 14:51
  • 2
    the standard template can be edited in the library folder, e.g. "C:\Users\ProfileX\Documents\R\win-library\3.4\rmarkdown\rmd\h\default.html" – visu-l Dec 05 '17 at 10:29

1 Answers1

1

I just ran into this issue too. As people have said in the comments, editing the template html file used by rmarkdown works. I copied and edited the template saved at approximately "C:\Users\ProfileX\Documents\R\win-library\3.4\rmarkdown\rmd\h\default.html" (thanks @visu-l)

You want to add the tag as the first one within <head>:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>

<head>

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

Then save the html template, and point to it within YAML:

---
title: "xxx"
output:
  html_document:
    template: path/to/custom/template.html
---
Oliver
  • 1,098
  • 1
  • 11
  • 16