Copyright (c) Miguel Santirso
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfSyntaxHighlighter plugin
The sfSyntaxHighlighterPlugin adds automatically the javascript code needed to use the SyntaxHighlighter javascript library.
After installation, you will only need to enable the sfSyntaxHighlighterFilter in the applications you want.
Installation
1. Install the plugin
symfony plugin-install http://plugins.symfony-project.com/sfSyntaxHighlighterPlugin
2. Modify the filters.yml file of the application to enable the filter so that the plugin can add the Javascript code at the bottom of every page.
# generally, you will want to insert your own filters here
sf_syntax_highlighter_plugin:
class: sfSyntaxHighlighterFilter
3. Clear the cache
symfony cc
sfSyntaxHighlighterPlugin's basic usage
Using BBCode
The most simple option is to surround the code you want to highlight
with BBCode. For example:
...
[code="php"]
... some php code here ...
[/code]
or
...
[code lang="php"]
... some php code here ...
[/code]
Also, you can use three different BBCode tags that will be automatically recognised:
...
[code="php"]
... some php code here ...
[/code]
[sourcecode="css"]
... some css code here ...
[/sourcecode]
[source="c++"]
... some C++ code here ...
[/source]
Then, the plugin will highlight any code surrounded with that tags. Notice that you have to use one of the aliases for the desired programming languages (see Supported Highlighting Brushes at the bottom of this documentation).
Using the library's syntax
You can find the official documentation of the SyntaxHighlighter library in ("usage" section of their wiki)[http://code.google.com/p/syntaxhighlighter/wiki/Usage].
Place your code on the page and surround it with pre tag. Set name attribute to code and class attribute to one of the language aliases you wish to use.
<pre name="code" class="php">
... some code here ...
</pre>
Supported Highlighting Brushes
These are the currently supported highlighting brushes. The different aliases for every brush are between parenthesis.
- ActionScript 3.0 ('as','actionscript','ActionScript','as3','AS3')
- C++ ('cpp','c','c++')
- C# ('c#','c-sharp','csharp')
- CSS ('css')
- Delphi ('delphi','pascal')
- Java ('java')
- JavaScript ('js','jscript','javascript')
- PHP ('php')
- Python ('py','python')
- Ruby ('ruby','rails','ror')
- SQL ('sql')
- Visual Basic ('vb','vb.net')
- XML ('xml','xhtml','xslt','html','xhtml')
SyntaxHighlighter version
This plugin uses version 1.5.1 of SyntaxHighlighter.