Confluence 的 R 语法高亮显示
R Syntax Highlighting for Confluence
有没有办法在 confluence 中高亮显示 R 语法?我试过常规配置> 配置代码宏> 添加新语言,但我不知道如何为 R 上传自定义画笔语法..有没有人已经这样做了或者有没有办法为 R 获取它?
为了添加语法高亮显示 "brush" javascript 文件,我发现以下过程工作得很好。
从以下位置获取最新的 Syntaxhighlighter:
http://alexgorbatchev.com/SyntaxHighlighter/
例如3.0.83 截至 2016-05
解压它并创建一个 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 文件并对它感到满意时,您可以通过常规配置 > 配置代码宏 > 添加新语言(和希望将生成的 js 文件添加到这个答案中,使它成为一个完整的解决方案 - 抱歉,我自己不了解 R,所以我在这部分帮不上什么忙)
以下面的R刷(取自上面的link)为例:
/**
* 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'];
有没有办法在 confluence 中高亮显示 R 语法?我试过常规配置> 配置代码宏> 添加新语言,但我不知道如何为 R 上传自定义画笔语法..有没有人已经这样做了或者有没有办法为 R 获取它?
为了添加语法高亮显示 "brush" javascript 文件,我发现以下过程工作得很好。
从以下位置获取最新的 Syntaxhighlighter: http://alexgorbatchev.com/SyntaxHighlighter/
例如3.0.83 截至 2016-05
解压它并创建一个 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 文件并对它感到满意时,您可以通过常规配置 > 配置代码宏 > 添加新语言(和希望将生成的 js 文件添加到这个答案中,使它成为一个完整的解决方案 - 抱歉,我自己不了解 R,所以我在这部分帮不上什么忙)
以下面的R刷(取自上面的link)为例:
/**
* 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'];