-
Notifications
You must be signed in to change notification settings - Fork 0
/
how_to_highlight_code.Rmd
52 lines (41 loc) · 1.25 KB
/
how_to_highlight_code.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
title: "Highlight code"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Highlight code}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(highlighter)
```
## Using highlighter
We can use the `highglighter` function in order to render and highlight code.
By default the function will highlight the syntax of R code.
```{r}
highlighter("some_variable <- 3")
```
If we want we can specify the language using the `language` parameter.
```{r}
highlighter("const someVariable = 3;", language = "js")
```
## Using highlight_file
We can pass the path to a local file using the `highlight_file` function
```{r eval = FALSE}
# Specifying the language to be used
highlight_file("<path_to_your_file>", language = "r")
# Auto guessing the language to be highlighted when the language
# parameter is not specified.
highlight_file("<path_to_your_file>")
```
## Using themes
Specifying a theme to be used. You can get the available themes by
means of the following function: `get_available_themes()`
```{r eval = FALSE}
# Specifying the language to be used and the theme
highlight_file("<path_to_your_file>", language = "r", theme = "dark")
```