2011-02-02 94 views
16

是否有任何MediaWiki擴展支持內聯語法高亮顯示? (即支持嵌入常規文本段落中的代碼片段)MediaWiki中的內聯語法高亮

我目前使用SyntaxHighlight GeSHi,但我不確定它是否支持內聯突出顯示。

+0

有關信息:對於*不內聯*,最簡單的解決方法是在行的開頭放置一個空格字符。 – Wikis 2012-12-29 19:00:09

回答

17

您可以添加enclose="none"<source>標籤:

There is <source lang="mylanguage" enclose="none">inline code</source> in this paragraph. 
+0

確實有用!但是,1)`代碼`文本看起來(太)小(er),2)沒有辦法說'代碼`,實際上是指` code`? – 2012-12-29 10:40:07

+1

更新:支持的標籤現在是`內聯代碼`,儘管上述內容仍然適用於兼容性。另外,自[2015年6月](https://gerrit.wikimedia.org/r/#/c/218584/)MediaWiki使用[Pygments](https://en.wikipedia.org/wiki/Pygments)代替GeSHi 。有關更多信息,請參閱:https://www.mediawiki.org/wiki/Extension:SyntaxHighlight – WinTakeAll 2016-03-27 06:15:56

8

最簡單的辦法是使用:<code>put your code here</code>

0

首先,標記你關心與span, code, source, div, p,等。對於直列最小的變化特點,跨度可能是你在找什麼。

其次,將樣式應用於標記字符。爲了突出你可能要像background: yellow

例子:

Highlights like <span style="border:thin solid green; background: yellow;">this</span> really draw the eye.

0

我發現,封閉與<pre></pre>整個塊顯示格式是最好的。

0

在使用<code>inline code</code>或例如<syntaxhighlight lang="groovy" inline>inline code</syntaxhighlight>時,輸入此內容是一件非常痛苦的事情,尤其是在處理大量代碼片段時。

如果這個wiki在你的控制之下,你可以extend its markup。下面的示例顯示瞭如何使用tag extensions方法分別縮短到<c>inline code</c><sg>inline code</sg>

在您的MediaWiki擴展目錄(MW_HOME/extensions/)中爲您的新擴展名創建Customtags目錄。在這個目錄下創建一個customtags.php文件,內容如下:

<?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>'; 
} 

?> 

LocalSettings.php最後註冊這個擴展,你是好去:

require_once "$IP/extensions/Customtags/customtags.php"; 

以類似的方式,你可以爲更大的創造短標籤代碼塊。