编号列表中的代码块(Wiki 语法)

在 MediaWiki (wikipedia 的) wiki 语法中,有没有一种方法可以在编号列表中加入代码块?

例如:

# Number 1
# Number 2
Indented section that will become a code block
# Number 3
# Number 4

在 MediaWiki 中会发生这样的事情:

1. Number 1
2. Number 2
Indented section that will become a code block
1. Number 3
2. Number 4

(请注意“数字3”和“数字4”是如何重置为1和2... 看起来 StackOverflow 比 MediaWiki 更聪明,我不得不把我的例子在 PRE 标签,使它搞砸了!)

我知道你可以使用“ # :”语法 缩进文本..。

# Number 1
# Number 2
#: Indented section that will merely be indented
# Number 3
# Number 4

... 但我真的想得到相同的可视化 CSS 类的代码,即使它是在一个编号列表。

对于嵌套的列表,它变得更加有趣。

# MainEntry 1
## Number 1
## Number 2
# MainEntry 2
## Number 1
## Number 2
Indented section that will become a code block
## Number 3
## Number 4

... 变成..。

1. MainEntry 1
1. Number 1
2. Number 2
2. MainEntry 2
1. Number 1
2. Number 2
Indented section that will become a code block
1. 1. Number 3
2. Number 4

(注意“ Number 3”现在是“1.1”)

31277 次浏览

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.

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

Bug 1584 - Need method for multiparagraph list items, continuing numbered lists, and assigning specific numbers to list items

By reading them, you will find the solution is to not use the MediaWiki syntax but to rely on "pure" HTML.

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>

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:

  • 1. one
    some stuff (just one indent level, not two)
    some more stuff
  • 2. two

  • 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&#10;code line 2</pre>
    # Numbered line 3.
    

    The secret is to replace the newlines with the entity and write everything in one line.

    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.

    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.