Is there any MediaWiki extension that supports inline syntax highlighting? (i.e. with support for code snippets embedded within regular text paragraphs)
I currently use SyntaxHighlight GeSHi, but I'm not sure it supports inline highlighting.
You can add enclose="none"
to your <source>
tag:
There is <source lang="mylanguage" enclose="none">inline code</source> in this paragraph.
The simplest solution is using: <code>put your code here</code>
While using <code>inline code</code>
or, for example, <syntaxhighlight lang="groovy" inline>inline code</syntaxhighlight>
works typing this in is a real pain, especially if you deal with a lot of code snippets.
If the wiki is under your control you can extend its markup. The example below shows how to shorten the above to <c>inline code</c>
and <sg>inline code</sg>
respectively using tag extensions method.
Create Customtags
directory for your new extension in your MediaWiki extensions directory (MW_HOME/extensions/
). In this directory create a customtags.php
file with the following content:
<?php
$wgHooks['ParserFirstCallInit'][] = 'customtagsInit';
function customtagsInit(Parser $parser) {
// parameters: custom tag, custom renderer function
$parser->setHook('c', 'customRenderShortCode');
$parser->setHook('sg', 'customRenderSourceGroovy');
return true;
}
function customRenderSourceGroovy($input, array $args, Parser $parser, PPFrame $frame) {
$input = '<syntaxhighlight lang="groovy" inline>' . $input . '</syntaxhighlight>';
$wikiparsed = $parser->recursiveTagParse($input, $frame);
return $wikiparsed;
}
function customRenderShortCode($input, array $args, Parser $parser, PPFrame $frame) {
$wikiparsed = $parser->recursiveTagParse($input, $frame);
return '<code>' . $wikiparsed . '</code>';
}
?>
Finally register this extension in LocalSettings.php
and you are good to go:
require_once "$IP/extensions/Customtags/customtags.php";
In a similar way you can create short tags for larger blocks of code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With