CodeMirror htmlwidget for R

This is an early version of a R htmlwidget version of CodeMirror by Marijn Haverbeke.

Installation

devtools::install_github("timelyportfolio/codemirrorR")

Examples

Simple

library(codemirrorR)

codemirror("hi")

Mode

library(codemirrorR)

codemirror(
  "
  library(codemirror)
  
  codemirror('hi')
  ",
  mode = "r"
)

library(codemirrorR)

codemirror(
  system.file(
    "htmlwidgets/codemirror.js",
    package = "codemirrorR"
  ),
  mode = "javascript",
  width = "100%",
  height = "400px"
)

library(codemirrorR)
library(xml2)
## Warning: package 'xml2' was built under R version 3.2.3
# ?xml2::readxml
cd <- read_xml("https://www.xmlfiles.com/examples/cd_catalog.xml")

codemirror(cd, mode = "xml", width = "100%", height = "400px")

Themes

library(codemirrorR)

codemirror(
  system.file(
    "htmlwidgets/codemirror.js",
    package = "codemirrorR"
  ),
  mode = "javascript",
  theme = "night"
)

Addons

will add much better support for addons

xml folding

library(codemirrorR)
library(xml2)

# ?xml2::readxml
cd <- read_xml("https://www.xmlfiles.com/examples/cd_catalog.xml")

cm <- codemirror(
  cd,
  mode = "xml",
  lineNumbers = TRUE
)

cm_foldcode(cm, "xml-fold")

brace folding

# brace fold
library(pipeR)

codemirror(
  system.file(
    "htmlwidgets/codemirror.js",
    package = "codemirrorR"
  ),
  mode = "javascript",
  theme = "night"
) %>>% cm_foldcode("brace-fold")

Praise, Thanks, and Attribution

For those of you who don’t know the incredible work of Marijn Haverbeke, go see it and fund him. Thanks Marijn!