Hi
In my wx application, I am getting plain text from wxTextCtrl and loading to wxSimpleHtmlListBox. The text can contain new line and any html entity like & >, < etc. I am handling it manually (i.e Replacing _T('<') with _T("<"), _T('\n') with _T("<br/>") and so on) when I find issue in displaying the text.
I want a way to do it automatically like we have wxURI which converts/encodes plain text to HTML URL. I tried loading URI but it comes as plain text.
"A\nB" displays as "A%0aB". It want it to be displayed in two line in the list.
Let me know if there is way where it automatically coverts/encodes to HTML string.
Please suggest.
Thanks
R.
[wxMSW[3.0.3] Convert plain text to html text
Re: [wxMSW[3.0.3] Convert plain text to html text
I do not think wxWidgets provide such function.
The closest thing it has is probably this private code doing that (for XML), that should be easy to adapt for your needs:
https://github.com/wxWidgets/wxWidgets/ ... .cpp#L1016
But perhaps it would be easier to find another and perhaps better C++ code for this...
The closest thing it has is probably this private code doing that (for XML), that should be easy to adapt for your needs:
https://github.com/wxWidgets/wxWidgets/ ... .cpp#L1016
But perhaps it would be easier to find another and perhaps better C++ code for this...
Re: [wxMSW[3.0.3] Convert plain text to html text
What kind of issues?when I find issue in displaying the text.
I don't think there is much more to do than you already did. I use a similar code:
Code: Select all
wxString ConvertTextToHTML( const wxString &in )
{
wxString out;
out.reserve( in.length() * 4 );
for( wxString::const_iterator p = in.begin(); p!=in.end(); p++ )
{
wxUniChar c = *p;
if( c >= 128 )
{
out.Append( wxString::Format("&#%d", c.GetValue()) );
}
else if( c == '<' )
out.Append( wxT("<") );
else if( c == '>' )
out.Append( wxT(">") );
else if( c == '&' )
out.Append( wxT("&") );
else
out.Append( c );
};
out.Shrink();
return out;
}
Use the source, Luke!
Re: [wxMSW[3.0.3] Convert plain text to html text
Thanks for the reply.
I don't see any problem with '>' and '&'. It gets displayed okay. I have to replace the '<'' with "<". Recently, I see problem with '\n', "A\nB" is displayed as "A B" in the list. I had to replace the '\n' with "<br/>". I find another one '\t'(Tab). "A\tB" is displayed as "A B".
I don't know which other chars can have issues, So, I wanted a way where it can be done automatically. As there is no such way, I need to know which other chars can create similar issue.
Thanks
R.
Initially, I was not handling '<', so it was not getting displayed in list if input string has it. e.g if input string is "a<c" then I was seeing only "a" in list.What kind of issues?
I don't see any problem with '>' and '&'. It gets displayed okay. I have to replace the '<'' with "<". Recently, I see problem with '\n', "A\nB" is displayed as "A B" in the list. I had to replace the '\n' with "<br/>". I find another one '\t'(Tab). "A\tB" is displayed as "A B".
I don't know which other chars can have issues, So, I wanted a way where it can be done automatically. As there is no such way, I need to know which other chars can create similar issue.
Thanks
R.
- T-Rex
- Moderator
- Posts: 1248
- Joined: Sat Oct 23, 2004 9:58 am
- Location: Zaporizhzhya, Ukraine
- Contact:
Re: [wxMSW[3.0.3] Convert plain text to html text
You probably could use libhtmlcxx and HTML::decode_entities function.