5

如何突出显示 xaringan 中的单个单词或代码选择而不是整行?

在下面的示例中,我只想突出显示管道运算符%>% 而不是整行。

---
output:
  xaringan::moon_reader:
    css: [default]
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=F}
library(magrittr)
```

Highlight Whole Line (not what I need)
```{r, eval=F}
iris %>% #<<
  summary()
```

Highlight Whole Line 2 (also not what I need)
```{r, eval=F}
{{ iris %>% }}
  summary()
```

Highlight Pipe only (What I would need, doesnt work)
```{r, eval=F}
iris {{ %>% }}
  summary()
```

Highlight Pipe only html-mark (doesnt work, as expected)
```{r, eval=F}
iris <mark>%>%</mark>
  summary()
```

这导致了这个在此处输入图像描述

任何帮助表示赞赏。

4

1 回答 1

14

我找到了一种解决方案:highlightSpans: true在代码中使用然后使用反引号。IE,

---
output:
  xaringan::moon_reader:
    css: [default]
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      highlightSpans: true
      countIncrementalSlides: false
---

```{r, eval=F}
iris `%>%`
  summary()
```

生产

在此处输入图像描述

该方法的唯一警告是,它仅在 R 本身不评估代码时运行。(eval=TRUE会返回错误)

其来源是:https ://github.com/gnab/remark/wiki/Configuration

于 2018-08-25T15:07:44.623 回答