<?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>techNerdia - Web Development Tips &#187; javascript</title> <atom:link href="http://technerdia.com/tag/javascript/feed" rel="self" type="application/rss+xml" /><link>http://technerdia.com</link> <description>Web Development Tips, Tricks and Ideas</description> <lastBuildDate>Mon, 07 May 2012 16:46:34 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Add Google Code SyntaxHighlighter to WordPress without using a Plugin</title><link>http://technerdia.com/885_syntaxhighlighter.html</link> <comments>http://technerdia.com/885_syntaxhighlighter.html#comments</comments> <pubDate>Tue, 21 Feb 2012 21:05:51 +0000</pubDate> <dc:creator>tribalNerd</dc:creator> <category><![CDATA[Customizing]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[code]]></category> <category><![CDATA[google]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[markup]]></category> <category><![CDATA[php]]></category> <category><![CDATA[wp]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://technerdia.com/?p=885</guid> <description><![CDATA[Instantly transform code/scripts/markup (php, html, css, java, etc) into a readable and downloadable example code.<p><div
style="border-top:1px dotted #cccccc;clear:both;font-size:14px;font-weight:bold;margin:2px 10px;padding:0 10px;text-align:left;"><ul><li><b>New Wordpress Plugin</b> <a
href="http://technerdia.com/projects/adminbar/plugin.html" target="_blank">WP My Admin Bar</a> (It's Free, Download Today!)</li><li><b>Reading:</b> <a
href="http://technerdia.com/885_syntaxhighlighter.html">Add Google Code SyntaxHighlighter to WordPress without using a Plugin</a> <b>By:</b> <a
href="https://plus.google.com/105408082571454010152/" target="_blank">tribalNerd</a> <b>From:</b> <a
href="http://technerdia.com/" target="_blank">techNerdia - Web Development Tips</a></li><li><b><a
href="https://plus.google.com/u/0/108046225913965315594/posts" target="_blank">Follow techNerdia on Google+</a></li></ul></div><p
align="center">~ <b>Thank you for subscribing to techNerdia.com - Please Share This Post With Others</b> ~</p></p> ]]></description> <content:encoded><![CDATA[<p>The <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3N5bnRheGhpZ2hsaWdodGVyLw==" target=\"_blank\">Google Code SyntaxHighlighter</a> instantly transforms code/scripts/markup (php, html, css, java, etc) into a readable and downloadable example code.</p><p><img
src="http://technerdia.com/files/syntaxhighlighter.jpg" alt="Google Syntax Highlighter Example" width="697" height="179" class="aligncenter" /></p><p><strong>Disclaimer:</strong> <em>If your Website has an active Syntax Highlighter installed on it, then you must replace the old Syntax Highlighter wraps with the style used by the Google SyntaxHighlighter. Otherwise your code examples will break.</em></p><p
class="alignCenter"><strong><em>Keep Current Syntax Highlighter Plugins / Scripts Active Until All Old Examples Have Been Replaced!</em></strong></p><hr
/><h2>Why use the Google SyntaxHighlighter?</h2><p>Because it&#8217;s pretty dang good! Of course, having the source code has massive advantages too. Also, not loading more brushes than your site may use, along with the ability to customize the look to your desires.</p><p>The SyntaxHighlighter currently Supports: C++, C#, CSS, Delphi, Java, JavaScript, PHP, Python, Ruby, Sql, VB, and XML/HTML markup and code types. [ <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3N5bnRheGhpZ2hsaWdodGVyL3dpa2kvTGFuZ3VhZ2Vz" target=\"_blank\">source</a> ]</p><h2>How Does The Google SyntaxHighlighter Work?</h2><p>It uses Javascript to find the HTML Pre tag and parse the &#8216;code&#8217; data within it. The Pre tag contains the type of code being displayed, allowing a filter to be called that translates the code or markup to readable text within the browser rather than rendering it with the Webpage markup.</p><p><strong>Example Pre Tag</strong>:</p><div
class="mycode"><pre name="code" class="html">&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;/* html markup here */&lt;/pre&gt;</pre></div><h2>Adding the SyntaxHighlighter to your WordPress Blog</h2><p>First, <strong><a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3N5bnRheGhpZ2hsaWdodGVyL2Rvd25sb2Fkcy9kZXRhaWw/bmFtZT1TeW50YXhIaWdobGlnaHRlcl8xLjUuMS5yYXI=" target=\"_blank\">download the SyntaxHighlighter rar file</a></strong> from Google Code. After you unRAR (<a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy43LXppcC5vcmcv" target=\"_blank\">7zip</a>) the file, finally open the dp.SyntaxHighlighter directory.</p><p>Within the directory will be three sub-folders:</p><ul><li><strong>Scripts</strong>: Core code and brush script files.</li><li><strong>Styles</strong>: The core CSS file.</li><li><strong>Uncompressed</strong>: Ignore</li></ul><h3>Let&#8217;s Get Started&#8230;</h3><p><strong>The CSS File</strong></p><ul><li>Enter the Styles directory, open the SyntaxHighlighter.css file, select all and copy the entire file.</li><li>Open your themes style.css file, paste the SyntaxHighlighter css data into your themes css file. I put this at the bottom of my css files, below the mobile goodies, sprites, etc.</li><li>Save the file and upload it to your WordPress theme directory.</li></ul><p><strong>The Core</strong></p><ul><li>Go back and into the Scripts directory.</li><li>Find the shCore.js file and right click the file and rename it to: SyntaxHighlighter.js</li></li><li>Open the file in Notepad or <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mbG9zLWZyZWV3YXJlLmNoL25vdGVwYWQyLmh0bWw=" target=\"_blank\">Notepad2</a> (what I use) or <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL25vdGVwYWQtcGx1cy1wbHVzLm9yZy9kb3dubG9hZC92NS45LjguaHRtbA==" target=\"_blank\">Notepad+</a></li><li>Leave the file open&#8230;.</li></ul><p><strong>The Brushes</strong><br
/> Brushes, is a term (or name) used to identify the highlighter script for a type of code or script being displayed.</p><p>For example, within the Scripts folder is shBrushCSS.js &#8211; This file would be called when displaying a CSS file within the &#8216;pre&#8217; tag.</p><ul><li><a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3N5bnRheGhpZ2hsaWdodGVyL3dpa2kvTGFuZ3VhZ2Vz" target=\"_blank\">View All Possible Code Languages That Can Be Called.</a></li></ul><p>Most Websites will use only a few Brushes. techNerdia for example uses these brushes: CSS, Javascript, PHP, XML/HTML and SQL. These are the only loaded brushes, the others have been ignored.</p><ul><li>Open the brush files that you&#8217;ll be using on your Website.</li><li>Select all and copy the contents of one of the brush file.</li><li>Return to the already opened SyntaxHighlighter.js file, scroll to the very bottom (last line) and paste the Brush code in.</li><li>Repeat this for each Brush type that you&#8217;ll be using.</li><li>Save the file when done. Uplaod the SyntaxHighlighter.js file to your Website/Server. I uploaded mine to domain.com/js/</li></ul><p><strong>Note</strong>: The Scripts directory contains a flash file named clipboard.swf. I could not get this feature working, so I&#8217;ve excluded it.</p><h3>Turning on the SyntaxHighlighter</h3><p>With the CSS data and SyntaxHighlighter.js files uploaded, it&#8217;s time to activate the highlighter.</p><p>** <strong>Do Not Disable</strong> Other highlighter Plugins Yet!!!</p><ul><li>Open your themes footer.php file, scroll to the bottom and find wp_footer().</li><li>Paste the snip below, above the wp_footer() line and above your Google Analytics code, if it&#8217;s in the footer.</li><li>Adjust the URL to the SyntaxHighlighter.js file, save the file, and upload to your theme or /js directory.</li></ul><div
class="mycode"><pre name="code" class="php">
&lt;?php if( is_singular() ){
&lt;script language=&quot;javascript&quot; src=&quot;http://domain.com/js/SyntaxHighlighter.js&quot;&gt;&lt;/script&gt;
&lt;script language=&quot;javascript&quot;&gt;
	dp.SyntaxHighlighter.HighlightAll(&#39;code&#39;);
&lt;/script&gt;
} ?&gt;
</pre></div><h3>Test the SyntaxHighlighter</h3><p>Easy enough&#8230;.</p><ul><li>Go into your WordPress Admin and CLEAR THE CACHE!</li><li>Create a new post, add the snip below to the body of the post, save the post as a draft, and preview it.</li></ul><div
class="mycode"><pre name="code" class="html"><pre name="code" class="html"><b>It's Working!</b></pre></pre></div><p>The class=&#8221;html&#8221; is what tells the script which brush to load. Change it to php, js, css, etc to display different code/markup types.</p><p>If something isn&#8217;t working, then a step is missing: Check the URL to the SyntaxHighlighter.js file, check that the Brushes have been added to the bottom of the file. Make sure the CSS data has been uploaded or added to your root css file. Ensure the footer call is above the wp_footer() line. Clear the caches again. Try a different brush. Try a different browser.</p><h3>Removing What Isn&#8217;t Used</h3><p>It&#8217;s time to find and replace a few things&#8230; with SyntaxHighlighter.js file open:</p><ul><li>Do a find for: <em>copy to clipboard</em></li><li>Remove the <em>copy to clipboard</em> words <strong>only</strong>.</li><li>Do a find for: <em>print</em> it will be within a label, like: label:&#8217;print&#8217;</li><li>Remove the word <em>print</em> <strong>only</strong>.</li></ul><p>The last removal is optional, it&#8217;s the question mark ? that contains the about information. If you remove this, you should give credit some place&#8230;. like making a blog post about the <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3N5bnRheGhpZ2hsaWdodGVyLw==" target=\"_blank\">SyntaxHighlighter</a>.</p><ul><li>To remove, do a find for: <em>label:&#8217;?&#8217;</em></li><li>Remove the <em>question mark ?</em> <strong>only</strong>.</li></ul><ul><li>Save your work, re-upload the file and retest.</li></ul><h2>Customizing the Look of the SyntaxHighlighter</h2><p>The Pre tag wrapper for the code has one customization that can be added to it. It&#8217;s a :collapse feature, which closes the code example when the page is loaded, and opening when clicked.</p><p>Example:</p><div
class="mycode"><pre name="code" class="html:collapse">&lt;pre name=&quot;code&quot; class=&quot;html:collapse&quot;&gt;/* html markup here */&lt;/pre&gt;</pre></div><h2>Wrap the Pre Tag Within a Class</h2><p>This isn&#8217;t mandatory to get the code working, but it does help if for some reason the JavaScript brushes do not load, and it makes the code display.</p><p>Add a class called &#8216;mycode&#8217; around the Pre tag of your code, then define it within your themes CSS file.</p><p><strong>Example</strong>:</p><div
class="mycode"><pre name="code" class="html">&lt;div class=&quot;mycode&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;/* the sample */&lt;/pre&gt;&lt;/div&gt;</pre></div><p><strong>mycode Class</strong>:</p><div
class="mycode"><pre name="code" class="css">
.mycode {
	border-bottom:1px dotted #aaaaaa;
	color:#006400;
	font-size:11px;
	line-height:16px;
	margin: -5px 0 20px 0;
	padding:0;
}
</pre></div><h3>The Main CSS File</h3><p>If the visual display of the code does not match design, then open the CSS file that contains the SyntaxHighlighter CSS data.</p><p><strong>The main wrapper</strong>: .dp-highlighter<br
/> Adjust the background color, typically this color should be different than your body color of your page, to help the code example stand out.</p><p>You may also want to add a line-height, larger than 12px and increase the padding around each line, this helps with readability.</p><p><strong>Example</strong>:</p><div
class="mycode"><pre name="code" class="css">
line-height:22px;
padding:10px 0;
</pre></div><p><strong>Complete</strong>:</p><div
class="mycode"><pre name="code" class="css">
.dp-highlighter {
	background:#ffffff;
	background-color:#ffffff;
	font-family:"Consolas", "Courier New", Courier, mono, serif;
	font-size:12px;
	line-height:22px;
	margin:18px 0 18px 0 !important;
	overflow:auto;
	padding:10px 0;
	width:99%;
}
</pre></div><p><strong>Rounded corners</strong>: Add the CSS below to the .dp-highlighter class.</p><div
class="mycode"><pre name="code" class="css">.dp-highlighter { -moz-border-radius: 9px; -webkit-border-radius: 9px; -khtml-border-radius: 9px; border-radius: 9px; }</pre></div><p><strong>Color Changes</strong>:
If you&#8217;ve adjusted the background color, you&#8217;ll probably want to adjust the other color settings. Do a find for the classes below, and adjust the color or background color setting.</p><div
class="mycode"><pre name="code" class="css">
.dp-highlighter ol /* base number colors */
.dp-highlighter .columns div /* odd number colors, I think */
.dp-highlighter .columns /* even numbers */
.dp-highlighter .tools /* toolbar colors */
.dp-highlighter .tools a /* link color in toolbar */
</pre></div><p>The last bit of the CSS information controls the colors of the code within the example. Adjust as needed.</p><h2>Cleanup And Disable SyntaxHighlighter Plugins</h2><p>Update old posts to use the new Pre tag wrapper, then disable old Syntax Highlighter Plugins and code.</p><p>It may seem obvious, but make sure you check check your work!!!</p><hr
/><h4>If you've enjoyed this article then please leave me some <a
href="http://technerdia.com/feedback.html" target="_blank">feedback</a>, thanks!</h4><br
/><p><div
style="border-top:1px dotted #cccccc;clear:both;font-size:14px;font-weight:bold;margin:2px 10px;padding:0 10px;text-align:left;"><ul><li><b>New WordPress Plugin</b> <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2huZXJkaWEuY29tL3Byb2plY3RzL2FkbWluYmFyL3BsdWdpbi5odG1s" target=\"_blank\">WP My Admin Bar</a> (It's Free, Download Today!)</li><li><b>Reading:</b> <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2huZXJkaWEuY29tLzg4NV9zeW50YXhoaWdobGlnaHRlci5odG1s">Add Google Code SyntaxHighlighter to WordPress without using a Plugin</a> <b>By:</b> <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9wbHVzLmdvb2dsZS5jb20vMTA1NDA4MDgyNTcxNDU0MDEwMTUyLw==" target=\"_blank\">tribalNerd</a> <b>From:</b> <a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2huZXJkaWEuY29tLw==" target=\"_blank\">techNerdia - Web Development Tips</a></li><li><b><a
href="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9wbHVzLmdvb2dsZS5jb20vdS8wLzEwODA0NjIyNTkxMzk2NTMxNTU5NC9wb3N0cw==" target=\"_blank\">Follow techNerdia on Google+</a></li></ul></div><p
align="center">~ <b>Thank you for subscribing to techNerdia.com - Please Share This Post With Others</b> ~</p></p> <img
src="http://technerdia.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=885" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://technerdia.com/885_syntaxhighlighter.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
