<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gergely Hodicska &#187; wordpress</title>
	<atom:link href="http://blog.felho.hu/stock/php/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.felho.hu</link>
	<description>Random secrets of PHP, web development</description>
	<lastBuildDate>Fri, 30 Nov 2007 10:16:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress quicktag toolbar tweaking again</title>
		<link>http://blog.felho.hu/wordpress-quicktag-toolbar-tweaking-again.html</link>
		<comments>http://blog.felho.hu/wordpress-quicktag-toolbar-tweaking-again.html#comments</comments>
		<pubDate>Sat, 10 Nov 2007 20:39:03 +0000</pubDate>
		<dc:creator>Felho</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.felho.hu/wordpress-quicktag-toolbar-tweaking-again.html</guid>
		<description><![CDATA[It is said that it is a good behavior to set title attribute to a tags. I usually put to the title the text of the link. The process is: I put the link to the clipboard, go to the editor, select the text, press Ctrl-A, insert the link to the dialog box, press enter, [...]]]></description>
			<content:encoded><![CDATA[<p>It is said that it is a good behavior to set <code>title</code> attribute to <code>a</code> tags. I usually put to the <code>title</code> the text of the link. The process is: I put the link to the clipboard, go to the editor, select the text, press <code>Ctrl-A</code>, insert the link to the dialog box, press enter, then put the text of the link to the clipboard, go to the opening <code>a</code> tag, insert <code> title=""</code> and finally paste the text from the clipboard to the attribute. This is a repetitive and tedious task, so like in the <a href="http://blog.felho.hu/posting-source-code-in-wordpress-escaping-and-syntax-highlighting-the-inserted-code.html" title="previous case">previous case</a> I automate it. <span id="more-42"></span></p>
<p>To get <a href="http://wordpress.org/" title="WordPress">WordPress</a> to insert the <code>title</code> attribute automatically to <code>a</code> tag we had to modify the <a href="http://" title="wp-includes/js/quicktags.js">wp-includes/js/quicktags.js</a> file by adding a few lines of code to the <code>edInsertTag</code> function at two places:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>341
342
343
</pre></td><td class="code"><div class="javascript" style="font-family: monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == <span style="color: #3366CC;">'ed_link'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/&gt;/</span>, <span style="color: #3366CC;">' title=&amp;qout;'</span>+selectedText+<span style="color: #3366CC;">'&amp;qout;&gt;'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>357
358
359
</pre></td><td class="code"><div class="javascript" style="font-family: monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == <span style="color: #3366CC;">'ed_link'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/&gt;/</span>, <span style="color: #3366CC;">' title=&amp;qout;'</span>+selectedText+<span style="color: #3366CC;">'&amp;qout;&gt;'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></table></div>

<p>You can download the fully modified version <a href="http://blog.felho.hu/wp-includes/js/quicktags.js" title="The modified version of quicktags.js">from here</a> (this file contains my former modifications).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.felho.hu/wordpress-quicktag-toolbar-tweaking-again.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Posting source code in WordPress: escaping and syntax highlighting the inserted code</title>
		<link>http://blog.felho.hu/posting-source-code-in-wordpress-escaping-and-syntax-highlighting-the-inserted-code.html</link>
		<comments>http://blog.felho.hu/posting-source-code-in-wordpress-escaping-and-syntax-highlighting-the-inserted-code.html#comments</comments>
		<pubDate>Sun, 04 Nov 2007 08:26:00 +0000</pubDate>
		<dc:creator>Felho</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[geshi]]></category>
		<category><![CDATA[highlighting]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[wp-syntax]]></category>

		<guid isPermaLink="false">http://blog.felho.hu/posting-source-code-in-wordpress-escaping-and-syntax-highlighting-the-inserted-code.html</guid>
		<description><![CDATA[I have already mentioned that I had difficulty in finding a suitable solution to post source code in my blog. However good the workaround presented in my previous post is functioning, I was not satisfied with it. I noticed two annoying things. The first was that I had to escape HTML special chars &#8220;manually&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://blog.felho.hu/escaping-problem-with-wp-syntax-wordpress-plugin.html">have already mentioned</a> that I had difficulty in finding a suitable solution to post source code in my blog. However good the workaround presented in my previous post is functioning, I was not satisfied with it. I noticed two annoying things. The first was that I had to escape HTML special chars &#8220;manually&#8221; in the inserted code, which was a pain in the ass. My second problem was (I like to indent my code with TAB) that indentation was too wide, which looked not really nice out (and was impractical when your code has multiple nested control structures). After a little JavaScript hacking and playing with <a href="http://qbnz.com/highlighter/" title="GeSHi - Generic Syntax Highlighter">GeSHi</a> and CSS I solved both of them.<span id="more-20"></span></p>
<p>A little side note: I found that the built-in rich text editor is almost absolutely useless, so I turned it off, and I suggest it to every WordPress user.  </p>
<h2>Escaping the inserted code</h2>
<p>When you want to put some source code to the post, you usually simply enclose it in <code>code</code> or <code>pre</code> tags. The problem is, that the source code may contain characters which have special meaning in the HTML language, so they should be escaped. These characters are: <code>&lt;</code>, <code>&gt;</code>, <code>&amp;</code>, <code>&qout;</code> and they should be converted to: <code>&amp;lt;</code>, <code>&amp;gt;</code>, <code>&amp;amp;</code>, <code>&amp;qout;</code>. I would like to have some kind of automation for this task, which could be run when we insert the text to the post.</p>
<p>When you insert a code (and use a syntax highlighter) you should specify the language of that code. For example if you use the WP-Syntax plugin you should enclose your code in <code>pre</code> tags and use the <code>lang</code> attribute to specify the language. In addition you can mark if you want line numbers to appear. Enclosing the copy-pasted text is another repetitive and tedious task so it is another good candidate for automation</p>
<p>It would be great if we could do this two task in one step, so I thought I extend the toolbar above the textarea to provide this functionality by adding a new <code>sourcecode</code> button to it:<br />
<img width="500" src='http://blog.felho.hu/wp-content/toolbarsourcecodebutton.png' alt='Toolbar sourcecode button' /></p>
<p>The <code>sourcecode</code> button works similar as the others button on the toolbar, if no text is selected on the first click it inserts the open tag, on the second click it inserts the close tag. If text is selected it encloses the text in <code>pre</code> tags when you activate it. The button can be accessed via <code>Ctrl-F</code> keyboard shortcut too. Before it ads the open tag to the editor it prompts for the syntax highlighting parameters and generates the proper open tag to them. When text is selected the special characters will be replaced to HTML entities in it. This way adding source code to your post will be very straightforward:</p>
<p>1. Select the text in te editor:<br />
<img width="500" src='http://blog.felho.hu/wp-content/selectthesourcecode.png' alt='Select the source code' /><br />
2. Select the inserted text and press <code>Ctrl-F</code>:<br />
<img width="500" src='http://blog.felho.hu/wp-content/selecttheinsertedtext.png' alt='Select the inserted text' /><br />
3. Type the syntax highlighting information:<br />
<img width="350" src='http://blog.felho.hu/wp-content/typesyntaxhighlightinginformation.png' alt='Type syntax highlighting information' /><br />
4. The resulted text is:<br />
<img width="500" src='http://blog.felho.hu/wp-content/theresulttext.png' alt='The resulted text' /></p>
<p>Extending the toolbar is quite easy, only the <code>wp-includes/js/quicktags.js</code> file should be slightly modified (you can download the fully modified version <a href="http://blog.felho.hu/wp-includes/js/quicktags.js">from here</a>, all the modifications are commented). To add a new button to the toolbar you should add the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>127
128
129
130
131
132
133
</pre></td><td class="code"><div class="javascript" style="font-family: monospace;">edButtons<span style="color: #66cc66;">&#91;</span>edButtons.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#93;</span> = <br />
<span style="color: #003366; font-weight: bold;">new</span> edButton<span style="color: #66cc66;">&#40;</span>&amp;#<span style="color: #CC0000;">39</span>;ed_pre&amp;#<span style="color: #CC0000;">39</span>;<br />
,&amp;#<span style="color: #CC0000;">39</span>;pre&amp;#<span style="color: #CC0000;">39</span>;<br />
,&amp;#<span style="color: #CC0000;">39</span>;&lt;pre&gt;&amp;#<span style="color: #CC0000;">39</span>;<br />
,&amp;#<span style="color: #CC0000;">39</span>;&lt;/pre&gt;&amp;#<span style="color: #CC0000;">39</span>;<br />
,&amp;#<span style="color: #CC0000;">39</span>;f&amp;#<span style="color: #CC0000;">39</span>;<br />
<span style="color: #66cc66;">&#41;</span>;</div></td></tr></table></div>

<p>After then we should modify the <code>edInsertTag</code> function, and we are ready:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
</pre></td><td class="code"><div class="javascript" style="font-family: monospace;"><span style="color: #009900; font-style: italic;">//------&lt;code modification&gt;-------</span><br />
<span style="color: #009900; font-style: italic;">// Prompts for syntax highlighting parameter, and return the appropriate start tag.</span><br />
<span style="color: #009900; font-style: italic;">// TODO: l10n support.</span><br />
<span style="color: #003366; font-weight: bold;">function</span> edGetPreStartTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> syntaxInfo = <span style="color: #000066;">prompt</span><span style="color: #66cc66;">&#40;</span>&amp;#<span style="color: #CC0000;">39</span>;Please insert syntax highlighting information:&amp;#<span style="color: #CC0000;">39</span>;+&amp;qout;\n&amp;qout;+&amp;#<span style="color: #CC0000;">39</span>;language<span style="color: #66cc66;">&#91;</span>, line number<span style="color: #66cc66;">&#93;</span>!&amp;#<span style="color: #CC0000;">39</span>;, &amp;#<span style="color: #CC0000;">39</span>;php,<span style="color: #CC0000;">1</span>&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span>&amp;#<span style="color: #CC0000;">39</span>;,&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> &amp;#<span style="color: #CC0000;">39</span>;&lt;pre lang=&amp;qout;&amp;#<span style="color: #CC0000;">39</span>;+syntaxInfo<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span>+&amp;#<span style="color: #CC0000;">39</span>;&amp;qout;&amp;#<span style="color: #CC0000;">39</span>;+<span style="color: #66cc66;">&#40;</span>syntaxInfo<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#93;</span> != undefined ? &amp;#<span style="color: #CC0000;">39</span>; line=&amp;qout;&amp;#<span style="color: #CC0000;">39</span>;+syntaxInfo<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#93;</span>+&amp;#<span style="color: #CC0000;">39</span>;&amp;qout;&amp;#<span style="color: #CC0000;">39</span>; : &amp;#<span style="color: #CC0000;">39</span>;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>+&amp;#<span style="color: #CC0000;">39</span>;&gt;&amp;#<span style="color: #CC0000;">39</span>;+&amp;qout;\n&amp;qout;;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// It converts all HTML special chars to HTML entites</span><br />
<span style="color: #003366; font-weight: bold;">function</span> edHtmlSpecialChars<span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> string.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/&amp;/g, &amp;#<span style="color: #CC0000;">39</span>;&amp;amp;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>/&lt;/g</span>, &amp;#<span style="color: #CC0000;">39</span>;&amp;lt;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/&gt;/g, &amp;#<span style="color: #CC0000;">39</span>;&amp;gt;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>/&amp;qout;/g</span>, &amp;#<span style="color: #CC0000;">39</span>;&amp;qout;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/&amp;#<span style="color: #CC0000;">39</span>;/g</span>, &amp;#<span style="color: #CC0000;">39</span>;&amp;#<span style="color: #CC0000;">39</span>;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #009900; font-style: italic;">//------&lt;/code modification&gt;-------</span><br />
<br />
<span style="color: #009900; font-style: italic;">// insertion code</span><br />
<br />
<span style="color: #003366; font-weight: bold;">function</span> edInsertTag<span style="color: #66cc66;">&#40;</span>myField, i<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//IE support</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>document.<span style="color: #006600;">selection</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #000066;">focus</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; sel = document.<span style="color: #006600;">selection</span>.<span style="color: #006600;">createRange</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>sel.<span style="color: #006600;">text</span>.<span style="color: #006600;">length</span> &gt; <span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == &amp;#<span style="color: #CC0000;">39</span>;ed_pre&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sel.<span style="color: #006600;">text</span> = edHtmlSpecialChars<span style="color: #66cc66;">&#40;</span>sel.<span style="color: #006600;">text</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edGetPreStartTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;/code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sel.<span style="color: #006600;">text</span> = edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> + sel.<span style="color: #006600;">text</span> + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!edCheckOpenTags<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span> || edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span> == &amp;#<span style="color: #CC0000;">39</span>;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == &amp;#<span style="color: #CC0000;">39</span>;ed_pre&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edGetPreStartTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;/code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sel.<span style="color: #006600;">text</span> = edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edAddTag<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sel.<span style="color: #006600;">text</span> = edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edRemoveTag<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #000066;">focus</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//MOZILLA/NETSCAPE support</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>myField.<span style="color: #006600;">selectionStart</span> || myField.<span style="color: #006600;">selectionStart</span> == &amp;#<span style="color: #CC0000;">39</span>;<span style="color: #CC0000;">0</span>&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> startPos = myField.<span style="color: #006600;">selectionStart</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> endPos = myField.<span style="color: #006600;">selectionEnd</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cursorPos = endPos;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> scrollTop = myField.<span style="color: #006600;">scrollTop</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>startPos != endPos<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> selectedText = myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span>startPos, endPos<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> selectedTextLengthGrowth = <span style="color: #CC0000;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == &amp;#<span style="color: #CC0000;">39</span>;ed_pre&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edGetPreStartTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedTextLengthGrowth = selectedText.<span style="color: #006600;">length</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedText = edHtmlSpecialChars<span style="color: #66cc66;">&#40;</span>selectedText<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedTextLengthGrowth = selectedText.<span style="color: #006600;">length</span> - selectedTextLengthGrowth;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">value</span> = myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span>, startPos<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + selectedText<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span>endPos, myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursorPos += edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span>.<span style="color: #006600;">length</span> + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span>.<span style="color: #006600;">length</span> + selectedTextLengthGrowth;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;/code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!edCheckOpenTags<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span> || edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span> == &amp;#<span style="color: #CC0000;">39</span>;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == &amp;#<span style="color: #CC0000;">39</span>;ed_pre&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edGetPreStartTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;/code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">value</span> = myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span>, startPos<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span>endPos, myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edAddTag<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursorPos = startPos + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span>.<span style="color: #006600;">length</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">value</span> = myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span>, startPos<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span>endPos, myField.<span style="color: #006600;">value</span>.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edRemoveTag<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursorPos = startPos + edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span>.<span style="color: #006600;">length</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #000066;">focus</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">selectionStart</span> = cursorPos;<br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">selectionEnd</span> = cursorPos;<br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">scrollTop</span> = scrollTop;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!edCheckOpenTags<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span> || edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span> == &amp;#<span style="color: #CC0000;">39</span>;&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span> == &amp;#<span style="color: #CC0000;">39</span>;ed_pre&amp;#<span style="color: #CC0000;">39</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span> = edGetPreStartTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------&lt;/code modification&gt;-------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">value</span> += edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagStart</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edAddTag<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #006600;">value</span> += edButtons<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">tagEnd</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edRemoveTag<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myField.<span style="color: #000066;">focus</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></table></div>

<h2>Controlling the indentation</h2>
<p>The <a href="http://wordpress.org/extend/plugins/wp-syntax/" title="WP-Syntax plugin home page">WP-Syntax plugin</a> uses GeSHi with default settings, which means that GeSHi wraps code blocks in <code>pre</code> tags. In this mode GeSHi doesn&#8217;t replace TAB characters with spaces, so we can&#8217;t control the appearance of the indentation. But if we instruct GeSHi to use <code>div</code> tags instead of <code>pre</code>, it will replace leading TAB characters to spaces, and you can set the number of spaces. If we want to use 4 spaces we should modify the plugin accordingly to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>79
80
81
82
</pre></td><td class="code"><div class="php" style="font-family: monospace;"><span style="color: #0000ff;">$geshi</span> = <span style="color: #000000; font-weight: bold;">new</span> GeSHi<span style="color: #66cc66;">&#40;</span>htmlspecialchars_decode<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$code</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$language</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0000ff;">$geshi</span>-&gt;<span style="color: #006600;">enable_keyword_links</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0000ff;">$geshi</span>-&gt;<span style="color: #006600;">set_header_type</span><span style="color: #66cc66;">&#40;</span>GESHI_HEADER_DIV<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0000ff;">$geshi</span>-&gt;<span style="color: #006600;">set_tab_width</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></table></div>

<p>After this modification you should probably modify your CSS. I use now the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><div class="css" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">/***** SYNTAX HIGHLIGHTER *****/</span><br />
<span style="color: #6666ff;">.wp_syntax</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #cc00cc;">#<span style="color: #933;">100</span></span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span>: <span style="color: #cc00cc;">#f9f9f9</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span>: <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">silver</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span>: <span style="color: #933;">0</span> <span style="color: #933;">0</span> <span style="color: #933;">1</span><span style="color: #6666ff;"><span style="color: #933;">.5em</span></span> <span style="color: #933;">0</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">overflow</span>: <span style="color: #993333;">auto</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* IE FIX */</span><br />
<span style="color: #6666ff;">.wp_syntax</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; overflow-x: <span style="color: #993333;">auto</span>;<br />
&nbsp; &nbsp; overflow-y: <span style="color: #993333;">hidden</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding-bottom</span>: expression<span style="color: #66cc66;">&#40;</span>this<span style="color: #6666ff;">.scrollWidth</span> &gt; this<span style="color: #6666ff;">.offsetWidth</span> ? <span style="color: #933;">15</span> : <span style="color: #933;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span>: <span style="color: #933;"><span style="color: #933;">100</span>%</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.wp_syntax</span> table <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-collapse</span>: <span style="color: #993333;">collapse</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.wp_syntax</span> div, <span style="color: #6666ff;">.wp_syntax</span> td <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">vertical-align</span>: <span style="color: #000000; font-weight: bold;">top</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #933;">2px</span> <span style="color: #933;">4px</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">white-space</span>: <span style="color: #993333;">nowrap</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.wp_syntax</span> <span style="color: #6666ff;">.line_numbers</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-align</span>: <span style="color: #000000; font-weight: bold;">right</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span>: <span style="color: #cc00cc;">#e8e9dc</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">gray</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">overflow</span>: <span style="color: #993333;">visible</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
td<span style="color: #6666ff;">.code</span> div <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding-top</span>: <span style="color: #933;">0px</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></table></div>

<p>I think these modifications would be interesting in the official WordPress version too, I found them useful, now I can insert source code to the post in a very convenient way.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.felho.hu/posting-source-code-in-wordpress-escaping-and-syntax-highlighting-the-inserted-code.html/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Escaping problem with WP-Syntax WordPress plugin</title>
		<link>http://blog.felho.hu/escaping-problem-with-wp-syntax-wordpress-plugin.html</link>
		<comments>http://blog.felho.hu/escaping-problem-with-wp-syntax-wordpress-plugin.html#comments</comments>
		<pubDate>Tue, 30 Oct 2007 00:48:40 +0000</pubDate>
		<dc:creator>Felho</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[geshi]]></category>
		<category><![CDATA[highlighting]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[wp-syntax]]></category>

		<guid isPermaLink="false">http://blog.felho.hu/escaping-problem-with-wp-syntax-wordpress-plugin</guid>
		<description><![CDATA[When I started this blog I had spent some time finding a syntax highlighter plug-in for the code snippets presented in the posts. I went to wordpress.org and I tried out some of the plug-ins, but I had some problems with all of them. After a few hours I found the WP-Syntax plug-in. I had [...]]]></description>
			<content:encoded><![CDATA[<p>When I started this blog I had spent some time finding a syntax highlighter plug-in for the code snippets presented in the posts. I went to <a href="http://wordpress.org" title="WordPress.org">wordpress.org</a> and I tried out some of the plug-ins, but I had some problems with all of them. After a few hours I found the WP-Syntax plug-in. I had had already some positive experience with the <a href="http://qbnz.com/highlighter/" title="Generic Syntax Highlighter">GeSHi </a>(Generic Syntax Highlighter) library, and I liked the <a href="http://www.emacsblog.org/2007/02/22/maximize-on-startup-part-2/" title="Maximize on startup - Part 2">demo</a> on the <a href="http://www.emacsblog.org" title="EmacsBlog">EmacsBlog</a> so I thought this is what I wanted.<span id="more-14"></span></p>
<p>I tried it out and I noticed that it doesn&#8217;t look as fancy as in the demo page. After a fast search I found that I need the following CSS addition:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><div class="css" style="font-family: monospace;"><span style="color: #6666ff;">.wp_syntax</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #cc00cc;">#<span style="color: #933;">100</span></span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span>: <span style="color: #cc00cc;">#f9f9f9</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span>: <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">silver</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span>: <span style="color: #933;">0</span> <span style="color: #933;">0</span> <span style="color: #933;">1</span><span style="color: #6666ff;"><span style="color: #933;">.5em</span></span> <span style="color: #933;">0</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">overflow</span>: <span style="color: #993333;">auto</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* IE FIX */</span><br />
<span style="color: #6666ff;">.wp_syntax</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; overflow-x: <span style="color: #993333;">auto</span>;<br />
&nbsp; &nbsp; overflow-y: <span style="color: #993333;">hidden</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding-bottom</span>: expression<span style="color: #66cc66;">&#40;</span>this<span style="color: #6666ff;">.scrollWidth</span> &gt; this<span style="color: #6666ff;">.offsetWidth</span> ? <span style="color: #933;">15</span> : <span style="color: #933;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span>: <span style="color: #933;"><span style="color: #933;">100</span>%</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.wp_syntax</span> table <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-collapse</span>: <span style="color: #993333;">collapse</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.wp_syntax</span> div, <span style="color: #6666ff;">.wp_syntax</span> td <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">vertical-align</span>: <span style="color: #000000; font-weight: bold;">top</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #933;">2px</span> <span style="color: #933;">4px</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.wp_syntax</span> <span style="color: #6666ff;">.line_numbers</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-align</span>: <span style="color: #000000; font-weight: bold;">right</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span>: <span style="color: #cc00cc;">#def</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">gray</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">overflow</span>: <span style="color: #993333;">visible</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* potential overrides for other styles */</span><br />
<span style="color: #6666ff;">.wp_syntax</span> pre <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span>: <span style="color: #933;">0</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span>: <span style="color: #993333;">auto</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">float</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">clear</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">overflow</span>: <span style="color: #993333;">visible</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></table></div>

<p>I added it to theme&#8217;s CSS, and I was happy. I started to finish my <a href="http://blog.felho.hu/neon-zend-studio-for-eclipse">first post</a>, but I noticed a very annoying behavior of the plug-in. The sample code contained &#8220;&gt;&#8221; character, but in the post appeared &#8220;&amp;gt;&#8221;. I was a little disappointed, but I thought it will be easy to find the source of the problem.</p>
<p>First I looked into the source of the highlighter plug-in, and observed that GeSHi converts the HTML special chars to HTML entities with its own <code>hcs()</code> function.  GeSHi could not be asked not to do this conversion, so I had to modify the plug-in a little:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>79
80
</pre></td><td class="code"><div class="php" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">//$geshi = new GeSHi($code, $language);</span><br />
<span style="color: #0000ff;">$geshi</span> = <span style="color: #000000; font-weight: bold;">new</span> GeSHi<span style="color: #66cc66;">&#40;</span>htmlspecialchars_decode<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$code</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$language</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></table></div>

<p>Unfortunately the server where this blog runs has PHP older than 5.1, so I had to create my own version of <a href="http://php.net/htmlspecialchars_decode"><code>htmlspecialchars_decode()</code></a>, so I add this code to the plug-in too:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>63
64
65
66
67
</pre></td><td class="code"><div class="php" style="font-family: monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #000066;">function_exists</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;htmlspecialchars_decode&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> htmlspecialchars_decode<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span>, <span style="color: #0000ff;">$quote_style</span> = ENT_COMPAT<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000066;">strtr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span>, <span style="color: #000066;">array_flip</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">get_html_translation_table</span><span style="color: #66cc66;">&#40;</span>HTML_SPECIALCHARS, <span style="color: #0000ff;">$quote_style</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></table></div>

<p>This little hack solved my problem, I hope it could be useful for others too.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.felho.hu/escaping-problem-with-wp-syntax-wordpress-plugin.html/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>


