WordPress <code> does not keep code indent’s – use <pre>

Yup. Silly as it may sound the <code> tags in WordPress are pretty much useless when you want to paste a code snippet and not have it look like a poem written by crazy robot… 🙂 Use the <pre> .. </pre> tags instead.

Here’s an example.

Code formatted with ‘<code>’:

while( 1 )
{
tmeasure_t0( NULL );

int res = select( fdout + 1, NULL, &fdset_wr, &fdset_ex, &timeout_select );

if( res < 0 && errno != EINTR ) { perror( "select -1" ); } else if( 0 == res ) { if( retries ) { --retries; sleep( 1 ); continue; } else { perror( "select 0" ); break; } } ... }

Code formatted with '<pre>':

    while( 1 )
    {
        tmeasure_t0( NULL );

        int res = select( fdout + 1, NULL, &fdset_wr, &fdset_ex, &timeout_select );

        if( res < 0 && errno != EINTR )
        {
            perror( "select -1" );
        }
        else if( 0 == res )
        {
            if( retries )
            {
                --retries;
                sleep( 1 );
                continue;
            }
            else
            {
                perror( "select 0" );
                break;
            }
        }
        ...
    }

Leave a Reply

Your email address will not be published. Required fields are marked *