inst/shinyApp/server.R

language <- getOption("prettify.language")
code <- getOption("prettify.code")
codemirror <- getOption("prettify.codemirror")
action <- getOption("prettify.action")
tabSize <- getOption("prettify.tabSize")

if(action == "prettify"){
  parser <- switch(
    language,
    css = "css",
    html = "html",
    rhtml = "html",
    javascript = "babel",
    jsx = "babel",
    markdown = "markdown",
    scss = "css",
    sql = "sql",
    yaml = "yaml",
    typescript = "typescript"
  )
}else{
  if(codemirror){
    parser <- language
  }else{
    parser <- switch(
      language,
      css = "css",
      html = "html",
      rhtml = "html",
      javascript = "js",
      jsx = "js",
      scss = "css",
      typescript = "ts"
    )
  }
}


shinyServer(function(input, output, session){

  observeEvent(input[["cancel"]], {
    stopApp()
  })

  observeEvent(input[["done"]], {
    stopApp(input[["prettyCode"]])
  })

  session$sendCustomMessage(
    action,
    list(code = code, parser = parser, tabSize = tabSize)
  )

  observeEvent(input[["prettifyError"]], {
    message("An error occured. This is possibly due to invalid code.")
    stopApp()
  })

  observeEvent(input[["prettyCode"]], {
    req(!codemirror)
    updateAceEditor(
      session, "editor",
      mode = language, value = input[["prettyCode"]]
    )
  })

})

Try the prettifyAddins package in your browser

Any scripts or data that you put into this service are public.

prettifyAddins documentation built on Sept. 14, 2023, 5:06 p.m.