R语法突出显示为汇合

时间:2016-04-28 06:05:17

标签: r confluence

有没有办法在汇合时获得R语法高亮?我试过一般配置>配置代码宏>添加新语言,但我不知道如何为R..上传任何已经完成此操作的自定义画笔语法,或者有没有办法可以为R获取它?

1 个答案:

答案 0 :(得分:4)

为了添加语法高亮的“刷”javascript文件,我发现以下过程可以很好地工作。

从以下位置获取最新的Syntaxhighlighter: http://alexgorbatchev.com/SyntaxHighlighter/

e.g。截至2016-05的3.0.83

解压缩并创建一个使用它的index.html文件,如:

<!DOCTYPE html>
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- Include required JS files -->
<script type="text/javascript" src="js/shCore.js"></script>

<!--
    At least one brush, here we choose JS. You need to include a brush for every 
    language you want to highlight
-->
<script type="text/javascript" src="css/shBrushRule.js"></script>

<!-- Include *at least* the core style and default theme -->
<link href="css/shCore.css" rel="stylesheet" type="text/css" />
<link href="css/shThemeDefault.css" rel="stylesheet" type="text/css" />
</head>
<body> 
<!-- You also need to add some content to highlight, but that is covered elsewhere. -->
<pre class="brush: R">
add your R code here
</pre>

<!-- Finally, to actually run the highlighter, you need to include this JS on your page -->
<script type="text/javascript">
     SyntaxHighlighter.all()
</script>
</body>
</html>

中的

<pre></pre>

你可能想要添加一些R代码。要创建R画笔,您可能需要使用css文件夹中的一些画笔:

shBrushAS3.js         shBrushDelphi.js      shBrushPerl.js        shBrushSass.js
shBrushAppleScript.js shBrushDiff.js        shBrushPhp.js         shBrushScala.js shBrushBash.js        shBrushErlang.js      shBrushPlain.js       shBrushSql.js
shBrushCSharp.js      shBrushGroovy.js      shBrushPowerShell.js  shBrushTcl.js
shBrushColdFusion.js  shBrushJScript.js     shBrushPython.js      shBrushVb.js
shBrushCpp.js         shBrushJava.js        shBrushRuby.js        shBrushXml.js
shBrushCss.js         shBrushJavaFX.js      shBrushRule.js

它只需要几行代码和正则表达式来设置关键字和注释,变量和其他规则。当你在互联网上创建(或搜索它,例如https://gist.github.com/yihui/1804862)shBrushR.js文件并对它感到满意时,你可以通过常规配置&gt;将其上传到汇合处。配置代码宏&gt;添加新语言(并希望将生成的js文件添加到此答案中,以使其成为一个完全完整的解决方案 - 抱歉,我自己也不知道R,所以我对此部分无能为力)

参见下面的R刷(摘自上面的链接)作为例子:

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