User:David Hedlund/MediaWiki table to TSV conversion

From Free Software Directory
< User:David HedlundThis is the approved revision of this page; it is not the most recent. View the most recent revision.
Jump to: navigation, search

Mastering the manual conversion between MediaWiki tables and tab-separated values (TSV) is essential for effective management of MediaWiki content. While scripts can automate this process, relying solely on them may lead to difficulties if you forget the script's name or don't have access to it. By understanding the fundamental structure of both formats, you can confidently handle MediaWiki tables even without automated tools.

For tables with entries on a single line

{| class="wikitable sortable"
|-
! Column 1 !! Column 2 !! Column 3
|-
| Hello || World || Bye
|-
| Foo || Bar || Baz
|-
|}

Convert MediaWiki table to (TSV)

  • Copy the table entries[1]
  • Replace "|-\n| " with nothing
  • Replace " || " with "\t" to make Libreoffice Calc display them in columns[3]
  • Open Libreoffic Calc
    • Create a new spreadsheet
    • Copy/paste the modified text to Libreoffice Calc. The data should now be separate into the A, B, and C column.
    • Modify the entries

Convert TSV to MediaWiki table

  • Copy the cells from Libreoffice Calc to a text editor
  • Add an initial blank line to the top
  • Replace "\n" with "\n|-\n| "
  • Replace "\t" with " || "

For tables with entries spanning multiple lines

{| class="wikitable sortable"
|-
! Column 1
! Column 2
! Column 3
|-
! Hello
| World
| Bye
|-
! Foo
| Bar
| Baz
|-
|}

Convert MediaWiki table to TSV

  • Copy the table entries[2]
  • To a text editor, copy paste the whole table except the table headers and "|}"
  • Replace "|-\n! " with nothing to only keep the data lines
  • Replace "\n| " with "\t" to make Libreoffice Calc display them in columns. Should now look like[3]
  • Open Libreoffic Calc
    • Create a new spreadsheet
    • Copy/paste the modified text to Libreoffice Calc. The data should now be separate into the A, B, and C column.
  • Modify the entries

Convert TSV to MediaWiki table

  • Copy the cells from Libreoffice Calc to a text editor
  • Add an initial blank line to the top
  • Replace "\n" with "\n|-\n! "
  • Replace "\t" with "\n| "

Refs

1.

|-
| Hello || World || Bye
|-
| Foo || Bar || Baz

2.

|-
! Hello
| World
| Bye
|-
! Foo
| Bar
| Baz


3.

Hello	World	Bye
Foo	Bar	Baz


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.