I’d like to display a string that containts html code (mainly for formating purposes like italic, bold, indentation, colors etc.) from a C# console application.
I don’t think I’ll need to go with a WebBrowser class for that, since there won’t be any kind of navigation possible.
1) What would be the most straightforward way to do it?
2) Would it be possible to display it too in the console using the hmtl formating?
thanks
Using an existing HTML rendering engine would be very expensive from a performance perspective – especially memory.
The other issue you face is that most HTML formatting will not translate to the console – the only effects you really have available is foreground and background color.
Your best bet is to write a simple parser your self. You will need to decide how to interpret things like bold and italic using console colors.
Since you only need to handle two possibly three HTML tags the parsing should be very simple, the logic to ignore other HTML tags should be pretty straight forward.
Note, HTML is not a regular language so you cannot effectively use regular expressions for parsing. I would recommend a simple recursive decent parser – these are straight forward to implement. You could also write a state machine, but it would need to have some recursive or stack semantics to be corret.