Table of Contents
Code Prettifier Plugin
Compatible with DokuWiki
2015-08-10, 2016-06-26, 2017-02-19, 2018-04-22a
Syntax highlighting of source code snippets in wiki page using google-code-prettify (javascript module with CSS files)
Similar to highlightjs, jquery-syntax, syntaxhighlighter3, syntaxhighlighter4
Installation
Require PHP 7.0.x or later!
Search and install the plugin using the Extension Manager. Refer to plugin installation instructions.
Note: After updated to 2015-09-12 release, you can remove older “google-code-prettify” subfolder in this plugin directory.
<Code:txt> Test of text </Code>
<Code:css> <style> hello </style> </Code>
Feature
This plugin enable syntax highlighting of code snippets in your page using Javascript code prettifier (former “google-code-prettify”). This plugin package includes subset of Javascript code prettifier, they are separately licensed under the Apache License, Version 2.0
- You can configure Code Prettifier plugin to override DokuWiki built-in syntax
<code>
for code blocks. - you may use skin (css file) for code block.
Examples/Usage
- Enclose code snippets using
<Code>
and</Code>
tag to show it pretty-printed in wiki page. - Prettify module makes a best effort to guess the language but works best with C-like and HTML-like languages.
- To specify language hint for Prettify, you can use
<Code:ext>
(file extension, you must put it just after “Code:” keyword)<Code lang-ext>
option
- For example, use
<Code:css>
or<Code lang-css>
to specify that the code is Cascading Style Sheets (CSS). - use
linenums
ornolinenums
option to turn on/off line numbering. You can add a colon and the number to the end of the option, eg.linenums:12
to specify start line number. - If you want to add title for code block, you can specify it after
|
that will be shown just above the code box.
<Code:php linenums:1 |Example #1 Our first PHP script: //hello.php//> <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html> </Code>
Configuration and Settings
Config key | Description |
---|---|
override | override DokuWiki built-in syntax <code> for Code Blocks. |
linenums | enable line numbering implicitly. |
url_loader | url of prettify loader (default blank) obsoleted since 2015-09-12 release |
url_prettify_handlers | Base URL for prettify.js and optional language handler scripts ex: https://cdn.rawgit.com/google/code-prettify/master/src/ (default blank) available in 2015-09-12 release |
url_prettify_skins | Base URL for color theme for code-prettify (css) ex: https://cdn.rawgit.com/google/code-prettify/master/styles/ (default blank) available in 2015-09-12 release |
lang_handlers | additional langage handler (comma separated) |
skin | color theme/skin for code-prettify (CSS filename in code-prettify/styles/) |
Detail information of the Javascript code prettifier is available from:
This plugin package contains some skins those found in Prettify Themes Gallery. You may set one of following css filename in the skin
field.
- desert.css
- doxy.css
- sons-of-obsidian.css
- sunburst.css
Other color themes for Prettify will be found at http://jmblog.github.io/color-themes-for-google-code-prettify/
Development
Change Log from github repository
- update version (2023-09-16 09:43)
- Fix warning on access array offset on value of type null (2023-09-16 09:19)
- rewrite to prevent PHP8 E_Warnings (2023-09-15 05:40)
- update version (2023-08-29 13:47)
- update url of code-prettify (2023-08-29 13:40)
ToDo/Wish List
- Collapse/Expand Code Feature
- follow recent updates of Japascript code prettifier project
FAQ
Non-highlight code block
use <Code:none>
or <Code lang-none>
to prevent highlight code. Maybe useful to show error log output or console output.
<Code:none> This is not any kind of code. </Code>
Geshi options in DowkuWiki
DowkuWiki suppports some additional Geshi options for syntax highlighting
since its 2018-04-22 release (Greebo). The extra Geshi options are to be specified inside [
and ]
.
The code prettifier plugin should also recognize them, and following example will work fine for both DokuWiki original syntax and code prettifier plugin (except <code>
and <Code>
markup tag respectively).
<Code C [enable_line_numbers=1, start_line_numbers_at=42]> void main () { printf ("Hello World!"); exit 0; } </Code>
Known Bugs and Issues
Discussion
Using current dokuwiki theme and prettifyer with <Code linenums> does print a linenumber only on every fifth. line.
To solve just add
.prettyprint ol.linenums > li { list-style-type: decimal; }
to lib/plugins/codeprettify/all.css