Converting TiddlyWiki to TWiki
Finally, I've imported my old TiddlyWiki page into this TWiki installation. The process involved two steps:
- Converting topic names to camel notation (mainly for file names)
- Converting datetime and syntax
Luckily I only used very basic Tiddly syntax elements, so the conversion was easy.
Title conversion (tiddly2twiki.sh)
#!/bin/sh
IFS='
'
:>tiddly2twiki.titlemap
grep '^<div tiddler=' tiddly.html|while read a;do
_title="${a#*tiddler=\"}"
title="${_title%%\" modifier=*}"
{
echo "$title"|perl -ne 's/(^"|"$)//g;\
s/(?:^| )([a-z])/\u\1/g;\
s/[^a-zA-Z0-9_]//g;\
print;';
echo ":$title";
}>>tiddly2twiki.titlemap
done
You can then edit the titlemap manually to your liking.
Syntax conversion (tiddly2twiki.pl)
#!/usr/local/bin/perl
use POSIX qw(strftime);
use POSIX::strptime;
system "rm -rf tiddly2twiki.files/";
mkdir "tiddly2twiki.files";
chdir "tiddly2twiki.files" || die "Could not chdir";
open TIDDLY, '<', '../tiddly.html';
while(<TIDDLY>){
next unless m#^<div tiddler="(.*?)".*modified="(\d+)".*?>(.*)</div>#;
my $title=$1;
my $tiddate=$2;
my $tiddler=$3;
my $twikidate=strftime('%s',POSIX::strptime($tiddate,'%Y%m%d%H%M'));
my $filetitle=`grep -m1 "[^:]*:$title\$" ../tiddly2twiki.titlemap`;
chomp($filetitle);
$filetitle=~s/:.*//;
$filetitle.=".txt";
print "$filetitle\n";
open OUT, '>', $filetitle;
print OUT '%META:TOPICINFO{author="AndrewPantyukhin" ';
print OUT 'date="'.$twikidate.'" ';
print OUT 'format="1.1" version="1.1"}%'."\n";
print OUT "---+$title\n";
$tiddler=~s#\\n#\n#g;
$tiddler=~s#\[\[(.*?)\|(.*?)\]\]#[[\2][\1]]#g;
$tiddler=~s#^!!!#---++++#mg;
$tiddler=~s#^!!#---+++#mg;
$tiddler=~s#^!#---++#mg;
$tiddler=~s#^\*\* # * #mg;
$tiddler=~s#^[*-] # * #mg;
$tiddler=~s/^# / 1. /mg;
$tiddler=~s#\{\{\{#<verbatim>#g;
$tiddler=~s#\}\}\}#</verbatim>#g;
$tiddler=~s#\|\|#|.|#g;
$tiddler=~s#(?<=\|)\>(?=\|)##g;
$tiddler=~s#(?<=\|)!([^|]+)(?=\|)#*$1*#g;
print OUT $tiddler."\n";
}
It's far from perfect and only supports a trivial subset of Tiddly syntax.