From 8a251b8cc5a59e385de82da7bbc73e727ae96985 Mon Sep 17 00:00:00 2001 From: Konrad Zdeb Date: Thu, 17 Jan 2019 20:36:39 +0000 Subject: [PATCH 1/4] Petty fix but it's either this or calling it like that: highlight::highlight( file = "jsa_quantiles.R", detective = highlight::lestrade ) --- README.Rmd | 1 + README.md | 36 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.Rmd b/README.Rmd index 6f18737..b677c50 100644 --- a/README.Rmd +++ b/README.Rmd @@ -30,6 +30,7 @@ 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 ) ``` diff --git a/README.md b/README.md index 51a3275..440e4fd 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ -highlight -========= +# highlight highlight is a syntax highlighter for R code. -Installation ------------- +## Installation You can install highlight from github with: @@ -14,12 +12,14 @@ 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 ) ``` @@ -27,12 +27,16 @@ This will look like this: ![](img/lestrade.png) -This differentiates function calls, formal arguments, used arguments ... because `lestrade` identified these tokens as such. +This differentiates function calls, +formal arguments, +used arguments … 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 ) @@ -40,12 +44,14 @@ 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( From acadbd54fe6e13af5a50138d429e095d2fc1be16 Mon Sep 17 00:00:00 2001 From: Konrad Zdeb Date: Thu, 17 Jan 2019 20:46:29 +0000 Subject: [PATCH 2/4] I've added a few minor steps that someone can do if interested in quickly obtaining a preview html file. --- README.Rmd | 12 ++++++++++++ README.md | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.Rmd b/README.Rmd index b677c50..d2fff47 100644 --- a/README.Rmd +++ b/README.Rmd @@ -32,6 +32,18 @@ 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: diff --git a/README.md b/README.md index 440e4fd..16fd8b5 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,18 @@ 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: From 5a6194d39e2cce25bf3392d2ee30ba88fec45acb Mon Sep 17 00:00:00 2001 From: Konrad Zdeb Date: Thu, 17 Jan 2019 20:47:33 +0000 Subject: [PATCH 3/4] Ignoring RStudio session logs Signed-off-by: Konrad Zdeb --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3f2bc3b..c65aa46 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ src/*.dll .DS_Store inst/doc README-source.* +sessionInfoLog From 91803167b1bc223e42f5a35a2599588a8b141b70 Mon Sep 17 00:00:00 2001 From: Konrad Zdeb Date: Thu, 17 Jan 2019 20:55:44 +0000 Subject: [PATCH 4/4] Removed sessionInfoLog from gitignore Signed-off-by: Konrad Zdeb --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c65aa46..3f2bc3b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,4 @@ src/*.dll .DS_Store inst/doc README-source.* -sessionInfoLog