Commons:Convert tables and charts to wiki code or image files

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Road sign merging.svg
It has been suggested that this project page should be merged with MW:Manual:Importing external content. (Discuss)

English | Magyar | Svenska | +/−

Note. Commons: ('commons' followed by a colon) is a namespace for internal Commons work, and for resource pages on the Commons. See: {{resources}} and Category:Commons resources. One can search the Commons namespace via the advanced tab at Special:Search.

Here are some tools, resources, tips, and instructions for converting tables and charts to wiki code or image files. Most of the tools and resources are free.

Some starting points[edit]

HTML to wiki code[edit]

Convert HTML (from web pages) to wiki code.

Online tools[edit]

Conversion examples[edit]

List of countries by incarceration rate[edit]

See the long table at en:List of countries by incarceration rate. It has over 200 rows. View the HTML code for the reference table by clicking the source command found in one of the menus of your browser ("view page source" in the Firefox menu that pop ups when you right-click the page). The table HTML starts with <table and ends with </table>.

Copy only the table HTML, and paste it into the "HTML markup" form of the online HTML to Wiki Converter by Magnus Manske. It is here: uni-bonn.de converter. Remove the CSS styling at the top of the table wikitext. It is unnecessary. Click "convert" at the bottom of the converter page. It converts the table HTML to wiki code (wikitext).

The wikitext needs to be cleaned up further. To do so copy the new wikitext into a blank page of a good free text editor such as NoteTab Light. Save this as a text file. Fix any text laddering. Then use the text editor's find-and-replace tool to replace double spaces with single spaces. Repeat until no double spaces remain. Save the text file.

Add and edit the column headers as necessary. Test in one of your user sandboxes as necessary to get things working right. Add the sortable wikitable class to make the rank and country columns sortable. See meta:Help:Table and the top of the current table wikitext at en:List of countries by incarceration rate. The simplest way is to copy the top lines from there in case anything has changed in its styling.

Rank Country (or dependent territory) Prisoners per
100,000
population
{| class="sortable wikitable" border=1 cellspacing=0 
! Rank
! Country (or dependent territory)
! data-sort-type="number" |Prisoners per <br>100,000 <br>population
|-

Note: "c." (circa) indicates "approximately." It should be put after the number, or numerical sorting of the rate column will not work, even with data-sort-type="number" in the column header. It is no longer necessary to put "c" in a separate column though. It is now possible to force the numerical sort order of a column by adding data-sort-type="number" to the column header. See: en:Help:Sorting. After moving "c" save again. Keep a separate copy of this. It may be needed for the country linking option explained in the shaded box farther down.

Next, click the replace command from the search menu of NoteTab. It pulls up the find-and-replace form. It can be used to quickly find and remove any remaining HTML. To add country linking and flag icons go directly to the shaded box farther down, and skip this section.

First replace </a> with nothing.

Then remove the rest of the HTML used for the country links. Put a checkmark in the regular expression checkbox, and then remove everything between HTML tag brackets: <>

To do that paste this regular expression in the "find what" line:

\<.*?>

In the "replace with" line put this:

style="text-align:left" |

Click "replace all." This instantly removes nearly all HTML code. It replaces it with styling that aligns the country names to the left. The names are easier to read that way.

Alternatively, you can add country linking and flag icons. To do so replace </a> with template end brackets: }}

Then replace the remaining HTML using the regular expression method. Put a checkmark in the regular expression checkbox, and then remove and replace everything between HTML tag brackets <>

To do so replace
\<.*?>
with this:
style="text-align:left" |{{flagcountry|

Those 2 changes should make all the country names into wikilinks, and add a flag icon in front of them. For example; see en:User:Timeshifter/Sandbox38. In some country lists created this way some of the country links may have to be created manually. This is because there is a need to create redirects to the country names used for these links. Fortunately, all the redirects except one have already been created for this country list. For the combined UK number for England and Wales add this line manually to keep both flags:

style="text-align:left" |{{flagicon|England}} & {{flagicon|Wales}} [[England and Wales]]

For more info see: en:Wikipedia:WikiProject Flag Template, en:Category:Country data templates and en:Category:Country data redirects. Country links and flag icons are not absolutely necessary in country lists. Timely updating of the list is more important. If you want flags and country links, and you want to be able to rapidly update a list you may need to create some redirects. To do so search here for the templates to redirect to. Add the country or territory name to the search.

Do some additional manual cleaning, if necessary, to get rid of the rest of the HTML. There shouldn't be a need to do so for en:List of countries by incarceration rate.

A column for notes (if necessary) is instantly added by doing a regular find-and-replace. Replace

|-
with
|^p|-
  • ^p is the NoteTab code for line breaks.
  • |- is the wikitext for a table row.
  • | is the wikitext for a table cell. See meta:Help:Table.

For consistency use the same reference table for all the countries and territories possible. If rates for additional countries or territories are found they can be entered in the table, and their references can be put directly after the rate numbers. This will no longer break numerical sorting of the rates column. A note above the table can specify that all the data comes from one source unless indicated otherwise by separate references in the table. There is no need to repeat the main reference over two hundred times in the table.

PDF to image files[edit]

See: Commons:PDF to image files

PDF to HTML, wikitext[edit]

Convert PDF charts and graphs to wikitext, or to HTML.

Some PDF charts can be converted to HTML charts. Copying and pasting some PDF charts produces comma-separated values (CSV) when pasted into some freeware text editors such as Notetab Light. See the next section for tools to convert CSV data into HTML charts and wikitext charts.

Sometimes you can paste a PDF chart into a Kompozer page. After doing so, select the chart text on the Kompozer page. Then click "create table from selection" in the table menu. Choose between commas or spaces (depending on what was used) to separate the columns. Save the page as an HTML web page. Then use one of the HTML to wiki converters to convert the HTML chart to wikitext.

PDF tools[edit]

Some of the previous sections refer to PDF files. Wikipedia has a comprehensive list of PDF software. Much of it is free and open source.

CNET has a category: PDF Software Downloads for Windows. Much of it is free, or free to try. Click "free" link in the left sidebar for freeware. Initial sort is by downloads last week. Recent popularity is usually a good comparative guide to ease of use.

Appropedia has notes on porting PDF files to MediaWiki.

For tables and charts, converting PDF to SVG is usually the optimal choice if you have the skills and tools to do so. Two programs that can do this are:

Convert wiki tables to Excel[edit]

Maybe you need to work on some tables, and prefer to work in Excel. See:

Convert CSV, DSV, or Excel to HTML or wikitext[edit]

Convert Excel, comma-separated values (CSV), tab-separated values, delimiter-separated values (DSV), etc. to table wiki code.

Online tools[edit]

More info in English: de:Benutzer:Duesentrieb/csv2wp_(en)

Microsoft Word to wiki code[edit]

Microsoft Word converters. See:

OpenOffice.org to wiki code[edit]

OpenOffice can export to wiki code. Install first the Sun Wiki Publisher extension. Next make your table and choose to Export to MediaWiki (.txt).

Print screen, and then edit chart image[edit]

The charts can be converted to images by using the "Print Screen" key on a keyboard. Image editors can then be used to capture and crop the chart found on the screenshot.

There are many free image editors. See:

For example; there is the free, popular, easy-to-use Irfanview. Use it to resize charts, remove watermarks, crop unused space from around the edges, and so on. Irfanview can also losslessly compress PNG images so as to use less kilobytes for the same image without any loss in image quality. Install the Irfanview plugin pack too. It installs instantly and includes even better PNG compression, PNGOUT, which is easy to use in Irfanview.

See also[edit]