diff options
author | andi <andi@splitbrain.org> | 2005-05-19 22:10:09 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-05-19 22:10:09 +0200 |
commit | ee20e7d16637625e900f518b6b46a61bfa30fe6e (patch) | |
tree | f621ec424429d9dc9732a059ec0ca4bf83aab566 /inc/parser | |
parent | 64f50cdbe21d0b9ca2165749301e6f553f9b8f02 (diff) | |
download | rpg-ee20e7d16637625e900f518b6b46a61bfa30fe6e.tar.gz rpg-ee20e7d16637625e900f518b6b46a61bfa30fe6e.tar.bz2 |
first attempt of syntax plugins
The first version of the new plugin system. Syntax plugins only yet. A very simple
example plugin called info (doing nothig useful yet) is included.
Missing Features
- Doku_Block_Handler needs work (doesn't honur plugins yet)
- there is no way to specify the order of plugins and other modes yet
- useful output from the info plugin
- bug testing and fixing
- code cleanup
- documentation
darcs-hash:20050519201009-9977f-f793dbfc6a39d8a9643b610927d93cd3288bdd6b.gz
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/handler.php | 19 | ||||
-rw-r--r-- | inc/parser/lexer.php | 7 | ||||
-rw-r--r-- | inc/parser/parser.php | 134 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 10 |
4 files changed, 129 insertions, 41 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php index e1ded183a..2379d60ff 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -54,6 +54,25 @@ class Doku_Handler { } return FALSE; } + + + /** + * Special plugin handler + * + * This handler is called for all modes starting with 'plugin_'. + * An additional parameter with the plugin name is passed + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + function plugin($match, $state, $pos, $pluginname){ + $data = array($match); + $plugin = null; + if(plugin_load('syntax',$pluginname,$plugin)){ + $data = $plugin->handle($match, $state, $pos, $handler); + } + $this->_addCall('plugin',array($pluginname,$data,$pos),$pos); + return TRUE; + } function base($match, $state, $pos) { switch ( $state ) { diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php index e7961932d..1cacaeed5 100644 --- a/inc/parser/lexer.php +++ b/inc/parser/lexer.php @@ -471,6 +471,13 @@ class Doku_Lexer { if (isset($this->_mode_handlers[$handler])) { $handler = $this->_mode_handlers[$handler]; } + // modes starting with plugin_ are all handled by the same + // handler but with an additional parameter + if(substr($handler,0,7)=='plugin_'){ + list($handler,$plugin) = split('_',$handler,2); + return $this->_parser->$handler($content, $is_match, $pos, $plugin); + } + return $this->_parser->$handler($content, $is_match, $pos); } diff --git a/inc/parser/parser.php b/inc/parser/parser.php index dd2b72aa0..87a29328c 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -5,6 +5,45 @@ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../') require_once DOKU_INC . 'inc/parser/lexer.php'; require_once DOKU_INC . 'inc/parser/handler.php'; + +/** + * Define various types of modes used by the parser - they are used to + * populate the list of modes another mode accepts + */ +global $PARSER_MODES; +$PARSER_MODES = array( + // containers are complex modes that can contain many other modes + // hr breaks the principle but they shouldn't be used in tables / lists + // so they are put here + 'container' => array('listblock','table','quote','hr'), + + // some mode are allowed inside the base mode only + 'baseonly' => array('header'), + + // modes for styling text -- footnote behaves similar to styling + 'formatting' => array('strong', 'emphasis', 'underline', 'monospace', + 'subscript', 'superscript', 'deleted', 'footnote'), + + // modes where the token is simply replaced - they can not contain any + // other modes + 'substition' => array('acronym','smiley','wordblock','entity', + 'camelcaselink', 'internallink','media', + 'externallink','linebreak','emaillink', + 'windowssharelink','filelink','notoc', + 'nocache','multiplyentity','quotes','rss'), + + // modes which have a start and end token but inside which + // no other modes should be applied + 'protected' => array('preformatted','code','file','php','html'), + + // inside this mode no wiki markup should be applied but lineendings + // and whitespace isn't preserved + 'disabled' => array('unformatted'), + + // used to mark paragraph boundaries + 'paragraphs' => array('eol') +); + //------------------------------------------------------------------- /** @@ -101,7 +140,7 @@ class Doku_Parser_Mode { var $Lexer; var $allowedModes = array(); - + // Called before any calls to connectTo function preConnect() {} @@ -120,15 +159,16 @@ class Doku_Parser_Mode { class Doku_Parser_Mode_Base extends Doku_Parser_Mode { function Doku_Parser_Mode_Base() { + global $PARSER_MODES; $this->allowedModes = array_merge ( - Doku_Parser_BlockContainers(), - Doku_Parser_BaseOnly(), - Doku_Parser_Paragraphs(), - Doku_Parser_Formatting(), - Doku_Parser_Substition(), - Doku_Parser_Protected(), - Doku_Parser_Disabled() + $PARSER_MODES['container'], + $PARSER_MODES['baseonly'], + $PARSER_MODES['paragraphs'], + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['protected'], + $PARSER_MODES['disabled'] ); } } @@ -137,13 +177,14 @@ class Doku_Parser_Mode_Base extends Doku_Parser_Mode { class Doku_Parser_Mode_Footnote extends Doku_Parser_Mode { function Doku_Parser_Mode_Footnote() { + global $PARSER_MODES; $this->allowedModes = array_merge ( - Doku_Parser_BlockContainers(), - Doku_Parser_Formatting(), - Doku_Parser_Substition(), - Doku_Parser_Protected(), - Doku_Parser_Disabled() + $PARSER_MODES['container'], + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['protected'], + $PARSER_MODES['disabled'] ); } @@ -237,7 +278,6 @@ class Doku_Parser_Mode_HR extends Doku_Parser_Mode { //------------------------------------------------------------------- class Doku_Parser_Mode_Formatting extends Doku_Parser_Mode { - var $type; var $formatting = array ( @@ -278,6 +318,7 @@ class Doku_Parser_Mode_Formatting extends Doku_Parser_Mode { ); function Doku_Parser_Mode_Formatting($type) { + global $PARSER_MODES; if ( !array_key_exists($type, $this->formatting) ) { trigger_error('Invalid formatting type '.$type, E_USER_WARNING); @@ -285,12 +326,18 @@ class Doku_Parser_Mode_Formatting extends Doku_Parser_Mode { $this->type = $type; + // formatting may contain other formatting but not it self + $modes = $PARSER_MODES['formatting']; + $key = array_search($type, $modes); + if ( is_int($key) ) { + unset($modes[$key]); + } + $this->allowedModes = array_merge ( - Doku_Parser_Formatting($type), - Doku_Parser_Substition(), - Doku_Parser_Disabled() + $modes, + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'] ); - } function connectTo($mode) { @@ -321,20 +368,16 @@ class Doku_Parser_Mode_Formatting extends Doku_Parser_Mode { class Doku_Parser_Mode_ListBlock extends Doku_Parser_Mode { function Doku_Parser_Mode_ListBlock() { + global $PARSER_MODES; $this->allowedModes = array_merge ( - Doku_Parser_Formatting(), - Doku_Parser_Substition(), - Doku_Parser_Disabled() + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'], + $PARSER_MODES['protected'] #XXX new ); - $this->allowedModes[] = 'footnote'; - $this->allowedModes[] = 'preformatted'; - $this->allowedModes[] = 'unformatted'; - $this->allowedModes[] = 'html'; - $this->allowedModes[] = 'php'; - $this->allowedModes[] = 'code'; - $this->allowedModes[] = 'file'; + // $this->allowedModes[] = 'footnote'; } function connectTo($mode) { @@ -355,15 +398,17 @@ class Doku_Parser_Mode_ListBlock extends Doku_Parser_Mode { class Doku_Parser_Mode_Table extends Doku_Parser_Mode { function Doku_Parser_Mode_Table() { + global $PARSER_MODES; $this->allowedModes = array_merge ( - Doku_Parser_Formatting(), - Doku_Parser_Substition(), - Doku_Parser_Disabled() + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'], + $PARSER_MODES['protected'] #XXX new ); - $this->allowedModes[] = 'footnote'; - $this->allowedModes[] = 'preformatted'; - $this->allowedModes[] = 'unformatted'; + #$this->allowedModes[] = 'footnote'; + #$this->allowedModes[] = 'preformatted'; + #$this->allowedModes[] = 'unformatted'; } function connectTo($mode) { @@ -473,15 +518,17 @@ class Doku_Parser_Mode_File extends Doku_Parser_Mode { class Doku_Parser_Mode_Quote extends Doku_Parser_Mode { function Doku_Parser_Mode_Quote() { + global $PARSER_MODES; $this->allowedModes = array_merge ( - Doku_Parser_Formatting(), - Doku_Parser_Substition(), - Doku_Parser_Disabled() + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'], + $PARSER_MODES['protected'] #XXX new ); - $this->allowedModes[] = 'footnote'; - $this->allowedModes[] = 'preformatted'; - $this->allowedModes[] = 'unformatted'; + #$this->allowedModes[] = 'footnote'; + #$this->allowedModes[] = 'preformatted'; + #$this->allowedModes[] = 'unformatted'; } function connectTo($mode) { @@ -774,9 +821,14 @@ class Doku_Parser_Mode_EmailLink extends Doku_Parser_Mode { } //------------------------------------------------------------------- +// +// XXX deprecated - replace by $PARSER_MODES +// // Help fns to keep mode lists - used to make it easier to populate // the list of modes another mode accepts +/* + // Can contain many other modes // E.g. a footnote can containing formatting etc. function Doku_Parser_BlockContainers() { @@ -848,6 +900,8 @@ function Doku_Parser_Disabled() { ); return $modes; } +*/ +// -------------------------------------------------------------------------- //Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index f9f6be1e6..b58c24435 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -19,6 +19,7 @@ if ( !defined('DOKU_TAB') ) { } require_once DOKU_INC . 'inc/parser/renderer.php'; +require_once DOKU_INC . 'inc/pluginutils.php'; /** * The Renderer @@ -41,7 +42,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { var $store = ''; - function document_start() { } @@ -57,6 +57,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= '</div>'.DOKU_LF; } } + + //handles plugin rendering + function plugin($name,$data){ + $plugin = null; + if(plugin_load('syntax',$name,$plugin)){ + $plugin->render('xhtml',$this,$data); + } + } function toc_open() { global $lang; |