#!/usr/local/bin/perl5.005 # Quick-n-dirty, HIGHLY LIMITED, RTF -> HTML converter # jason@jclark.org # # Only supports bold (as ), italic (as ), underline, # and paragraphs. Corrects improperly nested tags, handles rtf's # \plain. Ignores any RTF aside from the list above. Emits valid # xhtml fragments (i.e., wrap in a ). Quite certainly # contains bugs. Use as use wish, at your own risk. foreach my $file (@ARGV) { open(IN, "< $file"); local $/; #slurp mode my $rtfdoc = ; close IN; print rtf2html($rtfdoc); print "\n\n"; } sub rtf2html { # note: use of '#' as regexp delim just a workaround # for an xemacs syntax highlight bug. ($_) = @_; s![\n\r]!!g; s#^\s*{##; #clobber header s#{[^}]*?}##g; s#}\s*$##; #... and footer s!\\uc\w+!!g; s!\\pard!!g; s!\\ulnone!!g; s!\\b0!!g; #convert closing tags s!\\i0!!g; s!\\u0!!g; s!\\plain!!g; s!\\b!!g; #convert opening tags s!\\i!!g; s!\\ul!