Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMarkdown #1859

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
source 'https://rubygems.org'

gem 'warbler', platforms: :jruby

# FIXME:
Expand Down
1 change: 1 addition & 0 deletions lib/gollum/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Gollum::set_git_max_filesize(190 * 10**6)

Gollum::Filter::Code.language_handlers[/mermaid/] = Proc.new { |lang, code| "<div class=\"mermaid\">\n#{code}\n</div>" }
Gollum::Filter::Code.language_handlers[/{.*}/] =Proc.new { |lang, code| "<pre class=\"knitr\"><code class=\"#{lang}\">\n#{code}\n</code></pre>"}

# Run the frontend, based on Sinatra
#
Expand Down
2 changes: 2 additions & 0 deletions lib/gollum/public/gollum/javascript/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Require vendor assets from installed Node modules.
//= require mousetrap/mousetrap.min
//= require lodash/lodash.min

// Require application assets.
//= require jquery-1.7.2.min
Expand All @@ -12,3 +13,4 @@
//= require editor/sections
//= require jquery.resize
//= require polyfills
//= require rserve
24 changes: 24 additions & 0 deletions lib/gollum/public/gollum/javascript/gollum.js.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Helpers

const htmlDecode = (input) => {
const doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}

// Replace broken user icons with 'person' octicon
function brokenAvatarImage(image){
image.onerror = '';
Expand Down Expand Up @@ -86,6 +91,20 @@ function setTextDirection () {
$('.markdown-body p, .markdown-body span, .markdown-body pre, .markdown-body table').attr('dir','auto');
}

function replace_blocks (pre, data) {
pre.html(data['value']['value'][0])
}

function knitr () {
$( "pre.knitr" ).each(function (index) {
var pre = $(this)
code = $(this).children("code")
knitr_block = htmlDecode(('```' + code.attr('class') + "\n" + code.html() + "\n```\n")).replace(/"/g, '\\"');
knitr_cmd = "doc <- \"" + knitr_block + "\"\nlibrary(knitr)\nprint(knitr::knit2html(text = doc, fragment.only = TRUE, quiet = TRUE))"
rserve.eval(knitr_cmd, function (err, result) { if (err === null) { replace_blocks(pre, result); } } )
})
}

function preparePage () {
setTextDirection();
if(criticMarkup == 'true') {
Expand All @@ -94,6 +113,11 @@ function preparePage () {
$('span.critic.comment').wrap('<span class="popover" />');
$('span.critic.comment').filter(function() {return $(this).text()!="";}).before('&#8225;');
}
// Todo: check whether RMarkdown is enabled, make server configurable
var rserve = Rserve.create({
host: 'ws://127.0.0.1:2376',
on_connect: knitr
});
}

function getLocalTime(datetime_string, format) {
Expand Down
Loading