Thursday, June 16, 2005

TiddlyWiki hack: exporting tiddler HTML

I was trying to figure out how to export rendered HTML from a TiddlyWiki tiddler so I could paste it into an MS Word document. Since there doesn't seem to be a supported way to do this in TiddlyWiki, I found two methods that seem to work:

  • If you're using Firefox, just highlight the tiddler text, then right-click your selection and choose "View Selection Source." I dunno why this works, but it does.
  • Otherwise, I threw together the Ugliest TiddlyWiki Hack Ever!

I may be reinventing the wheel here, but whatever.

Save a backup of your TiddlyWiki file, then open it in a text editor and search for the createTiddlerToolbar function. In that function, look for the section that adds buttons to the non-editor toolbar and add the following lines to that block:

  "show/hide HTML of this tiddler",

Now add the following function somewhere in the page, preferably near where the other button handlers live:

function onClickToolbarShowHTML(e)
  if( {
    var viewer = 
      document.getElementById("viewer" +;
    if (!viewer.isHTMLView) {
      viewer.innerHTML = viewer.innerHTML.replace(/\</g,"&lt;");
      viewer.isHTMLView = true;
    } else {
      viewer.isHTMLView = false;

This is admittedly a gross hack: we're just grabbing the HTML of the viewer tiddler and replacing all the left angle brackets with HTML entities, then stuffing the HTML back into the tiddler. Since calling displayTiddler refreshes the tiddler content, we can use that to undo the damage without manipulating the string again.

This has been pretty useful to me, since I love the simple TiddlyWiki table markup for doing spec work, but usually have to cut and paste it into a report written in HTML or Word. Now, I just hit that "html" tiddler button, copy/paste the HTML, then toggle it back.


At 10:15 AM, Blogger Phil Ringnalda said...

Using view selection source works because it really should be named something odd like "view the sort of source which would produce the DOM that resulted in your selection." Makes it very handy for figuring out what a ton of script constructed, but also results in a never-ending stream of bug reports from people who think it should be the original source, even though something that you select could come from the combination of the HTML and ten different external script files.

At 7:32 AM, Blogger piepiping said...

Hello, I'm terribly sorry to comment off topic, but it seems that you could perhaps help me. I'm trying to understand how to set up a sort of archiving system, not that unlike blogger's, so that I can publish a webcomic. If you visit my blog, you will better understand my problem. It also contains a link to our webcomic.

If there's anything you know on the subject that could assist us and don't mind, please let us know. Any help would be appreciated.

At 8:11 AM, Blogger Helplessness said...

Good clues, thanks...

At 5:08 PM, Blogger MCAndre said...

The TiddlyWiki framework has changed significantly, so it's not as simply as copying and pasting this code in. Could you update the code and release it as a TiddlyWIki plugin?


Post a Comment

<< Home