Posting source code (and syntax highlighting) in the forum is a very common requirement, and due to various limitations, not an easy thing to do, especially when you take into account user roles restrictions for using many HTML tags.
GD bbPress Toolbox Pro 4.0 adds a new BBCode for posting source code called SCODE. This BBCode has several attributes:
- lang: language of the source code to use for syntax highlighting. Default: text.
- line: number to use as a start for line numbering: Default: 1.
- gutter: should highlight show gutter with a line number. Default: true.
- collapse: should the source code block be collapsed/hidden on load: Default: false.
- class: additional CSS class names to add to the source code block. Default: ”.
- highlight: number of lines to highlight in the source code. Default: ”. This should be a string with a number of lines comma separated.
You can post any sort of source code, but for syntax highlighting language (lang attribute) you can use one of these values (with their correcponding language):
- applescript: AppleScript
- actionscript3, as3: ActionScript3
- bash, shell: Bash
- coldfusion, cf: ColdFusion
- cpp, c: Cpp
- c#, c-sharp, csharp: CSharp
- css: CSS
- delphi, pascal: Delphi or Pascal
- diff, patch, pas: Diff
- erl, erlang: Erlang
- groovy: Groovy
- java: Java
- jfx, javafx: JavaFX
- perl, pl: Perl
- php: PHP
- text, plain: Plain Text
- py, python: Python
- ruby, rails, ror, rb: Ruby
- sass scss: SASS or SCSS
- scala: Scala
- sql: SQL
- swift: Apple Swift
- vb, vbnet: VisalBasic
- xml, xhtml, xslt, html: XML, HTML
Here is the example:
This will should source code in PHP, starting from line 4 and lines 5 and 9 are highlighted. Here it is:
Plugin supports several color schemes for syntax highlighting, and you can choose the theme for that in the plugin settings on BBCodes panel.