Suggestions for displaying code on webpages, MUST use <br> for newline
- by bguiz
Hi,
I want to post code snippets online (wordpress.com blog) - and have its whitespace formatted nicely.
See the answers suggested by this other SO question:
Those would be OK, except that I like to copy code to clip board or clip entire pages using Evernote - and they use either the <pre> tag or <table> (or both) to format the code. So I end up with text whose newlines and white spaces ignored, e.g.
string url = "<a href=\"" + someObj.getUrl() + "\" target=\"_blank\">"; // single line comments // second single line override protected void OnLoad(EventArgs e) { if(Attributes["class"] != null) { //_year.CssClass = _month.CssClass = _day.CssClass = Attributes["class"]; } base.OnLoad(e); }
Which I find rather annoying myself. I find that if the code was formatted using <br> tags, they copy/ clip porperly, e.g.
string url = "<a href=\"" + someObj.getUrl() + "\" target=\"_blank\">";
// single line comments
// second single line
override protected void OnLoad(EventArgs e)
{
if(Attributes["class"] != null)
{
//_year.CssClass = _month.CssClass = _day.CssClass = Attributes["class"];
}
base.OnLoad(e);
}
I find this annoying myself, so I don't want to inflict it upon others when I post my own code. Please suggest methods of posting code snippets online that are able to do this.
I would like to emphasise that syntax highlighting capability is secondary to correct white space markup.
Thank you