Suggestions for displaying code on webpages, MUST use <br> for newline

Posted by bguiz on Stack Overflow See other posts from Stack Overflow or by bguiz
Published on 2010-03-26T23:54:51Z Indexed on 2010/03/27 0:13 UTC
Read the original article Hit count: 635

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"]&nbsp;!= 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"]&nbsp;!= 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

© Stack Overflow or respective owner

Related posts about source-code

Related posts about html