gpt4 book ai didi

r-markdown - 突出显示 xaringan 中的代码选择

转载 作者:行者123 更新时间:2023-12-03 15:21:51 33 4
gpt4 key购买 nike

如何在 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()
```

结果是 enter image description here

任何帮助表示赞赏。

最佳答案

我找到的一种解决方案:使用 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()
```

产生

enter image description here

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

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

关于r-markdown - 突出显示 xaringan 中的代码选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52016911/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com