hasanghaforian
hasanghaforian

Reputation: 14022

bolding part of code in MediWiki

I use mediawiki-1.30.0 and want to bold a part of code snippet in MediaWiki. Unfortunately as it is described 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 extension which comes with MediaWiki 1.21 and above.

How I can bold part of code snippet without adding a space in front of each row?

Edit

I tested all these three:

<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>

The result was the same:

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

Only <code></code> bolds text, for example for both below codes

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

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

the result is:

a text inside another ... and another line

As you can see it processes <b></b>; but does not preserve new line characters.

Upvotes: 2

Views: 352

Answers (2)

a stone arachnid
a stone arachnid

Reputation: 1278

If you absolutely cannot add a space in front of each line, you could try using this: (somewhat inspired by @StanislavKralin's comment)

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

The .mw-code class mirrors the styles for <pre> for any element that has it. However, it also needs a display: block to be formatted correctly. If you didn't want to put the display: block on every instance, you could add the following code to the MediaWiki:Common.css page:

.mw-code{
    display: block;
}

Then, you would only have to add the .mw-code class to the <code> element.

However, this only works if no lines are skipped and the code isn't ever indented, this longer test case:

<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>

makes this: enter image description here Since this is not a <pre>, the wikitext is still parsed inside, such as a space making a code block, which is why we have all the nested codeblocks.


Alternatively, you could add a space in front of each row, like so:

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

yields:

a text inside another ...
and another line

and always works: test case with space

Upvotes: 3

Hershel
Hershel

Reputation: 163

You can use <code> and <b> and then use the <br> tag for new lines if you want:

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

the result is:

a text inside another

and another line

Upvotes: 1

Related Questions