Package 'solarizeddocx'

Title: A 'Solarized' Theme for 'RMarkdown` `Docx` Documents
Description: An 'RMarkdown' output format for 'Microsoft' Word '.docx' documents created by 'pandoc'.
Authors: Tristan Mahr [aut, cre] , Ethan Schoonover [ctb, cph] (Solarized color themes), John MacFarlane [ctb, cph] (Pandoc templates), KDE contributors [ctb] (R syntax definition https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/r.xml)
Maintainer: Tristan Mahr <[email protected]>
License: GPL (>= 3) + file LICENSE
Version: 0.0.1.9000
Built: 2024-11-11 02:42:52 UTC
Source: https://github.com/tjmahr/solarizeddocx

Help Index


Syntax highlighting theme building tools

Description

Syntax highlighting theme building tools

Usage

colors_solarized_light()

copy_base_pandoc_theme(path)

set_theme_text_style(data, name, ...)

patch_theme_text_style(data, data_patches)

write_pandoc_theme(data, output_path)

Arguments

path

Path where to save pandoc's built-in syntax highlighting theme.

data

List containing data from a syntax highlighting theme's JSON file.

name

String name of the text styles to modify (e.g., "Function"). The theme is a list with global style settings and a sub-list text-styles with each of the specific token styles. (See examples.) Use "global" to modify the top-level theme elements or a name in data[["text-styles"]] to modify those styles.

...

Key-value pairs setting the style appearance. The keys can be one of the color setters: text (text-color), background (background-color), line (line-number-color), line_background (line-number-background-color). These fields take a hex color value. The keys can also be one of the font style setters: bold, underline, italic. These fields take TRUE or FALSE.

data_patches

Alternatively, we can provide provide a list of patches and use those to call set_theme_text_style(). For example, list(global = list(text = "#657b83"), Comment = list(color = "#93a1a1")) would apply the approach changes to the global and comment styles.

output_path

Path where to write out a pandoc syntax highlighting theme JSON file.

Value

copy_base_pandoc_theme(path) saves the pandoc syntax highlighting theme's JSON data to path and returns the path invisibly. set_theme_text_style() and patch_theme_text_style() return a modified syntax highlighting theme. write_pandoc_theme() writes out the pandoc syntax highlighting theme to a JSON file and invisibly returns the original data. colors_solarized_light() returns a list with the solarized light colors.

References

Solarized Light Theme colors via https://github.com/altercation/solarized#the-values

Examples

## Not run: 
s <- tempfile()
copy_base_pandoc_theme(s)
data_theme <- jsonlite::read_json(s)
str(data_theme, max.level = 2)
str(data_theme$`text-styles`$Comment)

# Interactive (pipe-able) interface

# bold pink roman comments
my_theme <- set_theme_text_style(
    data_theme,
    "Comment",
    text = "#ff748c",
    bold = TRUE,
    italic = FALSE
)
str(my_theme$`text-styles`$Comment)

# Patching interface

# Stub for a Fairy Floss theme https://github.com/sailorhg/fairyfloss
data_theme_patches <- list(
  global = list(text = "#F8F8F2", background = "#5A5475"),
  Function = list(text = "#C2FFDF"),
  Operator = list(text = "#FFB8D1"),
  Float = list(text = "#C5A3FF")
)
my_theme2 <- patch_theme_text_style(data_theme, data_theme_patches)
str(my_theme2$`text-styles`$Function)
str(my_theme2$`text-styles`$Float)

## End(Not run)

Render and open the demo RMarkdown file

Description

Render and open the demo RMarkdown file

Usage

demo_document()

Value

This function renders the built-in RMarkdown file and opens it. It returns the path to the rendered file invisibly.


Solarized Syntax Highlighting in Microsoft Word

Description

Solarized Syntax Highlighting in Microsoft Word

Usage

document(
  ...,
  reference_docx = "solarized",
  highlight = "solarized",
  syntax_definition = "solarized",
  pandoc_args = character(0)
)

Arguments

...

Arguments passed to rmarkdown::word_document().

reference_docx

Reference docx file to use. By default, this value is set to use "solarized" to use this package's file. Alternatively, one could "default" for pandoc's default file or a path to a custom docx file.

highlight

Syntax highlighting style to use. By default, this value is set to "solarized" to use this package's syntax definition. See alternatives in rmarkdown::word_document().

syntax_definition

Syntax definition to use for syntax highlighting. Defaults to "solarized" to use this package's language definition. This option is not one available to rmarkdown::word_document(), but setting this argument to NULL or "default" will use the default behavior.

pandoc_args

Additional command line options to pass to pandoc. (This should be a character vector of options.)

Value

An RMarkdown output format for Word documents.

Examples

## Not run: 
rmarkdown::render("test.Rmd", output_format = solarizeddocx::document())

## End(Not run)

Retrieve file paths to package resources

Description

Retrieve file paths to package resources

Usage

file_reference_docx()

file_syntax_definition()

file_solarized_light_theme()

file_syntax_test()

file_code_block()

Value

file_reference_docx() returns the path to the reference docx file used by this package. file_syntax_definition() returns the path to the XML file specifying how pandoc should highlight the code in the document. file_solarized_light_theme() returns the path to the .theme file used by this package. file_syntax_test() returns the path to the RMarkdown file used by demo_document(). file_code_block() returns a minimal .Rmd file with a single code block for small illustrations.

References

the reference docx is a modified version of the own built into pandoc by John MacFarlane. The syntax definition is a modified version of the one by the KDE developers. I used the code here: https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/r.xml