CSV to Wikitable Converter
A CSV to MediaWiki converter turns a spreadsheet into wikitable markup for Wikipedia or any MediaWiki install. This one gives you the sortable and collapsible classes, a proper caption line, and escapes the two characters that would otherwise split your rows using HTML entities, because MediaWiki has no backslash escape to reach for. Nothing is uploaded.
Need to trim, sort or rename columns first? Open the app
There is no backslash escape
MediaWiki's table syntax is line-oriented and the delimiters live at the start of a line. A | begins a cell, a ! begins a header cell, |- starts a new row, and |} closes the table. Two pipes together, ||, separate cells written on the same line.
So a cell whose value contains a pipe splits the row. The instinct is to escape it with a backslash, and that does nothing: MediaWiki has no backslash escape at all. A \| renders as a backslash followed by a broken table.
The only reliable answer is the HTML entity. | renders as a pipe and is never parsed as markup, and ! does the same for an exclamation mark, which matters because a leading ! would turn a data cell into a header cell. Both substitutions happen automatically here.
This is one of those details that only shows up once your table is already on a live page and somebody notices a row with the wrong number of columns.
A worked example
Three rows, one containing a pipe:
city,country,population,note
Tokyo,Japan,37194000,largest
Delhi,India,32941000,"growing | fast"
Cairo,Egypt,21750000,
As a sortable wikitable with a caption:
{| class="wikitable sortable"
|+ World cities by population
|-
! city
! country
! population
! note
|-
| Tokyo
| Japan
| 37194000
| largest
|-
| Delhi
| India
| 32941000
| growing | fast
|-
| Cairo
| Egypt
| 21750000
|
|}
The pipe in Delhi's note is an entity, so the row still has four cells. The empty note on the Cairo row is a bare |, which is a legitimately empty cell rather than a missing one, so the table stays rectangular.
Sorting works properly on the population column because every value in it is numeric. That is not luck: types are decided once per column by reading the whole column, so a column with one stray n/a in it stays text and sorts alphabetically. An alphabetical sort you can see is better than a numeric sort that quietly puts 9 after 37194000.
Classes, captions and templates
wikitable is the class that gives you the standard borders and shaded header. Without it you get an unstyled table that looks out of place on any wiki. sortable adds the click-to-sort arrows. collapsible mw-collapsed renders the table folded with a show link, which is how a 200-row reference table lives on a busy page without dominating it.
The |+ line is the caption. It renders above the table and is the table's accessible name, which a heading in a separate line above it is not. If you want a title on your table, this is where it goes.
Numeric right-alignment is available but off by default, because MediaWiki has no per-column alignment: it has to be an inline style attribute on every cell, which triples the size of the markup and makes the source harder for other editors to work with. It is there when the table is a reference table of figures and worth the noise.
Template calls and wiki links in your data are left alone. A cell containing {{flag|Japan}} or [[Tokyo]] will be expanded by the wiki, and on Wikipedia that is very often the point: flag icons, unit conversions and article links are all done that way. You are told when such cells are present so it is a decision rather than a surprise, and <nowiki> is the way to show them literally.
Cells are written one per line by default. On a collaboratively edited page that is worth more than compactness: a one-cell change produces a one-line diff, rather than rewriting a long row that other editors have to read character by character to review.
Questions
Why are pipes written as | rather than escaped with a backslash?
Because MediaWiki has no backslash escape. A backslash before a pipe is just a backslash followed by a pipe, and the pipe still ends the cell. The HTML entity is the only thing that reliably renders as a pipe character without being parsed as markup. The exclamation mark gets the same treatment, since a leading one starts a header cell.
What does the sortable class do?
It adds click-to-sort arrows to each column header. It behaves well only when a column's values are consistently one type, which is exactly what the per-column type detection here guarantees: a column mixing numbers and text stays text and sorts alphabetically, which is the honest result rather than a wrong numeric one. Combine it with wikitable, which is what almost everyone wants.
Will a template call in my data be expanded?
Yes, and that is left alone deliberately. A cell containing double braces or double brackets is a template call or a wiki link, and a table of templates is a real and common thing on Wikipedia. Escaping it would break the intended use. You are warned when such cells are present so it is not a surprise; to show the characters literally, wrap the value in nowiki tags.
What is the caption line for?
A line beginning with a pipe and a plus sign is the table caption. It renders above the table, centred and bold in most skins, and it is the table's accessible name, so a screen reader listing the page's tables can identify yours. It is a better place for a title than a heading above the table, which is not associated with it.
How do I make a long table collapsible?
Turn on the collapsible option and the table gets the collapsible and mw-collapsed classes, so it renders folded with a show link. That is the standard way to keep a 200-row reference table on a busy page without it dominating everything. It needs the wiki's collapsible-content JavaScript, which Wikipedia and most installs have enabled.
Why is each cell on its own line by default?
Because it makes wiki diffs readable: changing one cell touches one line, rather than rewriting a long row that other editors then have to read character by character. On a collaboratively edited page that matters more than compactness. There is a compact option that puts a row on one line using the double-pipe separator if you prefer.
Is anything uploaded?
No. The conversion runs in your browser tab with nothing sent to a server, nothing kept between visits and no row cap. Copy the markup and paste it straight into the wiki editor.
Related
Convert your CSV to a wikitable
No sign-up, no upload, no row cap. Sortable and collapsible classes, a proper caption, pipes safely escaped.
Back to the converter