TW Macros to Convert Web Tables to TiddlyWiki

Personal Online Demo

Sometimes, all I want is to have the same table from the web in markup on my TiddlyWiki.

A method that is better than manual markup to duplicate web tables.

It involves first pasting the table to LibreOffice Calc, and then saving it to the csv format before importing it and converting it in TiddlyWiki.

If you import the .json, then use this link to access the instructions: [[Converter Demo|$:/wiki-user/experiments/csv2tw/Web 2 LibreOffice 2 CSV 2 TiddlyWiki]]

tableconvertdemo.json (143.0 KB)

These tiddlers are all prefixed with $:/wiki-user/experiments/csv2tw

A first stage will convert the table to TiddlyWiki Markup, and a second stage will convert it to tiddler cells, which have open-ended uses thus far.

3 Likes

Thanks for sharing.

It’s not exactly a solution or a competitor to your code, but recently I’ve been using a separate chat in CoPilot to generate WikiText from my pasted content. CoPilot has become really effective at creating wikitext markup with just a little guidance.

1 Like

Here’s a tip for windows: if you have powertoys installed, you can copy the table, then paste with windows+shift+v (advanced paste) and then select markdown:

From there, either use the markdown plugin, or edit the table a bit to make it wikitext compatible

You can also paste as json then use a macro to parse json instead of csv:

\procedure jsontotable(json)
<table>
<$list filter="[<json>jsonindexes[]]" variable="rowIndex">
  <tr>
    <$list filter="[<json>jsonget<rowIndex>]" variable="cellValue">
      <%if [<rowIndex>match[0]]%>
        <th><<cellValue>></th>
      <%else%>
        <td><<cellValue>></td>
      <%endif%>
    </$list>
  </tr>
</$list>
</table>
\end

<<jsontotable """[
  [
    "Company ",
    "Contact ",
    "Country"
  ],
  [
    "Alfreds Futterkiste ",
    "Maria Anders ",
    "Germany"
  ],
  [
    "Centro comercial Moctezuma ",
    "Francisco Chang ",
    "Mexico"
  ],
  [
    "Ernst Handel ",
    "Roland Mendel ",
    "Austria"
  ],
  [
    "Island Trading ",
    "Helen Bennett ",
    "UK"
  ],
  [
    "Laughing Bacchus Winecellars ",
    "Yoshi Tannamuri ",
    "Canada"
  ],
  [
    "Magazzini Alimentari Riuniti ",
    "Giovanni Rovelli ",
    "Italy"
  ]
]""">>
2 Likes

I have done this using a simple text editor, BBEdit for OSX in my case.

Copy the web table from the browser window and paste into new BBEdit document
Some simple editing instructions replaces all

  • end of line with | end of line |
  • tab with |

Multiline cells have to manually amended to make sure they remain as multiline cells, by replacing | with <br>

Works a treat for me but then my tables are usually quite simple.

bobj

Yeah, I would like to “sweeten the deal” on this thing to make it increasingly worthwhile compared to manually doing it.

I think that (primarily) means trying to translate cell merges from web tables - at first those limited to single columns. Spreadsheet applications understand all merges from copy/pasting, and it would be an advantage over a text editor.

I have an idea for a limited way of doing merges between merged cells in single vertical columns. However for horizontal merges I fear it might mean saving the table to html instead of csv. Such a leap of a solution might not be worth it to me at this time.

You might find the CodeMirror plugin helpful, as it includes a find-replace feature within the tiddler editor box. (I’m not sure it can handle “end of line” however. That’s cool.)