SyntaxHighlighter Ajax

SyntaxHighlighter Ajax

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
115 views

SyntaxHighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript. To get an idea of what SyntaxHighlighter is capable of, have a look at the demo page.

The project was started in 2004 and since then has gained a lot of acceptance. Version 2.0 is the new page in history of the project representing a near complete rewrite, clean up, optimization, standard compliance and new features.

Public Wiki

This is a public wiki. Most pages are open for contributions. If you would like to expand documentation or see a mistake, please feel free to correct or add more information. All offendending IPs will be banned permamently.
Preparing the page
After you got the files extracted and placed in your project, you will need to link them from your pages. For the purpose of this demonstration it will be assumed that scripts/*.* was extracted and placed into /scripts folder and styles/*.* into /styles.

The first file that you should get out of the way is adding SyntaxHighlighter main and theme CSS files to the tag like so:

<head>
	...
	<link type="text/css" rel="stylesheet" href="/styles/shCore.css" />
	<link type="text/css" rel="stylesheet" href="/styles/shThemeDefault.css" />
</head>

After that you have to add shCore.js followed by all brushes that you want to use (full list of default brushes):

<script type="text/javascript" src="/scripts/shCore.js"></script>
<script type="text/javascript" src="/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="/scripts/shBrushCpp.js"></script>

The last thing is to add a call to SyntaxHighlighter.all() like so:

<script type="text/javascript">
	SyntaxHighlighter.all();
</script>

And all together it should look like this:

<html>
	<head>
		<link type="text/css" rel="stylesheet" href="/styles/shCore.css" />
		<link type="text/css" rel="stylesheet" href="/styles/shThemeDefault.css" />
		<script type="text/javascript" src="/scripts/shCore.js"></script>
		<script type="text/javascript" src="/scripts/shBrushJScript.js"></script>
		<script type="text/javascript" src="/scripts/shBrushBash.js"></script>
		<script type="text/javascript" src="/scripts/shBrushCpp.js"></script>
		<script type="text/javascript">
			SyntaxHighlighter.all();
		</script>
	</head>

	...
</html>

Adding code blocks

SyntaxHighlighter looks for

 tags which have specially formatted class attribute. The format of the attribute is the same as style. The only required parameter is brush (see configuration) which should be set to one of the brush aliases that you have loaded prior.

Here's a typical example: 
<pre class="brush: js">
	alert("Hello world");
</pre>

Escaping XML tags

Because of the browser nature it is impossible to put left angle bracket "< " character unescaped. This character causes browsers to interpret the following text as XML tags which can completly break your highlighted block or even the whole page. Please make sure to replace all instance of < with <

Demo: http://alexgorbatchev.com/wiki/SyntaxHighlighter:Demo

Download: http://alexgorbatchev.com/downloads/grab.php?name=sh

Source: http://alexgorbatchev.com/wiki/SyntaxHighlighter

http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/stumbleupon_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/delicious_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/blinklist_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/furl_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/technorati_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/magnolia_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/google_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/myspace_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/facebook_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/sphinn_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/mixx_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/twitter_32.png

Related Listings:

  1. Scriptaculous Effect Script Script.aculo.us is a set of JavaScript libraries to enhance the...
  2. Lighter.js – Syntax highlighting for MooTools Lighter.js is a free syntax highlighting class developed with...
  3. AJAX image gallery Script Pyxy-gallery is an AJAX image gallery in PHP and JavaScript,...
  4. Form With Style – Ajax Script Forms are not very friendly when it comes to CSS...
  5. Lighter.js – Syntax highlighting for MooTools Lighter.js is a free syntax highlighting class developed with MooTools....

Do you like this post?

Email:     

Tags: , , , , , , , , , , , , , , , , , , ,

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment



Web Design & CSS (Templates) - TOP.ORG