NP_SyntaxHighlighter

Hint: NP_SyntaxHighlighter is outdated. Please use NP_GeSHi2 instead.

I wrote a plugin that make's possible to display source code or code snippets in your blog entries. The Syntax-Higlighter engine is based on the great PEAR::Text_Highlighter from Andrey Demenev. Currently PEAR::Text_Highlighter supports this language rules: PHP, XML, JAVASCRIPT, CSS, SQL, MYSQL, PYTHON, DIFF, DTD

The highlight rules are simply stored in XML-files, so they would be easy extensible. Documentation for the PEAR Class is available at http://blindman.dotgeek.org/projects/Text_Highlighter/doc/ and on http://pear.php.net/package/Text_Highlighter

General Plugin info
Author: Alfred 'Alf mit i' Scheibl
Current Version: 0.1
Download: NP_SyntaxHighlighter.phps (only plugin code)
NP_SyntaxHighlighter.zip (full package with PEAR)
Code: NP_SyntaxHighlighter_Code
Demo: -
Forum Thread: Forum thread

Install

I you have a well setuped PEAR Environment with installed Text_Highlighter on your Server you have to copy this file : http://www.alfmiti.net/download/NP_SyntaxHighlighter.phps otherwise you must download the whole package http://www.alfmiti.net/download/NP_SyntaxHighlighter.zip

If you use some other plugins that use line break conversions be aware that SyntaxHighlighter is the first plugin in order for well event listening. Otherwise the plugin couldn't format the source in a correct way.

This styles are used and you must add those to your css file! Code:

.highlight_php, .highlight_javascript, .highlight_xml, .highlight_css {
  background-color: #FFFAF0;
  border: 1px solid #120A8F;
  padding: 2px;
}

.hl-main {font-family: monospace; font-size:11px;}

.hl-default { color: #000000; }
.hl-code { color: #7f7f33; }
.hl-brackets { color: #993399; }
.hl-comment { color: #FF9900; }
.hl-quotes { color: #00007F; }
.hl-string { color: #CC0000; }
.hl-identifier { color: #000000; }
.hl-reserved { color: #006600;}
.hl-inlinedoc { color: #0000FF; }
.hl-var { color: #0000CC; }
.hl-url { color: #FF0000; }
.hl-special { color: #0000FF; }
.hl-number { color: #32CD32; }
.hl-inlinetags { color: #FF0000; }

Options

The NP_SyntaxHighlighter provides two render modes

.) Realtime rendering, The code snippets will every page call rendered. So you can easy update your code snippets, while there no endless html tags, in otherwise this can increase your pageloading time or use NP_Cache.

.) Parse and save The code snippets will one time parsed and saved. This decrease page load. But update your code will be difficult. Sometimes it could be usefull that you delete all snippets and paste new, to parse the section new. (You must remove the id attribut in the div container, otherwise the source will not parsed again). You see it's not so easy ..

Other options are use line numbers or not and also you can define the top-level tag of output. Default is <code> to automatically wrap lines.

Usage

To activate syntax highlighting you have to enlose your code-snippets with an div tag like that <div class=“highlight_php”> code </div>. Classname must be lowercase and begin always with “highlight_” following with the programming-language. (highlight_css, highlight_javascript and so on) For HTML Syntax Highlighting you must use “highlight_xml”

Todo

.) Better documentation and examples .) Make it possible to use PHP inbuild Syntaxhighlighter for PHP-code, this should be faster, than PEAR, but use those ugly not customizeable fonttags - I think should be your decision .) Maybe a alternative syntax in BBcode style for code section dedecting….

If you have any questions, remarks or improvements please post them at the nucleus forum http://forum.nucleuscms.org/viewtopic.php?t=4175

Alfred “Alf mit i” Scheibl

Plugin Review

NP_SyntaxHighlighter version 0.1 works with Nucleus CMS version 3.31. - 2007-11-28 kg

Hint: NP_SyntaxHighlighter has a really poor function. I would recommend NP_GeSHi2 instead.

:: Plugins ::

syntaxhighlighter.txt · Last modified: 2007/11/28 14:30 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki