I wrote the following Windows program to convert simple RTF to HTML:
Dim Result As Boolean
Dim HTMLType As New FileType
Dim RTFType As New FileType
Dim File1 As FolderItem
Dim Count, I As Integer
Dim AllPiecesOfPage, PieceOfPage As String
Dim Piece, Temp, WholeWebPage As String
Dim SR as StyleRun
RTFType.Name = "RTF Files"
RTFType.Extensions = "rtf"
File1 = GetOpenFolderItem ( RTFType )
If File1 <> Nil Then
Result = TextArea1.Open ( File1 )
End If
Count = TextArea1.StyledText.StyleRunCount
AllPiecesOfPage = ""
For I = 0 to Count - 1
SR = TextArea1.StyledText.StyleRun( I )
PieceOfPage = SR.Text
If SR.Bold = True Then
PieceOfPage = "<b>" + PieceOfPage + "</b>"
End If
If SR.Italic = True Then
PieceOfPage = "<i>" + PieceOfPage + "</i>"
End If
If SR.Underline = True Then
PieceOfPage = "<u>" + PieceOfPage + "</u>"
End If
PieceOfPage = ReplaceAll (PieceOfPage, Chr ( 13 ) + Chr ( 13 ), "<p>" )
PieceOfPage = ReplaceAll (PieceOfPage, Chr ( 13 ), "<br />" )
Piece = "<span style=" + Chr ( 34 ) + "font-family: " + SR.Font _
+ "; font-size: " + Str ( Floor ( .5 * SR.Size ) ) + "pt; color: " + Mid ( Str ( SR.textcolor ), 3 ) _
+ ";" + Chr ( 34 ) + ">" + PieceOfPage + "</span>"
AllPiecesOfPage = AllPiecesOfPage + Piece
Next I
WholeWebPage = "<html>" + EndOfLine + "<body style=""font-size: 30pt;>"
WholeWebPage = WholeWebPage + AllPiecesOfPage + EndOfLine
WholeWebPage = WholeWebPage + "</body>" + EndOfLine + "</html>" + EndOfLine
TextArea1.Text = WholeWebPage
TextArea1.SelStart = 0
TextArea1.SelLength = Len ( TextArea1.Text )
TextArea1.SelTextSize = 30
TextArea1.SelLength = 0
HTMLType.Name = "HTML files"
HTMLType.Extensions = ".html; .htm"
File1 = GetSaveFolderItem(HTMLType, "")
If File1 <> Nil Then
Result = TextArea1.Save ( File1, False )
End If
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.