2004年12月17日星期五

html2rtf.pl的超级链接支持

终于忍受不了html2rtf.pl,改了一下,添加了对URL的支持,在Word/Word和AbiWord都可以正确显示成超级链接(hyperlink),但wordpad似乎有自己的显示方式: 显示成了: text ,保存后超级链接会丢失

line: 257 处添加如下代码:

# now href
urlobj_data1 = "{field{*fldinst {fs24insrsid13071880 hichaf1dbchaf13lochf1 hichaf1dbchaf13lochf1n HYPERLINK";
urlobj_data2 = "hichaf1dbchaf13lochf1 }{fs24insrsid13071880charrsid13071880 {*datafield 00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b5a0000";
# urlobj_data3 is the URL(unicode) in hex code. e.g. http://www.zope.org/Members/Brian/PythonNet/
urlobj_data3 = "0068007400740070003a002f002f007700770077002e007a006f00700065002e006f00720067002f004d0065006d0062006500720073002f0042007200690061006e002f0050007900740068006f006e004e00650074002f";
urlobj_data4 = "000000}}}{fldrslt {cs15fs24ulcf2insrsid13071880charrsid13071880 hichaf1dbchaf13lochf1 ";
instream =~ s/]*>/urlobj_data1 "1" urlobj_data2&url_str2hex(1)urlobj_data4/ig;
instream =~ s//}}}/ig

其中url_str2hex的实现如下,随便放在什么地方

# input: http://
# output: 0068007400740070003a002f002f
sub url_str2hex {
local(s);
s = _[0];

out = "";
i=0;
while(i
ch = substr(s, i, 1);
#printf "%04xn", ord(ch);
out = out.sprintf("%04x", ord(ch));
i ++;
}
printf out;
return out;
}


html2rtf.pl的网址: http://fresh.t-systems-sfr.com/unix/src/www/.warix/html2rtf.pl.html

没有评论: