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

发布于 2024-10-17 06:02:06 字数 1053 浏览 7 评论 0原文

在 MediaWiki(维基百科)的 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

注意“Number 3”和“Number 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。”)

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:

1. Number 1
2. Number 2
   Indented section that will become a code block
1. Number 3
2. 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...

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

(Note how "Number 3" is now "1. 1.")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

永言不败 2024-10-24 06:02:06

您可以尝试以下 wiki 语法,它在 1.17 上适用于我,

# one
#:<pre>
#::some stuff
#::some more stuff</pre>
# two

它并不完美,因为您最终会缩进更多,但它确实允许人们使用 wiki 语法来正确格式化前块多行。

如前所述,另一种正确的方法是使用 HTML 标记。

<ol>
<li>one</li>
<li>two</li>
<pre>some stuff
some more stuff</pre>
<li>three</li>
</ol>

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>
四叶草在未来唯美盛开 2024-10-24 06:02:06

使用 html:

<ol>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

它可以在 mediawiki 中使用。

请注意,从我下面发布的示例中,正是 使其正常工作。

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.

小伙你站住 2024-10-24 06:02:06

这在 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.

秘密是将换行符替换为
实体并将所有内容写在一行中。

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.

最美的太阳 2024-10-24 06:02:06

您的问题是 2004 年末和 2005 年 MediaWiki bug 跟踪器中填写的两个 bug 的主题:

Bug 1115 - 换行符作为列表项终结符很麻烦

Bug 1584 - 需要多段落列表项、连续编号列表以及为列表分配特定编号的方法items

通过阅读它们,您会发现解决方案是不使用 MediaWiki 语法,而是依赖“纯”HTML。

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.

坚持沉默 2024-10-24 06:02:06

我建议一个不同的答案:不要这样做。

我尝试使用所有解决方法来解决这个基本的 Mediawiki 问题,但发现它们都非常不完美。我已经学会了没有数字的生活,而是:

  • 对我的所有列表使用 splat (*) 而不是 (#)
  • 继续对我的所有代码块使用前导空格

这比任何解决方法要简单得多且易于维护。此外,随着步骤的编辑,对数字的任何引用的使用都可能发生变化 - 这将成为另一个维护问题。

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.

花伊自在美 2024-10-24 06:02:06

在上面的示例中,第二个缩进 (::) 不是必需的。

只需一个缩进即可正常工作 (:),如下所示:

# one
#:<pre>
#:some stuff
#:some more stuff</pre>
# two

产生:

  • 1. one
     一些东西(只是一个缩进级别,而不是两个)
       还有一些东西
  • 2. 两个

  • 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

  • 人生百味 2024-10-24 06:02:06

    您还可以尝试在“pre”标签周围添加“blockquote”标签,使其看起来更精致。

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

    这将使灰色框与您的项目符号/数字一致,而不使用冒号。

    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.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文