Joachim Schork
Joachim Schork

Reputation: 2137

Highlight R Code Syntax in Wordpress

I would like to highlight R syntax in a wordpress blog, so that it looks similar as in RStudio. I found the wp-synthax-plugin, which is able to highlight R code as follows:

enter image description here

However, the colors are in my opinion way too extreme and I am searching for something more similar to basic RStudio. The code should be highlighted as follows:

enter image description here

Question: Is there a plugin for wordpress that produces such code or is there a way how to customize the colors myself?

Upvotes: 0

Views: 807

Answers (1)

chinsoon12
chinsoon12

Reputation: 25225

Original shBrushR.js

/**
*  Author: Yihui Xie
*  URL: http://yihui.name/en/2010/09/syntaxhighlighter-brush-for-the-r-language
*  License: GPL-2 | GPL-3
*/
SyntaxHighlighter.brushes.R = function() {
    var keywords = 'if else repeat while function for in next break TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_';
    var constants = 'LETTERS letters month.abb month.name pi';
    this.regexList = [
    { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
    { regex: SyntaxHighlighter.regexLib.singleQuotedString,    css: 'string' },
    { regex: SyntaxHighlighter.regexLib.doubleQuotedString,    css: 'string' },
    { regex: new RegExp(this.getKeywords(keywords), 'gm'),      css: 'keyword' },
    { regex: new RegExp(this.getKeywords(constants), 'gm'),    css: 'constants' },
    { regex: /[\w._]+[ \t]*(?=\()/gm,               css: 'functions' },
    ];
};
SyntaxHighlighter.brushes.R.prototype  = new SyntaxHighlighter.Highlighter(); SyntaxHighlighter.brushes.R.aliases = ['r', 's', 'splus']; 

suggested changes to have less highlighting to reply OP's comment:

/**
*  Author: Yihui Xie
*  URL: http://yihui.name/en/2010/09/syntaxhighlighter-brush-for-the-r-language
*  License: GPL-2 | GPL-3
*/
SyntaxHighlighter.brushes.R = function() {
    var keywords = 'if else repeat while function for in next break TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_';
    var constants = 'LETTERS letters month.abb month.name pi';
    this.regexList = [
    { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
    { regex: new RegExp(this.getKeywords(constants), 'gm'),    css: 'constants' },
    ];
};
SyntaxHighlighter.brushes.R.prototype  = new SyntaxHighlighter.Highlighter(); SyntaxHighlighter.brushes.R.aliases = ['r', 's', 'splus']; 

Upvotes: 1

Related Questions