将 MediaWiki 中的部分代码加粗

bolding part of code in MediWiki

我使用 mediawiki-1.30.0 并想在 MediaWiki 中加粗部分代码片段。不幸的是,正如所描述的那样,here, it seems <b></b> does not work in pre tag. Also I did not find any way to bold a part of code in SyntaxHighlight_GeSHi 扩展随 MediaWiki 1.21 及更高版本一起提供。

如何在不在每行前面添加 space 的情况下 加粗代码段

编辑

我测试了这三个:

<pre>
a <strong>text</strong> inside another ...
</pre>


<pre>
a &lt;strong&gt;text&lt;/strong&gt; inside another ...
</pre>

<code>
a &lt;strong&gt;text&lt;/strong&gt; inside another ...
</code>

结果是一样的:

a <strong>text</strong> inside another ...

只有 <code></code> 粗体文本,例如以下代码

<code>
a <strong>text</strong> inside another ...
and another line
</code>

<code>
a <b>text</b> inside another ...
and another line
</code>

结果是:

a text inside another ... and another line

如您所见,它正在处理 <b></b>;但不保留 new line 个字符。

您可以使用 <code><b>,然后根据需要使用 <br> 标签换行:

<code>
a <strong>text</strong> inside another ...
<br>and another line
</code>

结果是:

a text inside another

and another line

如果你绝对不能在每一行前面添加一个 space,你可以尝试使用这个:(有点受@StanislavKralin 的评论启发)

<code class="mw-code" style="display:block">
a <strong>text</strong> inside another ...
and another line
</code>

.mw-code class 镜像 <pre> 的任何元素的样式。但是,它还需要 display: block 才能正确格式化。如果您不想在每个实例上都放置 display: block,您可以将以下代码添加到 MediaWiki:Common.css 页面:

.mw-code{
    display: block;
}

然后,您只需将 .mw-code class 添加到 <code> 元素。

但是,这仅适用于如果没有跳过任何行并且代码从未缩进,这个更长的测试用例:

<code class="mw-code" style="display:block">
using System;

namespace <b>GDB</b>
{
    class Program
    {
        static void Main(string argv)
        { 
            Console.Write("Hello!");

            Console.Read();
        }
    }
}
</code>

使这个: 由于这是不是一个<pre>,wiki文本还是在里面解析,比如一个space做一个代码块,这就是为什么我们有所有嵌套的代码块.


或者,你可以在每一行前面添加一个space,像这样:

 a <strong>text</strong> inside another ...
 and another line

产量:

a text inside another ...
and another line

并且始终有效: