Help:Contributing/code: Difference between revisions
Carve out <code> for plain inline tokens without markup-significant characters, aligning with content-creation AGENTS.md (via update-page on MediaWiki MCP Server) |
Add plain inline code row (<code>) to the comparison table, demonstrating the carve-out (via update-page on MediaWiki MCP Server) |
||
| Line 19: | Line 19: | ||
| <translate><!--T:9--> <syntaxhighlight lang="sparql">SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5</syntaxhighlight></translate> | | <translate><!--T:9--> <syntaxhighlight lang="sparql">SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5</syntaxhighlight></translate> | ||
| <syntaxhighlight lang="sparql">SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5</syntaxhighlight> | | <syntaxhighlight lang="sparql">SELECT ?item WHERE { ?item wdt:P1 wd:Q6 } LIMIT 5</syntaxhighlight> | ||
|- | |||
| <translate><!--T:45--> Plain inline code — monospace within a sentence, no highlighting. Fine for short plain tokens without markup-significant characters.</translate> | |||
| <translate><!--T:46--> <code>latestId</code></translate> | |||
| <code>latestId</code> | |||
|- | |- | ||
| <translate><!--T:10--> Syntax-highlighted inline code — monospace within a sentence.</translate> | | <translate><!--T:10--> Syntax-highlighted inline code — monospace within a sentence.</translate> | ||
Revision as of 16:56, 19 August 2026
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
|
| Plain inline code — monospace within a sentence, no highlighting. Fine for short plain tokens without markup-significant characters. | <code>latestId</code> | latestId
|
| 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. For short plain tokens with none of those characters (#,quarto render)<code>is fine and lighter to render. Prefer<syntaxhighlight inline>whenever the snippet contains<,>or&(it escapes content) or you want syntax highlighting; never use<code>for blocks — use<pre>or<syntaxhighlight>.
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
|
inlineandcopyare 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
- MediaWiki syntax 101 (official)
- SyntaxHighlight extension (official)
- Pygments lexers — full language list
- Help:Contributing — contributing to this wiki