在Wordpress中突出显示R代码语法

时间:2018-01-26 09:34:24

标签: r wordpress syntax syntax-highlighting

我想在wordpress博客中强调R语法,以便它看起来与RStudio类似。我找到了wp-synthax-plugin,它能够突出显示R代码如下:

enter image description here

然而,在我看来,颜色太过极端,我正在寻找更类似于基本RStudio的东西。代码应突出显示如下:

enter image description here

问题:是否有一个wordpress插件可以生成这样的代码,或者有没有办法自己定制颜色?

1 个答案:

答案 0 :(得分:1)

原创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']; 

建议更改以减少回复OP的评论:

/**
*  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'];