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.
- 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 corresponding language):
- applescript: AppleScript
- actionscript3, as3: ActionScript3
- bash, shell, sh: Bash
- coldfusion, cf: ColdFusion
- cpp, c, cc, c++, h, hpp, h++: Cpp
- c#, c-sharp, csharp: CSharp
- css: CSS
- delphi, pascal, pas: Delphi or Pascal
- diff, patch: Diff
- erl, erlang: Erlang
- groovy: Groovy
- haxe, hx: Haxe
- java: Java
- jfx, javafx: JavaFX
- perl, pl: Perl
- php: PHP
- text, plain: Plain Text
- powershell, ps, posh: PowerShell
- py, python: Python
- ruby, rails, ror, rb: Ruby
- sass scss: SASS or SCSS
- scala: Scala
- sql: SQL
- swift: Apple Swift
- tap: Tap
- typescript, ts: Typescript
- vb, vbnet: VisalBasic
- xml, xhtml, xslt, html, plist: 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.