Since I’m using the WP-Syntax plug-in on my blog I tried to optimize font size and the tab width. Like a lot of developers I heavily use tabs in my source code. These tabs are really wide within the browser so I was looking for a way to minimize the used space.
I’m not a CSS guy but it seems like there is no way to set a specific tab width. So why not replace the tab with white space?
My change to wp-syntax/wp-syntax.php:
function wp_syntax_highlight($match) { global $wp_syntax_matches; $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $escaped = trim($match[3]); $code = wp_syntax_code_trim($match[4]); // INSERT JUST THIS LINE OF CODE $code = str_replace ( '\t' , ' ' , $code ); . . .
Thank you so much for this! Was driving me mad!
But after coping your code it just did not work (I have maybe a newer version) so I changed your line to this:
$code = str_replace ( "\t", ' ' , $code );
And it works like a charm.
Always glad to help. 🙂 Thanks for the hint – I updated the code snippet.
I had the same problem derRaab! Replace \t by fixed spaces is not really correct, tab char represent variables space char. I wrote a quickly solution making this two changes in wp-syntax/wp-syntax.php:
Change 1:
Change 2, insert a new funtion for my pre-blocks:
This last function is a copy-paste-modify of ident().
If I didn’t make a mistake this corrected tab’s size (in my case 8 to 4).
Thanks in advance Juampa. I’ll give it a try after the next wordpress update…