Title: | Code Syntax Highlighting using the 'Prism.js' Library |
---|---|
Description: | Code Syntax Highlighting made easy for code snippets or complete files. Whether you're documenting your data analysis or creating interactive 'shiny' apps. |
Authors: | Federico Rivadeneira [aut, cre, cph] |
Maintainer: | Federico Rivadeneira <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2 |
Built: | 2024-11-02 03:57:14 UTC |
Source: | https://github.com/federiva/highlighter |
List the available languages that can be used to highlight
get_available_languages()
get_available_languages()
A character vector that contains the programming languages available to highlight.
List the available themes that can be used with highlighter
get_available_themes()
get_available_themes()
A character vector with the names of the themes available.
Line highlight plugin
highlight(range)
highlight(range)
range |
A character indicating the range to be used, for example 2-5 will highlight from 2 up to 5. Also you can highlight two or more ranges in the following way 2-5,10-13,19. |
A list (named) with the name of the plugin and the range passed by the function
if (interactive()) { highlighter::highlighter( "print('Hello, world!')\ncat <- \"Aristofanes\"\nstr(some_variable)", language = "r", plugins = list( highlight( range = "1-2" ) ) ) }
if (interactive()) { highlighter::highlighter( "print('Hello, world!')\ncat <- \"Aristofanes\"\nstr(some_variable)", language = "r", plugins = list( highlight( range = "1-2" ) ) ) }
Highlights the content of a given file according to the source language, theme and plugins used.
highlight_file(file_path, language = NULL, plugins = NULL, theme = "default")
highlight_file(file_path, language = NULL, plugins = NULL, theme = "default")
file_path |
The path to the file to be highlighted |
language |
The programming language chosen to be highlighted |
plugins |
Optional. A list of plugins to be used |
theme |
A character. Indicating which theme will be used |
An object of class highlighter
get_available_languages()
for available languages,
get_available_themes()
for available themes
Highlights code
highlighter( code, language = "r", theme = "default", plugins = NULL, width = "100%", height = "auto", elementId = NULL )
highlighter( code, language = "r", theme = "default", plugins = NULL, width = "100%", height = "auto", elementId = NULL )
code |
The code to be highlighted |
language |
The programming language chosen to be highlighted |
theme |
A character. Indicating which theme will be used |
plugins |
Optional. A list of plugins to be used |
width |
Optional. The width to be used by the widget |
height |
Optional. The height to be used by the widget |
elementId |
Optional. The DOM element id to be used by the widget |
An object of class highlighter
get_available_languages()
for available languages,
get_available_themes()
for available themes
# Highlight R code if (interactive()) { highlighter("print('Hello, world!')", language = "r") }
# Highlight R code if (interactive()) { highlighter("print('Hello, world!')", language = "r") }
Output and render functions for using highlighter within Shiny applications and interactive Rmd documents.
highlighterOutput(outputId, width = "100%", height = "auto") renderHighlighter(expr, env = parent.frame(), quoted = FALSE)
highlighterOutput(outputId, width = "100%", height = "auto") renderHighlighter(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a highlighter |
env |
The environment in which to evaluate |
quoted |
Is |
An object of class shiny.tag.list
An object of class shiny.render.function
Line Number plugin
line_number(use_line_number = TRUE, start_from = 1)
line_number(use_line_number = TRUE, start_from = 1)
use_line_number |
Logical |
start_from |
A numeric indicating where to start to count from |
A list (named) with the name of the plugin, the class passed to the render function and the line number in which the line numbers will start from (optional).
if (interactive()) { highlighter::highlighter( "print('Hello, world!')\ncat <- \"Aristofanes\"\nstr(some_variable)", language = "r", plugins = list( line_number( use_line_number = TRUE, start_from = 2 ) ) ) }
if (interactive()) { highlighter::highlighter( "print('Hello, world!')\ncat <- \"Aristofanes\"\nstr(some_variable)", language = "r", plugins = list( line_number( use_line_number = TRUE, start_from = 2 ) ) ) }