DokuWiki

It's better when it's simple

用户工具

站点工具


zh:syntax_highlighting

语法高亮显示

DokuWiki支持语法页面中的代码语法高亮显示。

从DokuWiki版本“Greebo”开始,支持一些额外的语法高亮显示GeShi选项:

  • 启用行号
  • 从第 n 行起始行号
  • 特别标注某些行

所有选项都是通过向标准代码标记语法添加一些键值对来设置的。下面的例子解释了它们的用法。

例子

以下代码启用行号:

<code JavaScript [enable_line_numbers="true"]>
var de = function() {
	return (typeof(window.de) == 'object') ? window.de : {};
}();
</code>

表现效果:

  1. var de = function() {
  2. return (typeof(window.de) == 'object') ? window.de : {};
  3. }();

这一个示例标注显示了一行代码:

<code JavaScript [enable_line_numbers="true",highlight_lines_extra="2"]>
var de = function() {
	return (typeof(window.de) == 'object') ? window.de : {};
}();
</code>

表现效果:

  1. var de = function() {
  2. return (typeof(window.de) == 'object') ? window.de : {};
  3. }();

还可以标注显示多行:

<code JavaScript [enable_line_numbers="true",highlight_lines_extra="2,3"]>
var de = function() {
	return (typeof(window.de) == 'object') ? window.de : {};
}();
</code>

表现效果:

  1. var de = function() {
  2. return (typeof(window.de) == 'object') ? window.de : {};
  3. }();

行号可以从任何给定值开始:

<code C [enable_line_numbers="true", start_line_numbers_at="42"]>
void main () {
    printf ("Hello World!");
    exit 0;
}
</code>

表现效果:

  1. void main () {
  2. printf ("Hello World!");
  3. exit 0;
  4. }
zh/syntax_highlighting.txt · 最后更改: 2022-05-07 02:50 由 2409:8a44:6c16:8461:90c:f26a:b005:832f

除额外注明的地方外,本维基上的内容按下列许可协议发布: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki