Help:Contributing/code

From Wikibase
Revision as of 08:54, 19 August 2026 by SeedBot (talk | contribs) (Marked this version for translation)
Jump to navigation Jump to search

Languages: English · français · Esperanto


Code appears on this wikibase in two places: as content on wiki pages (this page) and as data (code-snippet items created via Special:AddCodeSnippet). This page covers the former.

Code blocks on wiki pages

Description You type You get
Plain preformatted block — text exactly as typed, no wiki markup interpreted, HTML escaped. Safe for pasting raw code. <pre>print("hello")</pre>
print("hello")
Syntax-highlighted block — Pygments highlighting and a copy button (top right of the block). <syntaxhighlight lang="sparql">SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5</syntaxhighlight>
SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5
Syntax-highlighted inline code — monospace within a sentence. <syntaxhighlight lang="python" inline>print("hello")</syntaxhighlight> print("hello")

Anything inside <syntaxhighlight> or <pre></pre> will not be interpreted. They are rendered literally.

You may see <code>…</code> used for inline code by others. It does not escape HTML: text such as < or & inside it is read as markup. Prefer <syntaxhighlight inline> instead.

Which languages can be highlighted

Any Pygments lexer alias works as the lang attribute — use the lowercase canonical name:

  • sparql — SPARQL queries (this wiki's query service)
  • python, javascript, bash, sql, json, wikitext — commonly used
  • Full list: Pygments lexers (use the alias column)

Options for highlighted blocks

Option You type You get
line — show line numbers <syntaxhighlight lang="sparql" line>SELECT ?item WHERE {
?item wdt:P1 wd:Q6 .
}</syntaxhighlight>
SELECT ?item WHERE {
?item wdt:P1 wd:Q6 .
}
start="{int}" — first line number (with line) <syntaxhighlight lang="sparql" line start="5">SELECT ?item WHERE {
?item wdt:P1 wd:Q6 .
}</syntaxhighlight>
SELECT ?item WHERE {
?item wdt:P1 wd:Q6 .
}
highlight — highlight specific lines (comma-separated) <syntaxhighlight lang="sparql" highlight="1,3">SELECT ?item WHERE {
?item wdt:P1 wd:Q6 .
}</syntaxhighlight>
SELECT ?item WHERE {
?item wdt:P1 wd:Q6 .
}
inline — render as inline code instead of a block <syntaxhighlight lang="sparql" inline>LIMIT</syntaxhighlight> LIMIT
copy — adds a button that copies the block <syntaxhighlight lang="sparql" copy>SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5</syntaxhighlight>
SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5

inline and copy are mutually exclusive.

Full parameter reference: SyntaxHighlight extension parameters (official).

Differences from Markdown

Markdown habit On this wiki
Fenced code blocks (```) There are no fenced blocks — ``` does nothing. Use <pre> or <syntaxhighlight>.
Literal [[ and {{ inside a fenced block In <pre> and <syntaxhighlight> wiki markup is not interpreted — {{, [[ and quotes appear literally, which is what you want for code.

Blocks larger than 100 kB lose highlighting automatically (a safety guard).

House rules for code content

  • Prefer <syntaxhighlight lang="…"> for anything syntax-highlightable; use <pre> for config dumps and logs where colours add noise.

See also