Skip to content

Instantly share code, notes, and snippets.

View cderv's full-sized avatar

Christophe Dervieux cderv

View GitHub Profile
@cderv
cderv / r.xml
Last active October 4, 2021 10:34
KDE syntax definition for R including correctly highlighting for new R native pipe
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!-- Kate 2.5 (KDE 3.5) highlighting module for R
based on an earlier version by E.L. Willighagen. Code folding code by Ben Goodrich
version 2.0: (c) 2006 Thomas Friedrichsmeier, Arne Henningsen, and the RKWard Team
license: GPL v2
Kate : http://kate.kde.org/
R : http://www.r-project.org/
RKWard : http://rkward.kde.org/
-->
@cderv
cderv / Notes.md
Last active August 20, 2021 09:12
How to debug Lua filter in Pandoc
  • This does not work yet
  • Zerobrane is correctly configured but still get an error
    pandoc.exe: Cannot decode byte '\x92': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream
    

It seems like what is sent to Pandoc is not ok.

@cderv
cderv / pandoc_releases.R
Created July 1, 2021 14:47
Analysis of Pandoc available releases on Github
# Check pandoc version file
devtools::load_all()
library(dplyr)
library(purrr)
library(tidyr)
releases <- pandoc_releases()
releases2 <- map(releases, "[[", c("tag_name"))
@cderv
cderv / list_extensions.R
Created May 27, 2021 14:20
List format and extensions from Pandoc in R
pandoc_list_extension <- function(format = "markdown") {
res <- processx::run(rmarkdown::pandoc_exec(), c("--list-extension", format))
tmp_file <- tempfile()
on.exit(unlink(tmp_file))
brio::write_file(res$stdout, tmp_file)
ext <- brio::read_lines(tmp_file)
tibble::tibble(
format = format,
extensions = gsub("^[-+]", "", extensions),
default = ifelse(gsub("^([-+]{1}).*", "\\1", ext) == "+", TRUE, FALSE)
@cderv
cderv / pseudocode.Rmd
Last active April 19, 2021 08:18
Use pseudocode.js in R Markdown document
---
title: "test"
output:
html_document:
self_contained: false
includes:
in_header: head.html
---
<!-- creating header file to insert in-header. mathjax config seems to be required -->
@cderv
cderv / check.lua
Last active April 9, 2021 12:34
Check Pandoc Version in LUA for 2.1+
--[[
This function tests the pandoc version againt a target version
For Pandoc 2.7.3, PANDOC_VERSION >= "2.8" would be enough but before 2.7.3
it is a table object
]]
local function pandocAvailable(target)
-- this function only work for Pandoc 2.1 and above. It returns false is not
if not PANDOC_VERSION then return false end
assert(target, "No target version specified in pandocAvailable.")
-- checking each version number
@cderv
cderv / import.lua
Last active April 9, 2021 08:50
import a script in a Pandoc lua filter
-- MIT LICENCE - 2021 Christophe Dervieux
-- Only works with Pandoc 2.1.2+ because of PANDOC_SCRIPT_FILE availability
function import(script)
local PATH_SEP = package.config:sub(1,1)
local path = PANDOC_SCRIPT_FILE:match("(.*"..PATH_SEP..")")
dofile(path .. script)
end
import("utils.lua")
@cderv
cderv / Makefile
Last active February 9, 2021 10:15
TOC in GFM output by Pandoc
all: test-gfm2.md test-gfm.md
test-gfm2.md: test.md
pandoc -f markdown+gfm_auto_identifiers -t gfm -s --table-of-contents -o $@ $<
test-gfm.md: test.md
pandoc -f markdown -t gfm -s --table-of-contents -o $@ $<
@cderv
cderv / How-to.md
Created December 10, 2020 14:12
Deploy Bookdown to RStudio Connect programatically

How to deploy to Rstudio Connect : Push mode

Theory

  • Create a manifest using rsconnect
  • Use API to create content on RSC -> GUID
  • Create a tar.gz bunlde with the manifest
  • USe API to push the bundle

Creating a Manifest

@cderv
cderv / R_in_lua.Rmd
Created November 30, 2020 16:02
R in lua
---
title: "Use R in a lua filter"
output:
html_document:
pandoc_args: !expr rmarkdown::pandoc_lua_filter_args("my.lua")
---
This document will have uppercase header using R function `toupper()`
```{cat, engine.opts = list(file = "my.lua")}