Title: | 'RStudio' Addins to Prettify 'JavaScript', 'C++', 'Python', and More |
---|---|
Description: | Provides 'RStudio' addins to prettify 'HTML', 'CSS', 'SCSS', 'JavaScript', 'JSX', 'Markdown', 'C(++)', 'LaTeX', 'Python', 'Julia', 'XML', 'Java', 'JSON', 'Ruby', and to reindent 'C(++)', 'Fortran', 'Java', 'Julia', 'Python', 'SAS', 'Scala', 'Shell', 'SQL' and "TypeScript". Two kinds of addins are provided: 'Prettify' and 'Indent'. The 'Indent' addins only reindent the code, while the 'Prettify' addins also modify the code, e.g. trailing semi-colons are added to 'JavaScript' code when they are missing. |
Authors: | Stéphane Laurent [aut, cre], James Long and contributors [cph] ('Prettier' library), Zeb Zhao [cph] ('indent.js' library), Marijn Haverbeke [cph] ('CodeMirror' library), George Leslie-Waksman and other contributors [cph] ('sql-formatter' library), Austin Cheney [cph] ('prettydiff' library), John Schlinkert [ctb, cph] (word-wrap) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 2.6.1 |
Built: | 2024-10-24 03:58:36 UTC |
Source: | https://github.com/stla/prettifyaddins |
Returns the list of languages that are supported by this package.
getPrettifiableLanguages()
getPrettifiableLanguages()
Prettify Java code, JSON code or Ruby code.
prettify_FCA(contents = NA, language = NA)
prettify_FCA(contents = NA, language = NA)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
The pretty code in a character string.
This function requires a connection to Internet.
library(prettifyAddins) code <- c( "{a: [0,1, 2 ],", "f: function( x){return x+1}}" # this function will be prettified too ) ## Not run: cat(prettify_FCA(code, "json")) ## End(Not run)
library(prettifyAddins) code <- c( "{a: [0,1, 2 ],", "f: function( x){return x+1}}" # this function will be prettified too ) ## Not run: cat(prettify_FCA(code, "json")) ## End(Not run)
Prettify some code using a Shiny app.
prettify_Shiny(contents = NA, language = NA, tabSize = NULL, themeInfo = NULL)
prettify_Shiny(contents = NA, language = NA, tabSize = NULL, themeInfo = NULL)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
tabSize |
number of spaces of the indentation (usually |
themeInfo |
this argument is not important, it controls the theme of
the Shiny app;
it must be |
The pretty code in a character string.
library(prettifyAddins) code <- c( "function f(x){", "return x+1", "}" ) if(interactive()){ cat(prettify_Shiny(code, "javascript")) }
library(prettifyAddins) code <- c( "function f(x){", "return x+1", "}" ) if(interactive()){ cat(prettify_Shiny(code, "javascript")) }
Prettify some code using the V8 package.
prettify_V8(contents = NA, language = NA, tabSize = NULL)
prettify_V8(contents = NA, language = NA, tabSize = NULL)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
tabSize |
number of spaces of the indentation (usually |
The pretty code in a character string.
library(prettifyAddins) code <- c( "function f(x){", "return x+1", "}" ) cat(prettify_V8(code, "JavaScript"))
library(prettifyAddins) code <- c( "function f(x){", "return x+1", "}" ) cat(prettify_V8(code, "JavaScript"))
This package provides some RStudio addins: Prettify
addins and
Indent
addins. To run an addin, select it from the Addins menu
within RStudio. The Indent
addins only reindent the code, while
the Prettify
addins also modify the code, e.g. they add trailing
semi-colons to JavaScript code when they are missing.
# get the list of supported languages: getPrettifiableLanguages()
# get the list of supported languages: getPrettifiableLanguages()
This function is imported from the 'webdriver' package.
Follow the link to its documentation:
install_phantomjs
Prettify some C, C++ or Java code.
prettifyCLANG(contents = NA, language = NA, tabSize = NULL)
prettifyCLANG(contents = NA, language = NA, tabSize = NULL)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
language |
the language of the code; when the contents is read from a file, this option is ignored, because the language is obtained from the extension of the file |
tabSize |
number of spaces of the indentation (usually |
The pretty code in a character string.
This function requires the command line utility clang-format
.
Prettify some HTML code. It works for big files.
prettifyHTML(contents = NA, tabSize = NULL)
prettifyHTML(contents = NA, tabSize = NULL)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
tabSize |
number of spaces of the indentation (usually |
The pretty code in a character string.
This function requires the command line utility prettydiff
,
to install with npm
.
Prettify Julia code.
prettifyJulia(contents = NA, tabSize = NULL)
prettifyJulia(contents = NA, tabSize = NULL)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
tabSize |
number of spaces of the indentation (usually |
The pretty code in a character string.
This function requires that Julia is installed on your system and that
the Julia package JuliaFormatter
is installed.
Prettify LaTeX code, including Sweave code, sty
files,
cls
files, and bib
files.
prettifyLaTeX(contents = NA, tabSize = NULL, log = FALSE)
prettifyLaTeX(contents = NA, tabSize = NULL, log = FALSE)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
tabSize |
number of spaces of the indentation (usually |
log |
logical, whether to generate a log file (it will be named
|
The pretty code in a character string.
This function requires the command line utility latexindent
.
Prettify Python code.
prettifyPython(contents = NA)
prettifyPython(contents = NA)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
The pretty code in a character string.
This function requires black.
Prettify some XML or SVG code.
prettifyXML(contents = NA, tabSize = NULL)
prettifyXML(contents = NA, tabSize = NULL)
contents |
the code to be prettified; there are three possibilities for
this argument:
|
tabSize |
number of spaces of the indentation (usually |
The code is prettified with the help of the command line utility
xmllint
if it is available, otherwise the xml2
is used.
The pretty code in a character string.
Reindent some code using chromote.
reindent_chromote(contents = NA, language = NA, tabSize = NULL)
reindent_chromote(contents = NA, language = NA, tabSize = NULL)
contents |
the code to be reindented; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
tabSize |
number of spaces of the indentation (usually |
The reindented code in a character string.
This function uses chromote::find_chrome()
to find the
executable of Google Chrome or another Chromium-based browser. If it is
not found you will get an error. In this case set the environment variable
CHROMOTE_CHROME
to the path of such an executable
(e.g. Sys.setenv(CHROMOTE_CHROME = "path/to/chrome.exe")
).
library(prettifyAddins) code <- c( 'if test == 1:', 'print "it is one"', 'else:', 'print "it is not one"' ) if(Sys.which("chrome") != "") { cat(reindent_chromote(code, "python")) }
library(prettifyAddins) code <- c( 'if test == 1:', 'print "it is one"', 'else:', 'print "it is not one"' ) if(Sys.which("chrome") != "") { cat(reindent_chromote(code, "python")) }
Reindent some code using PhantomJS.
reindent_PhantomJS(contents = NA, language = NA, tabSize = NULL)
reindent_PhantomJS(contents = NA, language = NA, tabSize = NULL)
contents |
the code to be reindented; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
tabSize |
number of spaces of the indentation (usually |
The reindented code in a character string.
This function requires the 'phantomjs' command-line utility.
library(prettifyAddins) code <- c( 'if test == 1:', 'print "it is one"', 'else:', 'print "it is not one"' ) if(Sys.which("phantomjs") != "") { cat(reindent_PhantomJS(code, "python")) }
library(prettifyAddins) code <- c( 'if test == 1:', 'print "it is one"', 'else:', 'print "it is not one"' ) if(Sys.which("phantomjs") != "") { cat(reindent_PhantomJS(code, "python")) }
Reindent some code using a Shiny app.
reindent_Shiny(contents = NA, language = NA, tabSize = NULL, themeInfo = NULL)
reindent_Shiny(contents = NA, language = NA, tabSize = NULL, themeInfo = NULL)
contents |
the code to be reindented; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
tabSize |
number of spaces of the indentation (usually |
themeInfo |
this argument is not important, it controls the theme of
the Shiny app;
it must be |
The reindented code in a character string.
Reindent some code using the V8 package.
reindent_V8(contents = NA, language = NA, tabSize = NULL)
reindent_V8(contents = NA, language = NA, tabSize = NULL)
contents |
the code to be reindented; there are three possibilities for
this argument:
|
language |
the language of the code, such as |
tabSize |
number of spaces of the indentation (usually |
The reindented code in a character string.
library(prettifyAddins) code <- c( "function f(x){", "return x+1", "}" ) cat(reindent_V8(code, "javascript"))
library(prettifyAddins) code <- c( "function f(x){", "return x+1", "}" ) cat(reindent_V8(code, "javascript"))
Word wrap a text.
wordWrap(contents = NA, ncharacters = 80)
wordWrap(contents = NA, ncharacters = 80)
contents |
the text to be wrapped; there are three possibilities for
this argument:
|
ncharacters |
target number of characters per line |
The wrapped text in a character string.