Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add X-UA-Compatible in rmarkdown html output

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?

like image 229
Leonardo Motta Avatar asked Nov 08 '22 22:11

Leonardo Motta


1 Answers

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
---
like image 120
Oliver Avatar answered Nov 15 '22 05:11

Oliver