Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,20 @@ Typical syntax highlighting is only interested in whether a token is a function
call, a keyword, a string, ... this is what the `lestrade` detective does:

```r
library(highlight)
highlight( file = "css_file.R", detective = lestrade )
# Generate html file to preview externally
tmp_page <- tempfile(pattern = "highlight_preview", fileext = ".html")
capture.output(cat(
highlight(
file = "./R/css_file.R",
detective = lestrade,
header = document_header()
)
),
file = tmp_page)
# Open in RStudio
rstudioapi::viewer(tmp_page, height = NULL)
```

This will look like this:
Expand Down
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

highlight
=========
# highlight

highlight is a syntax highlighter for R code.

Installation
------------
## Installation

You can install highlight from github with:

Expand All @@ -14,38 +12,58 @@ You can install highlight from github with:
devtools::install_github("romainfrancois/highlight")
```

Typical highlighting (lestrade)
-------------------------------
## Typical highlighting (lestrade)

Typical syntax highlighting is only interested in whether a token is a function call, a keyword, a string, ... this is what the `lestrade` detective does:
Typical syntax highlighting is only interested in whether a token is a
function call, a keyword, a string, … this is what the `lestrade`
detective does:

``` r
library(highlight)
highlight( file = "css_file.R", detective = lestrade )
# Generate html file to preview externally
tmp_page <- tempfile(pattern = "highlight_preview", fileext = ".html")
capture.output(cat(
highlight(
file = "./R/css_file.R",
detective = lestrade,
header = document_header()
)
),
file = tmp_page)
# Open in RStudio
rstudioapi::viewer(tmp_page, height = NULL)
```

This will look like this:

![](img/lestrade.png)

This differentiates <span class="functioncall">function calls</span>, <span class="symbol_formalargs">formal arguments</span>, <span class="symbol_argument">used arguments</span> ... because `lestrade` identified these tokens as such.
This differentiates <span class="functioncall">function calls</span>,
<span class="symbol_formalargs">formal arguments</span>,
<span class="symbol_argument">used arguments</span> … because `lestrade`
identified these tokens as such.

semantic highlighting (sherlock)
--------------------------------
## semantic highlighting (sherlock)

Traditional highlighting only reveals the obvious, so the package also benefits from the investigation of `sherlock` for semantic highlighting. In semantic highlighting, every symbol gets a different color.
Traditional highlighting only reveals the obvious, so the package also
benefits from the investigation of `sherlock` for semantic highlighting.
In semantic highlighting, every symbol gets a different color.

``` r
highlight( file = "css_file.R", detective = sherlock )
```

![](img/sherlock.png)

With this we can quickly skim through the file and see e.g. the different uses of `filename`.
With this we can quickly skim through the file and see e.g. the
different uses of `filename`.

In rmarkdown
------------
## In rmarkdown

To use in `rmarkdown` you can use the `hl_hook_source` and `hl_hook_document` hooks. Unfortunately this does not work for README on github so this document uses screenshots.
To use in `rmarkdown` you can use the `hl_hook_source` and
`hl_hook_document` hooks. Unfortunately this does not work for README on
github so this document uses screenshots.

``` r
knitr::knit_hooks$set(
Expand Down