“carbon.js is the easiest way to create beautiful images of your source code.”
This package uses an R6
api to interact with carbon.js and create directly from the console carbon images.
Like the image below:
The default code in the carbon object is taken from the clipboard.
But can also be defined inline. Code can be a character object of any length.
The code is kept in the object and can be changed at any time.
x$code
#> [1] "Package: carbonate"
#> [2] "Title: Interact with 'carbon.js'"
#> [3] "Version: 0.1.3"
#> [4] "Authors@R: "
#> [5] " person(given = \"Jonathan\","
#> [6] " family = \"Sidi\","
#> [7] " role = c(\"aut\", \"cre\"),"
#> [8] " email = \"yonicd@gmail.com\","
#> [9] " comment = c(ORCID = \"0000-0002-4222-1819\"))"
#> [10] "Description: Create beautiful images of source code using"
#> [11] " 'carbon.js'<https://carbon.now.sh/about>."
#> [12] "License: MIT + file LICENSE"
#> [13] "URL: https://github.com/yonicd/carbonate"
#> [14] "BugReports: https://github.com/yonicd/carbonate/issues"
#> [15] "Depends: "
#> [16] " R (>= 3.2.0)"
#> [17] "Imports: "
#> [18] " clipr,"
#> [19] " details,"
#> [20] " httr,"
#> [21] " magick,"
#> [22] " R6,"
#> [23] " RSelenium,"
#> [24] " rtweet,"
#> [25] " utils,"
#> [26] " wdman,"
#> [27] " yaml"
#> [28] "Suggests: "
#> [29] " covr,"
#> [30] " knitr,"
#> [31] " rmarkdown,"
#> [32] " testthat"
#> [33] "VignetteBuilder: "
#> [34] " knitr"
#> [35] "RdMacros: "
#> [36] " details"
#> [37] "Encoding: UTF-8"
#> [38] "LazyData: true"
#> [39] "Roxygen: list(markdown = TRUE)"
#> [40] "RoxygenNote: 6.1.1"
The main job of the R6 object is to convert all the options into a uri that is sent to the carbon url page, where it is processed.
x$uri()
#> [1] "https://carbon.now.sh/?bg=rgba(171%2C175%2C195%2C0.7)&t=panda-syntax&wt=none&l=r&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=11px&ph=14px&ln=false&fm=Fira%20Code&fs=14px&lh=133%25&si=false&es=1x&wm=false&ts=false&code=Package%253A%2520carbonate%250ATitle%253A%2520Interact%2520with%2520%27carbon.js%27%250AVersion%253A%25200.1.3%250AAuthors%2540R%253A%2520%250A%2520%2520%2520%2520person(given%2520%253D%2520%2522Jonathan%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520family%2520%253D%2520%2522Sidi%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520role%2520%253D%2520c(%2522aut%2522%252C%2520%2522cre%2522)%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520email%2520%253D%2520%2522yonicd%2540gmail.com%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520comment%2520%253D%2520c(ORCID%2520%253D%2520%25220000-0002-4222-1819%2522))%250ADescription%253A%2520Create%2520beautiful%2520images%2520of%2520source%2520code%2520using%250A%2520%2520%2520%2520%27carbon.js%27%253Chttps%253A%252F%252Fcarbon.now.sh%252Fabout%253E.%250ALicense%253A%2520MIT%2520%252B%2520file%2520LICENSE%250AURL%253A%2520https%253A%252F%252Fgithub.com%252Fyonicd%252Fcarbonate%250ABugReports%253A%2520https%253A%252F%252Fgithub.com%252Fyonicd%252Fcarbonate%252Fissues%250ADepends%253A%2520%250A%2520%2520%2520%2520R%2520(%253E%253D%25203.2.0)%250AImports%253A%2520%250A%2520%2520%2520%2520clipr%252C%250A%2520%2520%2520%2520details%252C%250A%2520%2520%2520%2520httr%252C%250A%2520%2520%2520%2520magick%252C%250A%2520%2520%2520%2520R6%252C%250A%2520%2520%2520%2520RSelenium%252C%250A%2520%2520%2520%2520rtweet%252C%250A%2520%2520%2520%2520utils%252C%250A%2520%2520%2520%2520wdman%252C%250A%2520%2520%2520%2520yaml%250ASuggests%253A%2520%250A%2520%2520%2520%2520covr%252C%250A%2520%2520%2520%2520knitr%252C%250A%2520%2520%2520%2520rmarkdown%252C%250A%2520%2520%2520%2520testthat%250AVignetteBuilder%253A%2520%250A%2520%2520%2520%2520knitr%250ARdMacros%253A%2520%250A%2520%2520%2520%2520details%250AEncoding%253A%2520UTF-8%250ALazyData%253A%2520true%250ARoxygen%253A%2520list(markdown%2520%253D%2520TRUE)%250ARoxygenNote%253A%25206.1.1"
Click the link to see the URI works.
Aesthetics of the carbon object that can be manipulated
Carbon Variable | Carbonate Variable | Description | Default |
---|---|---|---|
l | language | language | r |
bg | palette | layout pallete (vector with c(r,g,b,a) | c(r=171,g=184,b=195,a=1) |
t | template | layout template (listed in get_templates()) | ‘seti’ |
wc | add_window_control | add/remove window controls (circles on top left corner) | TRUE |
wt | window_control_theme | change window control themes (listed in get_windows_control_themes()) | ‘none’ |
ds | add_drop_shadow | add/remove dropshadow | TRUE |
dsyoff | drop_shadow_offset_y | shadow vertical offset (px) | 20 |
dsblur | drop_shadow_blur_radius | shadow blur radius (px) | 68 |
wa | auto_adjust_width | auto-audjust output width | TRUE |
pv | padding_vertical | vertical padding (px) | 48 |
ph | padding_horizontal | horizontal padding (px) | 32 |
ln | add_line_number | add/remove line numbers | FALSE |
fm | font_family | layout font family (listed in get_font_families()) | ‘Hack’ |
fs | font_size | font size (px) | 14 |
lh | line_height_percent | relative space between lines (percent) | 133 |
si | square_image | output image is square | FALSE |
es | relative_export_size | image size in export relative to what is in the preview (1,2 or 4) | 1 |
wm | add_watermark | add official carbon.js watermark | FALSE |
x$get_templates()
#> [1] "3024-night" "blackboard"
#> [3] "base16-dark" "base16-light"
#> [5] "cobalt" "dracula"
#> [7] "duotone" "hopscotch"
#> [9] "material" "monokai"
#> [11] "night-owl" "oceanic-next"
#> [13] "one-dark" "panda-syntax"
#> [15] "paraiso" "seti"
#> [17] "solarized dark" "solarized light"
#> [19] "tomorrow-night-bright" "lucario"
#> [21] "twilight" "verminal"
#> [23] "yeti" "zenburn"
Users can use a file called carbon.yml
and place it in their home directory (~
) to override the packages defaults in order to create a session peristent carbon template they like. The config file controls all the public carbon object fields. The following is an example of such a configuration file.
These fields will set
g
and a
fields to 175 and 0.7 respectivelypanda-syntax
Fira Code
All carbon outputs are collected and saved in the list x$carbons