Template:Codesample/doc
This is a documentation subpage for Template:Codesample. It contains usage information, categories and other content that is not part of the original Template page. |
This template augments a <syntaxhighlight> block with fancy colors and an optional title
Parameter | Description | Type | Status | |
---|---|---|---|---|
Title | name | Title (name) of this code sample. Often a filename | String | suggested |
Programming language | lang | Name of lexer to use for highlighting
| String | suggested |
Code | code 1 | Code sample to render | String | required |
Highlighted lines | highlight | Line(s) in example to highlight. Comma separated list of line numbers | String | optional |
Show line numbers | line | Enable line numbers for sample | Boolean | optional |
Starting line number | start | Starting line number when line numbers are shown. Note: Does not effect line numbers used for highlights.
| Number | optional |
Color scheme | scheme | Color scheme to use.
| String | optional |
Copy button | copy | Show a "copy" button to copy the code to the clipboard | Boolean | optional |
Examples
[edit]{{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
[edit]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
[edit]- {{Code }}
- {{Inline-code }}
- {{Codesample }}
- {{Terminal }}