为什么智能引号和 em-dashes 没有出现在 Xaringan 幻灯片中?

Why are smart quotes and em-dashes not appearing in Xaringan slides?

问题

根据文档,Xaringan 应该

  1. 将普通引号" "变成智能引号“”,并且

  2. 将 3 个连字符“---”的序列转换为 em-dash“—”

我遇到的问题是,这些转换仅发生在 yaml 元数据中的字符串(出现在标题幻灯片中),但不会发生在普通幻灯片中的文本中.

例子

文件 minimal.Rmd 包含以下代码:

---
title: "\"It works, doesn't it?\" --- this is the title slide"
subtitle: "Smart quotes and em dash work in yaml"
output: 
  xaringan::moon_reader
---

# This is a normal slide

It works in the slides too, doesn't it? --- "I hope so", he said.

No, it doesn't.

编织后,我在minimal.html中得到以下幻灯片:

  1. 幻灯片标题(注意智能引号和 em-dash):

  2. 第二张幻灯片(丑陋的引号和 3 个连字符):

想法

  1. 我很确定 Xaringan 不会 使用 Pandoc 生成 html。过程中如果使用Pandoc,会默认美化引号

  2. 我尝试在 yaml 元数据中使用 smart: true,如 RMarkdown book 所示,但没有效果。

  3. 查看 moon_reader function 的代码,我看到它调用 rmarkdown::html_document 生成 html。

  4. open issue in the RMarkdown Github repository 讨论了 smart: true 选项和调用 Pandoc 时的等效选项。该问题的作者建议删除 yaml 选项并将其留给 Pandoc 来美化引号等。

    但是 Xaringan 使用 Pandoc,所以这可能相关吗?

我的设置

R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

xaringan_0.15
knitr_1.28
rmarkdown_2.1

在此先感谢您的帮助。

Link 解决方案

https://github.com/fnaufel/smartify

详情

毕竟,xaringanremarkjs 都没有负责美化引号和破折号。

我四处寻找 Javascript 解决方案来解决我的问题,但最终决定实施我自己的解决方案。将几行添加到 in_header.htmlafter_body.html,您可以加载和 运行 我的 Javascript hack 来智能化幻灯片中的引号和破折号。无需安装任何东西。

详情请见 https://github.com/fnaufel/smartify

我希望这对其他人有用。

再次感谢@YihuiXie 的评论