Real Software Forums http://forums.realsoftware.com/ |
|
RTF to HTML: Two Questions http://forums.realsoftware.com/viewtopic.php?f=6&t=39729 |
Page 1 of 1 |
Author: | barrytraver [ Thu Jul 07, 2011 3:38 am ] |
Post subject: | RTF to HTML: Two Questions |
I wrote the following Windows program to convert simple RTF to HTML: Dim Result As Boolean It's not pretty, but it seems to work. Question #1: Should I be using "span" or "div" or something more complicated than either? (Both "span" and "div" appear to work, but that doesn't necessarily mean that either works all the time.) Question #2: Do you notice any (other?) non-obvious errors in the code (or at least non-obvious to me)? Thanks in advance for any advice. Barry Traver P.S. I'm posting this in the Windows area because I have an idea that the lines containing "13" may not work on the Mac and/or with Linux. |
Author: | timhare [ Thu Jul 07, 2011 3:54 am ] |
Post subject: | Re: RTF to HTML: Two Questions |
You should use <span> instead of <div>. <div> is a block oriented tag, and is a superset of <p>. <span> is in-line, within a <p> and a <div>. TextArea uses chr(13) on all platforms, regardless of each platform's EndOfLine. |
Author: | barrytraver [ Thu Jul 07, 2011 4:24 am ] |
Post subject: | Re: RTF to HTML: Two Questions |
timhare wrote: You should use <span> instead of <div>. <div> is a block oriented tag, and is a superset of <p>. <span> is in-line, within a <p> and a <div>. Thanks for the comment. timhare wrote: TextArea uses chr(13) on all platforms, regardless of each platform's EndOfLine. Thanks again. If I understand what you're saying, then Windows seems not to be the only platform where the platfom's normal EndOfLine is different from the platform's EndOfline for a TextArea. Interesting! Another question.... Assume the following code: Dim S1 As String Do I remember correctly that for Windows end-of-line is one-character in TextArea1 -- i.e., Chr ( 13 ) -- but is now automatically converted to a normal Windows end-of-line of two characters -- i.e., Chr ( 13 ) + Chr ( 10 ) -- in S1 in the preceding code snippet? Barry Traver |
Author: | timhare [ Thu Jul 07, 2011 11:31 am ] |
Post subject: | Re: RTF to HTML: Two Questions |
No, the end of line character remains a single chr(13). There is no automatic conversion for that simple assignment. You would have to code it as s1 = ReplaceLineEndings(Textarea1.Text, EndOfLine) Tim |
Author: | barrytraver [ Fri Jul 08, 2011 2:31 pm ] |
Post subject: | Re: RTF to HTML: Two Questions |
Tim, You're absolutely correct. I had it backwards. Let's see if I can get it right this time. What does take place is not that S1 automatically adds Chr (10) but that TextArea1.Text automatically loses Chr (10). (I'm talking about Windows, of course.) Example #1: S1 = Chr ( 65 ) + Chr ( 13 ) + Chr ( 10 ) Example #2: TextArea1.Text = Chr ( 65 ) + Chr ( 13 ) + Chr ( 10 ) Also, ReplaceLineEndings can be a bit tricky at times. No surprises with this: S1 = Chr ( 65 ) + Chr ( 13 ) But try this: TextArea1 = Chr ( 65 ) + Chr ( 13 ) Barry Traver P.D. I think I've got it right this time, but please let me know if I didn't. |
Author: | timhare [ Fri Jul 08, 2011 2:50 pm ] |
Post subject: | Re: RTF to HTML: Two Questions |
What's surprising about that example? And the "tricky" part is not ReplaceLineEndings, but assigning a string to TextArea1.Text. ReplaceLineEndings returns a string with a trailing chr(10). TextArea1 dutifully removes it. |
Author: | barrytraver [ Fri Jul 08, 2011 8:51 pm ] |
Post subject: | Re: RTF to HTML: Two Questions |
timhare wrote: What's surprising about that example? And the "tricky" part is not ReplaceLineEndings, but assigning a string to TextArea1.Text. ReplaceLineEndings returns a string with a trailing chr(10). TextArea1 dutifully removes it. What's surprising to me as a non-professional is that TextArea1.Text is _exactly_ the same both before and after the following line: TextArea1.Text = ReplaceLineEndings(TextArea1.Text, EndOfLine.Windows) That is, one might expect from the code that a one-character line ending is being replaced by a two-character line ending throughout the text. Instead, TextArea1.Text ends up unchanged. (EndOfLine.Windows is two characters long, not the one-character line ending it started out with.) Question: does that line of code even make sense? Is it even valid? After all, Chr ( 13 ) is supposedly being replaced by Chr ( 13 ) + Chr ( 10 ), and that doesn't seem to happen, right? Barry Traver |
Author: | timhare [ Sat Jul 09, 2011 2:24 am ] |
Post subject: | Re: RTF to HTML: Two Questions |
Yes, it does happen. ReplaceLineEndings puts in a 2-character end of line. TextArea1 immediately takes it right back out. As you noted previously, when you assign a string to TextArea.Text, it replaces the normal line endings with chr(13), but when you take the string back out, the line endings remain a single chr(13). Try to imagine the intermediate results: dim s as string TextArea1.Text = chr(65) + chr(13) s = ReplaceLineEndings(TextArea1.Text, EndOfLine.Windows) msgbox str(len(s)) TextArea1.Text = s msgbox str(len(TextArea1.Text)) The first msgbox will be "3", the second will be "2". |
Page 1 of 1 | All times are UTC - 5 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |