plugin:code
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:code [2015-09-04 09:09] – 130.112.1.3 | plugin:code [2024-03-04 21:59] (current) – Aleksandr | ||
---|---|---|---|
Line 3: | Line 3: | ||
---- plugin ---- | ---- plugin ---- | ||
description: | description: | ||
- | author | + | author |
- | email : chris@jalakai.co.uk | + | email : chris@jalakai.co.uk, N/A |
type : syntax | type : syntax | ||
- | lastupdate : 2008-08-13 | + | lastupdate : 2020-07-28 |
- | compatible : 2005-09-22 and later | + | compatible : Hogfather |
depends | depends | ||
conflicts | conflicts | ||
Line 13: | Line 13: | ||
tags : code, syntaxhighlight | tags : code, syntaxhighlight | ||
- | downloadurl: | + | downloadurl: |
---- | ---- | ||
- | This [[plugin]] replaces the current DokuWiki handlers for '' | + | This plugin replaces the current DokuWiki handlers for '' |
This plugin was inspired by [[bug> | This plugin was inspired by [[bug> | ||
Line 24: | Line 24: | ||
---- | ---- | ||
- | See the plugin in action [[http:// | + | See the plugin in action [[http:// |
===== Syntax ===== | ===== Syntax ===== | ||
Line 37: | Line 37: | ||
Supported parameters (fileextensions given if differ from lang): | Supported parameters (fileextensions given if differ from lang): | ||
- | FIXME - this list is incomplete, please add any supported language | + | FIXME - this list is incomplete, please add any supported language |
A full list of supported languages can be found [[http:// | A full list of supported languages can be found [[http:// | ||
Line 71: | Line 71: | ||
===== Installation ===== | ===== Installation ===== | ||
+ | Search and install the plugin using the [[plugin: | ||
- | Plugin sources: [[http://dokuwiki.jalakai.co.uk/ | + | Plugin sources: [[https://github.com/lgnap/dokuwiki-plugin-code/ |
- | Download the source to your plugin folder, '' | ||
- | |||
- | The folder will contain: | ||
- | style.css | ||
- | syntax/ | ||
- | syntax/ | ||
- | syntax/ | ||
- | |||
- | The plugin is now installed. | ||
===== Details ===== | ===== Details ===== | ||
- | The plugin consists of three files, two (almost identical) syntax plugins files, [[# | + | The plugin consists of three files, two (almost identical) syntax plugins files, [[# |
- | ==== syntax/ | + | |
- | <code php code.php> | ||
- | <?php | ||
- | /** | ||
- | * Code Plugin: replaces DokuWiki' | ||
- | * | ||
- | * Syntax: | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | * | ||
- | * if no title is provided will render as native DokuWiki code syntax mode, e.g. | ||
- | | ||
- | * | ||
- | * if title is provide will render as follows | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | * | ||
- | * @license | ||
- | * @author | ||
- | */ | ||
- | |||
- | if(!defined(' | ||
- | |||
- | /** | ||
- | * All DokuWiki plugins to extend the parser/ | ||
- | * need to inherit from this class | ||
- | */ | ||
- | class syntax_plugin_code_code extends DokuWiki_Syntax_Plugin { | ||
- | |||
- | var $syntax = ""; | ||
- | |||
- | /** | ||
- | * return some info | ||
- | */ | ||
- | function getInfo(){ | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | ' | ||
- | ); | ||
- | } | ||
- | |||
- | function getType(){ return ' | ||
- | function getPType(){ return ' | ||
- | |||
- | // must return a number lower than returned by native ' | ||
- | function getSort(){ return 195; } | ||
- | |||
- | /** | ||
- | * Connect pattern to lexer | ||
- | */ | ||
- | function connectTo($mode) { | ||
- | $this-> | ||
- | } | ||
- | |||
- | function postConnect() { | ||
- | $this-> | ||
- | } | ||
- | |||
- | /** | ||
- | * Handle the match | ||
- | */ | ||
- | function handle($match, | ||
- | |||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER: | ||
- | $this-> | ||
- | return false; | ||
- | |||
- | case DOKU_LEXER_UNMATCHED: | ||
- | // will include everything from <code ... to ... </code > | ||
- | // e.g. ... [lang] [|title] > [content] | ||
- | | ||
- | | ||
- | |||
- | if ($this-> | ||
- | $lang = trim($lang); | ||
- | if ($lang == ' | ||
- | if (!$lang) $lang = NULL; | ||
- | } else { | ||
- | $lang = NULL; | ||
- | } | ||
- | |||
- | | ||
- | } | ||
- | return false; | ||
- | } | ||
- | |||
- | /** | ||
- | * Create output | ||
- | */ | ||
- | function render($mode, | ||
- | |||
- | if (count($data) == 4) { | ||
- | list($syntax, | ||
- | |||
- | if($mode == ' | ||
- | if ($title) $renderer-> | ||
- | if ($syntax == ' | ||
- | if ($title) $renderer-> | ||
- | } else { | ||
- | if ($syntax == ' | ||
- | } | ||
- | |||
- | return true; | ||
- | } | ||
- | return false; | ||
- | } | ||
- | } | ||
- | |||
- | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
- | </ | ||
- | |||
- | ==== syntax/ | ||
- | |||
- | <code php file.php> | ||
- | <?php | ||
- | /** | ||
- | * File Plugin: replaces DokuWiki' | ||
- | * | ||
- | * Syntax: | ||
- | | ||
- | | ||
- | * | ||
- | * if no title is provided will render as native DokuWiki code syntax mode, e.g. | ||
- | | ||
- | * | ||
- | * if title is provide will render as follows | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | * | ||
- | * @license | ||
- | * @author | ||
- | */ | ||
- | |||
- | if(!defined(' | ||
- | |||
- | /** | ||
- | * All DokuWiki plugins to extend the parser/ | ||
- | * need to inherit from this class | ||
- | */ | ||
- | class syntax_plugin_code_file extends DokuWiki_Syntax_Plugin { | ||
- | |||
- | var $syntax = ""; | ||
- | |||
- | /** | ||
- | * return some info | ||
- | */ | ||
- | function getInfo(){ | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | ' | ||
- | ); | ||
- | } | ||
- | |||
- | function getType(){ return ' | ||
- | function getPType(){ return ' | ||
- | |||
- | // must return a number lower than returned by native ' | ||
- | function getSort(){ return 194; } | ||
- | |||
- | /** | ||
- | * Connect pattern to lexer | ||
- | */ | ||
- | function connectTo($mode) { | ||
- | $this-> | ||
- | } | ||
- | |||
- | function postConnect() { | ||
- | $this-> | ||
- | } | ||
- | |||
- | /** | ||
- | * Handle the match | ||
- | */ | ||
- | function handle($match, | ||
- | |||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER: | ||
- | $this-> | ||
- | return false; | ||
- | |||
- | case DOKU_LEXER_UNMATCHED: | ||
- | // will include everything from <code ... to ... </code > | ||
- | // e.g. ... [lang] [|title] > [content] | ||
- | list($attr, $content) = preg_split('/>/ | ||
- | list($lang, $title) = preg_split('/ | ||
- | |||
- | if ($this-> | ||
- | $lang = trim($lang); | ||
- | if ($lang == ' | ||
- | if (!$lang) $lang = NULL; | ||
- | } else { | ||
- | $lang = NULL; | ||
- | } | ||
- | |||
- | return array($this-> | ||
- | } | ||
- | return false; | ||
- | } | ||
- | |||
- | /** | ||
- | * Create output | ||
- | */ | ||
- | function render($mode, | ||
- | |||
- | if (count($data) == 4) { | ||
- | list($syntax, | ||
- | |||
- | if($mode == ' | ||
- | if ($title) $renderer-> | ||
- | if ($syntax == ' | ||
- | if ($title) $renderer-> | ||
- | } else { | ||
- | if ($syntax == ' | ||
- | } | ||
- | |||
- | return true; | ||
- | } | ||
- | return false; | ||
- | } | ||
- | } | ||
- | |||
- | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
- | </ | ||
- | |||
- | |||
- | ==== style.css ==== | ||
- | |||
- | These may be modified to suit your own requirements. | ||
- | |||
- | <code css style.css> | ||
- | /* | ||
- | * code plugin extension - style additions | ||
- | * | ||
- | * @author | ||
- | * @link http:// | ||
- | */ | ||
- | |||
- | /* layout */ | ||
- | div.code, div.file { | ||
- | width: 92%; | ||
- | margin: 1em auto; | ||
- | border: 1px solid; | ||
- | padding: 4px; | ||
- | } | ||
- | |||
- | div.code p, div.file p { | ||
- | font-size: 90%; | ||
- | margin: 0; | ||
- | padding: 2px; | ||
- | } | ||
- | |||
- | div.code pre.code, div.file pre.file { | ||
- | margin: 4px 0 0 0; | ||
- | } | ||
- | |||
- | /* colours */ | ||
- | div.code { | ||
- | border-color: | ||
- | background: #e4ecf8; | ||
- | } | ||
- | |||
- | div.code p { | ||
- | background: #cad0ee; | ||
- | } | ||
- | |||
- | div.file { | ||
- | border-color: | ||
- | background: #f8ece4; | ||
- | } | ||
- | |||
- | div.file p { | ||
- | background: #eed0ca; | ||
- | } | ||
- | |||
- | div.file pre.file { | ||
- | background: #fdf4ec; | ||
- | border-color: | ||
- | } | ||
- | |||
- | /* end code plugin style additions */ | ||
- | </ | ||
===== Revision History ===== | ===== Revision History ===== | ||
+ | * 2020-07-29 --- Fix fatal issue about function signatures, and put code on github | ||
* 2008-08-13 --- Update plugin URL | * 2008-08-13 --- Update plugin URL | ||
* --- Add support for unknown render formats (e.g. ODT plugin) | * --- Add support for unknown render formats (e.g. ODT plugin) | ||
Line 405: | Line 99: | ||
===== Discussion ===== | ===== Discussion ===== | ||
+ | |||
+ | doesn' | ||
+ | |||
+ | --- // | ||
+ | ---- | ||
What would be nice is if it automatically generates a title based on the language attribute set if no title is explicitly set. --- // | What would be nice is if it automatically generates a title based on the language attribute set if no title is explicitly set. --- // |
plugin/code.1441350585.txt.gz · Last modified: 2015-09-04 09:09 by 130.112.1.3