跳转到内容

模板:Codesample/doc

来自天灾之下:危险连接资料站
wiki>Waddie962025年8月5日 (二) 11:01的版本 (→See also:​ add)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

This template augments a <syntaxhighlight> block with fancy colors and an optional title

模板参数

此模板首选参数换行的代码块格式。

参数描述类型状态
Titlename

Title (name) of this code sample. Often a filename

字符串推荐
Programming languagelang

Name of lexer to use for highlighting

默认值
text
示例值
shell-session
字符串推荐
Codecode 1

Code sample to render

字符串必需
Highlighted lineshighlight

Line(s) in example to highlight. Comma separated list of line numbers

字符串可选
Show line numbersline

Enable line numbers for sample

布尔可选
Starting line numberstart

Starting line number when line numbers are shown. Note: Does not effect line numbers used for highlights.

默认值
1
数字可选
Color schemescheme

Color scheme to use.

默认值
dark
字符串可选
Copy buttoncopy

Show a "copy" button to copy the code to the clipboard

布尔可选

Examples

{{Codesample |echo "hello world!"}}
echo "hello world!"
{{Codesample |echo "hello world!" |lang=text |scheme=light}}
echo "hello world!"
{{Codesample |$ echo "hello world!" |lang=shell-session |scheme=dark}}
$ echo "hello world!"
{{Codesample |code=<nowiki>{{Codesample}}</nowiki> |lang=wikitext}}
{{Codesample}}
{{Codesample |name=ingress.yaml |lang=yaml |scheme=dark |line=1 |highlight=5,8 |code=
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: foo-redirect
  namespace: tool-foo
  labels:
    name: foo-redirect
  annotations:
    kubernetes.io/ingress.class: nginx
}}
ingress.yaml
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: foo-redirect
  namespace: tool-foo
  labels:
    name: foo-redirect
  annotations:
    kubernetes.io/ingress.class: nginx
{{Codesample |name=metadata |lang=yaml |scheme=light |line=1 |start=5 |highlight=1,4 |code=
  name: foo-redirect
  namespace: tool-foo
  labels:
    name: foo-redirect
  annotations:
    kubernetes.io/ingress.class: nginx
}}
metadata
name: foo-redirect
  namespace: tool-foo
  labels:
    name: foo-redirect
  annotations:
    kubernetes.io/ingress.class: nginx
{{Codesample |echo "hello world!" |copy=}}
echo "hello world!"

Adding a new color scheme

The scheme=... parameter will load a css sub-page to add styles matching the Pygments markup definitions. The easiest way to introduce a new scheme is to export it from Pygments itself: pygmentize -f html -S $style -a .wt-codesample-${style}.

See also