在rmarkdown html输出中添加X-UA兼容

Leo*_*tta 5 r pandoc knitr r-markdown

我正在尝试添加以下标记

 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
Run Code Online (Sandbox Code Playgroud)

作为rmkardown HTML文档输出之后的一个<header>.这对于Internet Explorer是必需的,如本MSDN 文章中所述.

这个答案对我不起作用,因为标签是在末尾添加的<head>并被忽略.我的HTML输出中嵌入了一些嵌入在X-UA兼容元标记之前的脚本.

有没有办法在rmarkdown中自动添加标签作为第一个?

Oli*_*ver 1

我也刚刚遇到这个问题。正如人们在评论中所说,编辑 rmarkdown 使用的模板 html 文件是有效的。我复制并编辑了保存在大约“C:\Users\ProfileX\Documents\R\win-library\3.4\rmarkdown\rmd\h\default.html”的模板(感谢@visu-l)

您想要将标签添加为以下内的第一个标签<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" />
Run Code Online (Sandbox Code Playgroud)

然后保存 html 模板,并在 YAML 中指向它:

---
title: "xxx"
output:
  html_document:
    template: path/to/custom/template.html
---
Run Code Online (Sandbox Code Playgroud)