Code block in numbered list (Wiki syntax)
SyntaxWikiMediawikiSyntax Problem Overview
In MediaWiki (wikipedia's) wiki syntax, is there a way to have a numbered list with a code block in the middle?
For example:
Number 1
Number 2
Indented section that will become a code block
Number 3
Number 4
What happens in MediaWiki is you end up with something like this:
- Number 1
- Number 2 Indented section that will become a code block
- Number 3
- Number 4
(Note how "Number 3" and "Number 4" are reset as 1 and 2... It looks like StackOverflow is much smarter than MediaWiki, i had to put my example in PRE tags to make it screw up!)
I know you can indent text using "#:" syntax...
Number 1
Number 2
#: Indented section that will merely be indented
Number 3
Number 4
...but I really would like to get the same visual CSS class for my code even if it's in a numbered list.
It gets even more entertaining with nested lists. This syntax...
MainEntry 1
Number 1
Number 2
MainEntry 2
Number 1
Number 2
Indented section that will become a code block
Number 3
Number 4
...becomes...
- MainEntry 1
- Number 1
- Number 2
- MainEntry 2
- Number 1
- Number 2 Indented section that will become a code block
- Number 3
- Number 4
(Note how "Number 3" is now "1. 1.")
Syntax Solutions
Solution 1 - Syntax
You could try the following wiki syntax, it works for me on 1.17
# one
#:<pre>
#::some stuff
#::some more stuff</pre>
# two
It is not perfect, because you end up with a more indent but it does allow one to use the wiki syntax for correctly formatted pre blocks over multiple lines.
As previously mentioned, the other proper way would be to use HTML mark up.
<ol>
<li>one</li>
<li>two</li>
<pre>some stuff
some more stuff</pre>
<li>three</li>
</ol>
Solution 2 - Syntax
Use html:
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
it will work in mediawiki.
Note from the example that I posted below, it is the </li>
that makes it work properly.
Solution 3 - Syntax
This works fine in MediaWiki 1.17.0:
===Alternative way of using pre in numbered lists.===
# Numbered line 1.
# Numbered line 2.<pre>code line 1 code line 2</pre>
# Numbered line 3.
The secret is to replace the newlines with the entity and write everything in one line.
Solution 4 - Syntax
Your issue is the subject of two bugs filled in the MediaWiki bug tracker in late 2004 and 2005 :
Bug 1115 - Newline as list item terminator is troublesome
By reading them, you will find the solution is to not use the MediaWiki syntax but to rely on "pure" HTML.
Solution 5 - Syntax
I'm suggesting a different answer: don't do it.
I've attempted to use all the workarounds for this basic Mediawiki issue and found that they are all very imperfect. I've learned to live without numbers, and instead:
- Use the splat (*) instead of (#) for all my lists
- Continue to use the leading space for all my code blocks
This is far far simpler and maintainable than any workaround. Besides, use of any reference to a number is subject to change as the steps are edited - and this then becomes another maintenance issue.
Solution 6 - Syntax
In the above example the second indentation (::) is not necessary.
Just one indentation works fine (:) as follows:
# one
#:<pre>
#:some stuff
#:some more stuff</pre>
# two
Produces:
some stuff (just one indent level, not two) some more stuff
Solution 7 - Syntax
You can also try adding a "blockquote" tag surrounding the "pre" tag, makes it look a little more polished.
== HAProxy Configuration ==
#'''File:''' /etc/haproxy/haproxy.cfg
<blockquote>
<pre>
global
log 127.0.0.1 local1 notice
maxconn 4096
#daemon
debug
crt-base /usr/local/haproxy/ssl
</pre>
</blockquote>
Which will indent the gray box in line with your bullets/numbers without using colons.