Place a table in an Ordered List in Mediawiki
Asked Answered
W

4

7

I'm trying to place a table inline in an ordered list in Mediawiki however it breaks my numbering. What I want is

1. A1
1.1 B1
1.2 B2
my table
2. A2

but what I get is

1. A1
1.1 B1
1.2 B2
my table
1. A2

Basic markup I'm using is;

# A1
## B1
## B2
my table
#A2
Waylan answered 18/3, 2017 at 13:14 Comment(0)
P
5

I don't think it's possible with wikitext, but you can use HTML lists to make the table part of B2:

<ol>
<li> A1 <ol>
<li> B1
<li> B2
{|class=wikitable
! Header
|-
| Data
|}
</ol>
<li>A2
</ol>

The other thing that can help in situations like this (although not, it seems, this particular one) is the value parameter for list items.

Planometer answered 18/3, 2017 at 21:31 Comment(1)
This is one of the two solutions of mediawiki.org/wiki/Topic:Q9xbaa4rctdx3vn1Bremble
T
2

As alternative to Sam Wilson's answer you can keep wiki markup for ordered list, but use HTML markup for table instead. To do so you'll need to replace all line breaks within table markup with HTML comments, like this:

# A
# B
## BB
## CC
### <table><!--
--><tr><!--
-- --><td>dawda</td><td>dawd</td><!--
--></tr><!--
--><tr><!--
-- --><td>dawda</td><td>dawd</td><!--
--></tr><!--
--></table>
## EE
## FF
# G

Note that ‎<thead>‎, ‎<tbody> and ‎<tfoot> are not supported.

Tonyatonye answered 20/3, 2017 at 14:26 Comment(1)
This is one of the two solutions of mediawiki.org/wiki/Topic:Q9xbaa4rctdx3vn1Bremble
W
1

Colleague worked out the answer so I thought I'd share it here - simply a tweak to the common.css file

}
.list_numbered > ol:first-of-type, .list_numbered > ol ol {
    counter-reset: item;
}
Waylan answered 20/3, 2017 at 8:44 Comment(3)
This makes the numbers display correctly, but doesn't actually change the underlying HTML structure — you'll still have two ordered lists. (Not that that's a problem, if it works for you.)Planometer
Not pretty, but it did the job and is only on one page for an internal knowledge base :-)Waylan
This doesn't work any more for me, there's no numbering instance of name "item" in mediawiki css.Bremble
I
1

Building on Sam's (already fine) answer:

As mentioned on the MediaWiki Support desk, you can use HTML lists to make the table part of B2:

<ol>
  <li> A1
    <ol>
      <li> B1
      <li> B2
{| class=wikitable
 ! Header
 |-
 | Data
 |}
    </ol>
  <li> A2
</ol>

The indentation is not required, but adding leading spaces for alignment makes the structure easier to comprehend visually.

Alternatively, you can use an HTML table within the wikitext list. Note that MediaWiki doesn't currently recognize <thead> or <tbody>, so omit those.

# A1
## B1
## B2 <table class=wikitable><tr><th>Header</th></tr><tr><td>Data</td></tr></table>
# A2

As noted in wakalaka's answer, you can (ab)use HTML comments to spread the table over multiple lines, if you wish.

The complexity of your list versus the complexity of your table will probably dictate which method you choose. A benefit of the latter solution is you can hide the gnarly HTML in a template or subpage and transclude it into the list with the expected alignment, which is not possible with the former (see the screenshot below).

Results of each of the three methods of embedding a table within a list in MediaWiki

Iata answered 6/2 at 5:12 Comment(2)
You can indent the table too, no?Agathaagathe
@Agathaagathe Indeed, you can indent wikitext tables by any amount of whitespace, it appears. That I didn't is evidence of some superstition I have, since leading whitespace usually starts you into a block of preformatted text (ref). Almost seems like a bug, or behavior that could change later?Iata

© 2022 - 2024 — McMap. All rights reserved.