Hi all! I am trying to use the flair package in xaringan slides to highlight text strings. This is adapated from Danielle Navarro's slides source code.
I am having trouble with the regex to highlight patterns. Any help would be much appreciated!
The four compenents of the string that I would like to be able to pull out are:
[prefix]_[stem]_[description].[ext]
I can get the prefix and extention, but I am struggling with stem and description. I'm not sure if it is the regex or the flair, but in some cirumstances the underscores are rendering as italicized text.
Incorrect rendering of stem:
Description I can get when specificing exact text strings but not with regex patterns.
Here is the full demo .Rmd:
---
title: "Flair demo"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
---
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
library(flair)
```
---
---
# text
```{r filenames, include=FALSE, results='hide'}
"2021-01-01_stem1_description1.xlsx"
"2021-01-01_stem1_description2.xlsx"
"2022-03-15_longstem1.pdf"
"2022-03-15_longstem1_description1.pdf"
```
---
# flair prefix
```{r, echo=FALSE, results='asis'}
decorate_chunk("filenames") %>%
flair_rx('"[^_\n]+') %>%
flair::knit_print.with_flair()
```
---
# flair stem attempts
```{r, echo=FALSE, results='asis'}
decorate_chunk("filenames") %>%
flair_rx("_.*_") %>%
flair::knit_print.with_flair()
```
```{r, echo=FALSE, results='asis'}
decorate_chunk("filenames") %>%
flair_rx("stem1") %>%
flair_rx("longstem1") %>%
flair::knit_print.with_flair()
```
---
# flair description attempts
```{r, echo=FALSE, results='asis'}
decorate_chunk("filenames") %>%
flair_rx("_[^.]*") %>%
flair::knit_print.with_flair()
```
```{r, echo=FALSE, results='asis'}
decorate_chunk("filenames") %>%
flair_rx("_description1") %>%
flair_rx("_description2") %>%
flair::knit_print.with_flair()
```
---
# flair extension
```{r, echo=FALSE, results='asis'}
decorate_chunk("filenames") %>%
flair_rx("\\..*") %>%
flair::knit_print.with_flair()
```