gpt4 book ai didi

Confluence 的 R 语法高亮

转载 作者:行者123 更新时间:2023-12-03 21:30:34 27 4
gpt4 key购买 nike

有没有办法在融合中突出显示 R 语法?我已经尝试过常规配置 > 配置代码宏 > 添加新语言,但我不知道如何为 R 上传自定义画笔语法。

最佳答案

为了添加一个语法高亮“画笔”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 文件并对其感到满意后,您可以通过常规配置> 配置代码宏> 添加新语言(并希望添加结果)将其上传到 Confluence 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'];

关于Confluence 的 R 语法高亮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906490/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com