『楼 主』:
关于txt转htm的问题,欢迎大家讨论
使用 LLM 解释/回答一下
本人平时喜欢收集一些文本文档的资料,本想做一个txt转htm的批处理,将收集的大量东西转为htm,再编译成CHM的电子书,没想到刚着手,却先被txt转htm的问题难住了,本要在批处理专栏发帖的,想想这又不是DOS的问题,所以就在这发了,望版主不要说我发错地方了..
一种方法是一些电子书制作软件本身支持对txt的编译,它保持了文本的原样,但有一个致命的弱点就是不能支持全文搜索.这对于较大的CHM来说是相当不好的.弱点二是对于单行较长的,在浏览时不能自动换行,要通过横向滚动条拖动才能看完.
网上也很少有这种小软件,华军有一个也不过是通过在<pre></pre>间插入文本的方法,这种方法转成的htm可以保持txt的原始风格,且编译成CHM后可以支持全文搜索,但也是对于单行较长的,在浏览时不能自动换行.感觉很不便.
我到是用了一个笨点的方法,就是先用 替换文本内所有的空格,然后将文本每行行首加上<br>再将整个文本放入<p></P>之间,最后加上开始和结尾的代码,将扩展名改为htm就可以了.这先将文本转成htm再编译成chm,保持了文本的原有风格,而对于较长的行也能自动换行,并且也支持全文搜索,可有一点不足,就是转换后的htm文件比原来的txt文件大了近两倍(这是由于空格的替换造成的,但这是为了保持文本原有风格的代价),这对于大量的文本来说也是不太理想的,由于我网页方面知识有限,希望能有更精通的人来说一说文本转htm的最佳方法.
最好方法简单,易于实现,并且克服上述的缺点.
Last edited by zzhh612 on 2007-4-6 at 11:50 AM ]
I usually like to collect some text document materials. I originally wanted to make a batch processing for converting txt to htm, to convert a large amount of collected things into htm, and then compile them into CHM e-books. Unexpectedly, I was first stumped by the problem of converting txt to htm just when I started. I was going to post in the batch processing column, but thought this is not a DOS problem, so I posted here. I hope the moderator won't say I posted in the wrong place..
One method is that some e-book making software itself supports compiling txt, which maintains the original appearance of the text, but there is a fatal weakness that it cannot support full-text search. This is quite bad for larger CHM. Weakness two is that for lines that are longer in a single line, when browsing, it cannot wrap automatically, and you have to drag the horizontal scroll bar to finish reading.
There are also very few such small software on the Internet. There is one on Huajun, which is just a method of inserting text between <pre></pre>. The htm converted by this method can maintain the original style of txt, and after compiling into CHM, it can support full-text search, but it is also for lines that are longer in a single line, and when browsing, it cannot wrap automatically. It feels very inconvenient.
I actually used a clumsy method, that is, first replace all spaces in the text with , then add <br> at the beginning of each line, then put the entire text between <p></P>, and finally add the start and end codes, change the extension to htm. This first converts the text to htm and then compiles it into chm, which maintains the original style of the text, and can also wrap automatically for longer lines, and also supports full-text search. But there is one shortcoming, that is, the converted htm file is nearly twice as large as the original txt file (this is caused by the replacement of spaces, but this is the price to maintain the original style of the text). This is also not ideal for a large amount of text. Since I have limited knowledge in web pages, I hope that those who are more proficient can talk about the best method for converting text to htm.
The best method is simple, easy to implement, and overcomes the above shortcomings.
Last edited by zzhh612 on 2007-4-6 at 11:50 AM ]
|