5

Is it possible to indent a block of code in MediaWiki using SyntaxHighlight GeSHi?

For example, I would like the code container below to be aligned with the third-level list

* This is plain text of a first-level list to be rendered by MediaWiki
** This is plain text of a a second-level list to be rendered by MediaWiki
*** This is plain text of a third-level list to be rendered by MediaWiki

<source lang="Cpp">
int main(int argc, char** argv)
{
    my_function(4, 1, 2, 3);
    return 0;
}
</source>

I have tried wrapping the GeSHi code container with colons (using MediaWiki's standard indentation syntax), but that prevents SyntaxHighlight GeSHi from parsing the code correctly.

Just to clarify, I would like to avoid wrapping my code with <code></code> as I need proper syntax highlighting.

Any suggestions?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

3 Answers3

6

You could always wrap it with normal HTML div tags as well:

<div style="margin-left: 2em;">
  <source ...>
    ...
  </source>
</div>
Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69
  • 1
    Good answer, thanks! This works reasonably well, but it does not allow you to continue the list below the code block -- a `***` will give you a triple-bullet, and a `::*` isn't quite the same (but the best solution I know of). – Dan Mar 16 '11 at 21:24
  • 1
    Is it really not possible to indent a dozen of code lines? Can't accept it -- there must be some way to do this. I 've tried too many things (reading [Meta, WikiMedia, Help:List](http://meta.wikimedia.org/wiki/Help:List)) and still did not find it. Any expert? – Nikos Alexandris Dec 29 '12 at 20:02
  • 1
    Dan: as of June 2013 there is no way to continue the numbering other than with HTML commands. See http://meta.wikimedia.org/wiki/Help:List#Specifying_a_starting_value. So the only solution to your problem is to us
      and friends.
    – Leo Jun 07 '13 at 13:38
4

You can put the source inside a table, and then indent the table:

:::{|
|
<source ...>
...
</source>
|}
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • 1
    Would have been wonderful, if instead of indentation (:::), it could also be done by normal bulleted list (#*). In other words, it would be good to have the ability to put a table as a bulleted item. – bbv Nov 25 '16 at 06:11
1

Maybe there is a way to misuse the <ul>...</ul> HTML element? A possible workaround is given (by Jeremy Koppel) at Meta, WikiMedia, Help:Editing FAQ among the answers to the question Can I put preformatted text inside a numbered list?:

<ul>
      <li>one</li>
      <li>two<pre>

Here are a couple lines...
...of preformatted text

      </pre></li>
      <li>and the numbering</li>
      <li>starts over</li>
   </ul>

I successfuly used this, in a WikiMedia based wiki, to highlight bash code under a bulleted text line, as follows:

 <ul>
<source lang="bash">sudo apt-get install \
build-essential \
...
libglu1-mesa-dev libxmu-dev</source>
   </ul>

Did not succeed to make it work for deeper levels though!

Nikos Alexandris
  • 708
  • 2
  • 22
  • 36