10cecf9d5Sandi<?php 25c2aad12SAndreas Gohr 3cbb44eabSAndreas Gohruse dokuwiki\Extension\Event; 4e1d9dcc8SAndreas Gohruse dokuwiki\Extension\SyntaxPlugin; 5be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\Block; 6be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\CallWriter; 7be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\CallWriterInterface; 8be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\Lists; 9be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\Nest; 10be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\Preformatted; 11be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\Quote; 12be906b56SAndreas Gohruse dokuwiki\Parsing\Handler\Table; 135c2aad12SAndreas Gohr 148b1b81beSAndreas Gohr/** 158b1b81beSAndreas Gohr * Class Doku_Handler 168b1b81beSAndreas Gohr */ 170cecf9d5Sandiclass Doku_Handler { 188b1b81beSAndreas Gohr /** @var CallWriterInterface */ 198b1b81beSAndreas Gohr protected $callWriter = null; 200cecf9d5Sandi 218b1b81beSAndreas Gohr /** @var array The current CallWriter will write directly to this list of calls, Parser reads it */ 228b1b81beSAndreas Gohr public $calls = array(); 230cecf9d5Sandi 248b1b81beSAndreas Gohr /** @var array internal status holders for some modes */ 258b1b81beSAndreas Gohr protected $status = array( 2644881bd0Shenning.noren 'section' => false, 27e950d12fSChristopher Smith 'doublequote' => 0, 280cecf9d5Sandi ); 290cecf9d5Sandi 308b1b81beSAndreas Gohr /** @var bool should blocks be rewritten? FIXME seems to always be true */ 318b1b81beSAndreas Gohr protected $rewriteBlocks = true; 32b7c441b9SHarry Fuecks 338b1b81beSAndreas Gohr /** 34*ac1d8211SAndreas Gohr * @var bool are we in a footnote already? 35*ac1d8211SAndreas Gohr */ 36*ac1d8211SAndreas Gohr protected $footnote; 37*ac1d8211SAndreas Gohr 38*ac1d8211SAndreas Gohr /** 398b1b81beSAndreas Gohr * Doku_Handler constructor. 408b1b81beSAndreas Gohr */ 41e1cdd96cSAndreas Gohr public function __construct() { 428b1b81beSAndreas Gohr $this->callWriter = new CallWriter($this); 430cecf9d5Sandi } 440cecf9d5Sandi 45276820f7SScrutinizer Auto-Fixer /** 468b1b81beSAndreas Gohr * Add a new call by passing it to the current CallWriter 478b1b81beSAndreas Gohr * 488b1b81beSAndreas Gohr * @param string $handler handler method name (see mode handlers below) 498b1b81beSAndreas Gohr * @param mixed $args arguments for this call 508b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 51276820f7SScrutinizer Auto-Fixer */ 5231c0895aSAndreas Gohr public function addCall($handler, $args, $pos) { 530cecf9d5Sandi $call = array($handler,$args, $pos); 548b1b81beSAndreas Gohr $this->callWriter->writeCall($call); 550cecf9d5Sandi } 560cecf9d5Sandi 57533aca44SAndreas Gohr /** 58533aca44SAndreas Gohr * Accessor for the current CallWriter 59533aca44SAndreas Gohr * 60533aca44SAndreas Gohr * @return CallWriterInterface 61533aca44SAndreas Gohr */ 62533aca44SAndreas Gohr public function getCallWriter() { 63533aca44SAndreas Gohr return $this->callWriter; 64533aca44SAndreas Gohr } 65533aca44SAndreas Gohr 66533aca44SAndreas Gohr /** 67533aca44SAndreas Gohr * Set a new CallWriter 68533aca44SAndreas Gohr * 69533aca44SAndreas Gohr * @param CallWriterInterface $callWriter 70533aca44SAndreas Gohr */ 71533aca44SAndreas Gohr public function setCallWriter($callWriter) { 72533aca44SAndreas Gohr $this->callWriter = $callWriter; 73533aca44SAndreas Gohr } 74533aca44SAndreas Gohr 75eb33b670SAndreas Gohr /** 76eb33b670SAndreas Gohr * Return the current internal status of the given name 77eb33b670SAndreas Gohr * 78eb33b670SAndreas Gohr * @param string $status 79eb33b670SAndreas Gohr * @return mixed|null 80eb33b670SAndreas Gohr */ 81eb33b670SAndreas Gohr public function getStatus($status) { 82eb33b670SAndreas Gohr if (!isset($this->status[$status])) return null; 83eb33b670SAndreas Gohr return $this->status[$status]; 84eb33b670SAndreas Gohr } 85eb33b670SAndreas Gohr 86eb33b670SAndreas Gohr /** 87eb33b670SAndreas Gohr * Set a new internal status 88eb33b670SAndreas Gohr * 89eb33b670SAndreas Gohr * @param string $status 90eb33b670SAndreas Gohr * @param mixed $value 91eb33b670SAndreas Gohr */ 92eb33b670SAndreas Gohr public function setStatus($status, $value) { 93eb33b670SAndreas Gohr $this->status[$status] = $value; 94eb33b670SAndreas Gohr } 95eb33b670SAndreas Gohr 9631c0895aSAndreas Gohr /** @deprecated 2019-10-31 use addCall() instead */ 9731c0895aSAndreas Gohr public function _addCall($handler, $args, $pos) { 9831c0895aSAndreas Gohr dbg_deprecated('addCall'); 9931c0895aSAndreas Gohr $this->addCall($handler, $args, $pos); 10031c0895aSAndreas Gohr } 10131c0895aSAndreas Gohr 1028b1b81beSAndreas Gohr /** 1038b1b81beSAndreas Gohr * Similar to addCall, but adds a plugin call 1048b1b81beSAndreas Gohr * 1058b1b81beSAndreas Gohr * @param string $plugin name of the plugin 1068b1b81beSAndreas Gohr * @param mixed $args arguments for this call 1078b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 1088b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 1098b1b81beSAndreas Gohr * @param string $match matched syntax 1108b1b81beSAndreas Gohr */ 111767b83f9SAndreas Gohr public function addPluginCall($plugin, $args, $state, $pos, $match) { 11282d61635Spierre.spring $call = array('plugin',array($plugin, $args, $state, $match), $pos); 1138b1b81beSAndreas Gohr $this->callWriter->writeCall($call); 11404ebd214Schris } 11504ebd214Schris 1168b1b81beSAndreas Gohr /** 1178b1b81beSAndreas Gohr * Finishes handling 1188b1b81beSAndreas Gohr * 1198b1b81beSAndreas Gohr * Called from the parser. Calls finalise() on the call writer, closes open 1208b1b81beSAndreas Gohr * sections, rewrites blocks and adds document_start and document_end calls. 1218b1b81beSAndreas Gohr * 1228b1b81beSAndreas Gohr * @triggers PARSER_HANDLER_DONE 1238b1b81beSAndreas Gohr */ 1248b1b81beSAndreas Gohr public function finalize(){ 1258b1b81beSAndreas Gohr $this->callWriter->finalise(); 126f4f02a0fSchris 127e1c10e4dSchris if ( $this->status['section'] ) { 128e1c10e4dSchris $last_call = end($this->calls); 129e1c10e4dSchris array_push($this->calls,array('section_close',array(), $last_call[2])); 1300cecf9d5Sandi } 1310cecf9d5Sandi 132b7c441b9SHarry Fuecks if ( $this->rewriteBlocks ) { 1335c2aad12SAndreas Gohr $B = new Block(); 1340cecf9d5Sandi $this->calls = $B->process($this->calls); 135b7c441b9SHarry Fuecks } 136e0ad864eSchris 137cbb44eabSAndreas Gohr Event::createAndTrigger('PARSER_HANDLER_DONE',$this); 1380cecf9d5Sandi 1390cecf9d5Sandi array_unshift($this->calls,array('document_start',array(),0)); 1400cecf9d5Sandi $last_call = end($this->calls); 1410cecf9d5Sandi array_push($this->calls,array('document_end',array(),$last_call[2])); 1420cecf9d5Sandi } 1430cecf9d5Sandi 1449e491c01SAndreas Gohr /** 1459e491c01SAndreas Gohr * fetch the current call and advance the pointer to the next one 1469e491c01SAndreas Gohr * 1478b1b81beSAndreas Gohr * @fixme seems to be unused? 1489e491c01SAndreas Gohr * @return bool|mixed 1499e491c01SAndreas Gohr */ 1508b1b81beSAndreas Gohr public function fetch() { 1519e491c01SAndreas Gohr $call = current($this->calls); 1529e491c01SAndreas Gohr if($call !== false) { 1539e491c01SAndreas Gohr next($this->calls); //advance the pointer 1549e491c01SAndreas Gohr return $call; 1550cecf9d5Sandi } 15644881bd0Shenning.noren return false; 1570cecf9d5Sandi } 158ee20e7d1Sandi 159ee20e7d1Sandi 160ee20e7d1Sandi /** 161e2d88156SLarsDW223 * Internal function for parsing highlight options. 162e2d88156SLarsDW223 * $options is parsed for key value pairs separated by commas. 163e2d88156SLarsDW223 * A value might also be missing in which case the value will simple 164e2d88156SLarsDW223 * be set to true. Commas in strings are ignored, e.g. option="4,56" 165e2d88156SLarsDW223 * will work as expected and will only create one entry. 166e2d88156SLarsDW223 * 16754f741e8SAndreas Gohr * @param string $options space separated list of key-value pairs, 168e2d88156SLarsDW223 * e.g. option1=123, option2="456" 169e2d88156SLarsDW223 * @return array|null Array of key-value pairs $array['key'] = 'value'; 170e2d88156SLarsDW223 * or null if no entries found 171e2d88156SLarsDW223 */ 172e2d88156SLarsDW223 protected function parse_highlight_options($options) { 173e2d88156SLarsDW223 $result = array(); 17454f741e8SAndreas Gohr preg_match_all('/(\w+(?:="[^"]*"))|(\w+(?:=[^\s]*))|(\w+[^=\s\]])(?:\s*)/', $options, $matches, PREG_SET_ORDER); 175e2d88156SLarsDW223 foreach ($matches as $match) { 176e2d88156SLarsDW223 $equal_sign = strpos($match [0], '='); 177e2d88156SLarsDW223 if ($equal_sign === false) { 17854f741e8SAndreas Gohr $key = trim($match[0]); 179e2d88156SLarsDW223 $result [$key] = 1; 180e2d88156SLarsDW223 } else { 181e2d88156SLarsDW223 $key = substr($match[0], 0, $equal_sign); 182e2d88156SLarsDW223 $value = substr($match[0], $equal_sign+1); 183e2d88156SLarsDW223 $value = trim($value, '"'); 184e2d88156SLarsDW223 if (strlen($value) > 0) { 185e2d88156SLarsDW223 $result [$key] = $value; 186e2d88156SLarsDW223 } else { 187e2d88156SLarsDW223 $result [$key] = 1; 188e2d88156SLarsDW223 } 189e2d88156SLarsDW223 } 190e2d88156SLarsDW223 } 191e2d88156SLarsDW223 192e2d88156SLarsDW223 // Check for supported options 193e2d88156SLarsDW223 $result = array_intersect_key( 194e2d88156SLarsDW223 $result, 195e2d88156SLarsDW223 array_flip(array( 196e2d88156SLarsDW223 'enable_line_numbers', 197e2d88156SLarsDW223 'start_line_numbers_at', 198e2d88156SLarsDW223 'highlight_lines_extra', 199e2d88156SLarsDW223 'enable_keyword_links') 200e2d88156SLarsDW223 ) 201e2d88156SLarsDW223 ); 202e2d88156SLarsDW223 203e2d88156SLarsDW223 // Sanitize values 204e2d88156SLarsDW223 if(isset($result['enable_line_numbers'])) { 20554f741e8SAndreas Gohr if($result['enable_line_numbers'] === 'false') { 20654f741e8SAndreas Gohr $result['enable_line_numbers'] = false; 20754f741e8SAndreas Gohr } 208e2d88156SLarsDW223 $result['enable_line_numbers'] = (bool) $result['enable_line_numbers']; 209e2d88156SLarsDW223 } 210e2d88156SLarsDW223 if(isset($result['highlight_lines_extra'])) { 211e2d88156SLarsDW223 $result['highlight_lines_extra'] = array_map('intval', explode(',', $result['highlight_lines_extra'])); 212e2d88156SLarsDW223 $result['highlight_lines_extra'] = array_filter($result['highlight_lines_extra']); 213e2d88156SLarsDW223 $result['highlight_lines_extra'] = array_unique($result['highlight_lines_extra']); 214e2d88156SLarsDW223 } 215e2d88156SLarsDW223 if(isset($result['start_line_numbers_at'])) { 216e2d88156SLarsDW223 $result['start_line_numbers_at'] = (int) $result['start_line_numbers_at']; 217e2d88156SLarsDW223 } 218e2d88156SLarsDW223 if(isset($result['enable_keyword_links'])) { 21954f741e8SAndreas Gohr if($result['enable_keyword_links'] === 'false') { 22054f741e8SAndreas Gohr $result['enable_keyword_links'] = false; 22154f741e8SAndreas Gohr } 22254f741e8SAndreas Gohr $result['enable_keyword_links'] = (bool) $result['enable_keyword_links']; 223e2d88156SLarsDW223 } 224e2d88156SLarsDW223 if (count($result) == 0) { 225e2d88156SLarsDW223 return null; 226e2d88156SLarsDW223 } 227e2d88156SLarsDW223 228e2d88156SLarsDW223 return $result; 229e2d88156SLarsDW223 } 230e2d88156SLarsDW223 2318b1b81beSAndreas Gohr /** 2328b1b81beSAndreas Gohr * Simplifies handling for the formatting tags which all behave the same 2338b1b81beSAndreas Gohr * 2348b1b81beSAndreas Gohr * @param string $match matched syntax 2358b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 2368b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 2378b1b81beSAndreas Gohr * @param string $name actual mode name 2388b1b81beSAndreas Gohr */ 2398b1b81beSAndreas Gohr protected function nestingTag($match, $state, $pos, $name) { 2408b1b81beSAndreas Gohr switch ( $state ) { 2418b1b81beSAndreas Gohr case DOKU_LEXER_ENTER: 2428b1b81beSAndreas Gohr $this->addCall($name.'_open', array(), $pos); 2438b1b81beSAndreas Gohr break; 2448b1b81beSAndreas Gohr case DOKU_LEXER_EXIT: 2458b1b81beSAndreas Gohr $this->addCall($name.'_close', array(), $pos); 2468b1b81beSAndreas Gohr break; 2478b1b81beSAndreas Gohr case DOKU_LEXER_UNMATCHED: 2488b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 2498b1b81beSAndreas Gohr break; 2508b1b81beSAndreas Gohr } 2518b1b81beSAndreas Gohr } 2528b1b81beSAndreas Gohr 2538b1b81beSAndreas Gohr 2548b1b81beSAndreas Gohr /** 2558b1b81beSAndreas Gohr * The following methods define the handlers for the different Syntax modes 2568b1b81beSAndreas Gohr * 257be906b56SAndreas Gohr * The handlers are called from dokuwiki\Parsing\Lexer\Lexer\invokeParser() 2588b1b81beSAndreas Gohr * 2598b1b81beSAndreas Gohr * @todo it might make sense to move these into their own class or merge them with the 2608b1b81beSAndreas Gohr * ParserMode classes some time. 2618b1b81beSAndreas Gohr */ 2628b1b81beSAndreas Gohr // region mode handlers 2638b1b81beSAndreas Gohr 2648b1b81beSAndreas Gohr /** 2658b1b81beSAndreas Gohr * Special plugin handler 2668b1b81beSAndreas Gohr * 2678b1b81beSAndreas Gohr * This handler is called for all modes starting with 'plugin_'. 2688b1b81beSAndreas Gohr * An additional parameter with the plugin name is passed. The plugin's handle() 2698b1b81beSAndreas Gohr * method is called here 2708b1b81beSAndreas Gohr * 2718b1b81beSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2728b1b81beSAndreas Gohr * 2738b1b81beSAndreas Gohr * @param string $match matched syntax 2748b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 2758b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 2768b1b81beSAndreas Gohr * @param string $pluginname name of the plugin 2778b1b81beSAndreas Gohr * @return bool mode handled? 2788b1b81beSAndreas Gohr */ 2798b1b81beSAndreas Gohr public function plugin($match, $state, $pos, $pluginname){ 2808b1b81beSAndreas Gohr $data = array($match); 281e1d9dcc8SAndreas Gohr /** @var SyntaxPlugin $plugin */ 2828b1b81beSAndreas Gohr $plugin = plugin_load('syntax',$pluginname); 2838b1b81beSAndreas Gohr if($plugin != null){ 2848b1b81beSAndreas Gohr $data = $plugin->handle($match, $state, $pos, $this); 2858b1b81beSAndreas Gohr } 2868b1b81beSAndreas Gohr if ($data !== false) { 2878b1b81beSAndreas Gohr $this->addPluginCall($pluginname,$data,$state,$pos,$match); 2888b1b81beSAndreas Gohr } 2898b1b81beSAndreas Gohr return true; 2908b1b81beSAndreas Gohr } 2918b1b81beSAndreas Gohr 2928b1b81beSAndreas Gohr /** 2938b1b81beSAndreas Gohr * @param string $match matched syntax 2948b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 2958b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 2968b1b81beSAndreas Gohr * @return bool mode handled? 2978b1b81beSAndreas Gohr */ 2988b1b81beSAndreas Gohr public function base($match, $state, $pos) { 2998b1b81beSAndreas Gohr switch ( $state ) { 3008b1b81beSAndreas Gohr case DOKU_LEXER_UNMATCHED: 3018b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 3028b1b81beSAndreas Gohr return true; 3038b1b81beSAndreas Gohr break; 3048b1b81beSAndreas Gohr } 3058b1b81beSAndreas Gohr return false; 3068b1b81beSAndreas Gohr } 3078b1b81beSAndreas Gohr 3088b1b81beSAndreas Gohr /** 3098b1b81beSAndreas Gohr * @param string $match matched syntax 3108b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3118b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3128b1b81beSAndreas Gohr * @return bool mode handled? 3138b1b81beSAndreas Gohr */ 3148b1b81beSAndreas Gohr public function header($match, $state, $pos) { 3158b1b81beSAndreas Gohr // get level and title 3168b1b81beSAndreas Gohr $title = trim($match); 3178b1b81beSAndreas Gohr $level = 7 - strspn($title,'='); 3188b1b81beSAndreas Gohr if($level < 1) $level = 1; 3198b1b81beSAndreas Gohr $title = trim($title,'='); 3208b1b81beSAndreas Gohr $title = trim($title); 3218b1b81beSAndreas Gohr 3228b1b81beSAndreas Gohr if ($this->status['section']) $this->addCall('section_close', array(), $pos); 3238b1b81beSAndreas Gohr 3248b1b81beSAndreas Gohr $this->addCall('header', array($title, $level, $pos), $pos); 3258b1b81beSAndreas Gohr 3268b1b81beSAndreas Gohr $this->addCall('section_open', array($level), $pos); 3278b1b81beSAndreas Gohr $this->status['section'] = true; 3288b1b81beSAndreas Gohr return true; 3298b1b81beSAndreas Gohr } 3308b1b81beSAndreas Gohr 3318b1b81beSAndreas Gohr /** 3328b1b81beSAndreas Gohr * @param string $match matched syntax 3338b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3348b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3358b1b81beSAndreas Gohr * @return bool mode handled? 3368b1b81beSAndreas Gohr */ 3378b1b81beSAndreas Gohr public function notoc($match, $state, $pos) { 3388b1b81beSAndreas Gohr $this->addCall('notoc', array(), $pos); 3398b1b81beSAndreas Gohr return true; 3408b1b81beSAndreas Gohr } 3418b1b81beSAndreas Gohr 3428b1b81beSAndreas Gohr /** 3438b1b81beSAndreas Gohr * @param string $match matched syntax 3448b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3458b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3468b1b81beSAndreas Gohr * @return bool mode handled? 3478b1b81beSAndreas Gohr */ 3488b1b81beSAndreas Gohr public function nocache($match, $state, $pos) { 3498b1b81beSAndreas Gohr $this->addCall('nocache', array(), $pos); 3508b1b81beSAndreas Gohr return true; 3518b1b81beSAndreas Gohr } 3528b1b81beSAndreas Gohr 3538b1b81beSAndreas Gohr /** 3548b1b81beSAndreas Gohr * @param string $match matched syntax 3558b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3568b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3578b1b81beSAndreas Gohr * @return bool mode handled? 3588b1b81beSAndreas Gohr */ 3598b1b81beSAndreas Gohr public function linebreak($match, $state, $pos) { 3608b1b81beSAndreas Gohr $this->addCall('linebreak', array(), $pos); 3618b1b81beSAndreas Gohr return true; 3628b1b81beSAndreas Gohr } 3638b1b81beSAndreas Gohr 3648b1b81beSAndreas Gohr /** 3658b1b81beSAndreas Gohr * @param string $match matched syntax 3668b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3678b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3688b1b81beSAndreas Gohr * @return bool mode handled? 3698b1b81beSAndreas Gohr */ 3708b1b81beSAndreas Gohr public function eol($match, $state, $pos) { 3718b1b81beSAndreas Gohr $this->addCall('eol', array(), $pos); 3728b1b81beSAndreas Gohr return true; 3738b1b81beSAndreas Gohr } 3748b1b81beSAndreas Gohr 3758b1b81beSAndreas Gohr /** 3768b1b81beSAndreas Gohr * @param string $match matched syntax 3778b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3788b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3798b1b81beSAndreas Gohr * @return bool mode handled? 3808b1b81beSAndreas Gohr */ 3818b1b81beSAndreas Gohr public function hr($match, $state, $pos) { 3828b1b81beSAndreas Gohr $this->addCall('hr', array(), $pos); 3838b1b81beSAndreas Gohr return true; 3848b1b81beSAndreas Gohr } 3858b1b81beSAndreas Gohr 3868b1b81beSAndreas Gohr /** 3878b1b81beSAndreas Gohr * @param string $match matched syntax 3888b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 3898b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 3908b1b81beSAndreas Gohr * @return bool mode handled? 3918b1b81beSAndreas Gohr */ 3928b1b81beSAndreas Gohr public function strong($match, $state, $pos) { 3938b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'strong'); 3948b1b81beSAndreas Gohr return true; 3958b1b81beSAndreas Gohr } 3968b1b81beSAndreas Gohr 3978b1b81beSAndreas Gohr /** 3988b1b81beSAndreas Gohr * @param string $match matched syntax 3998b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4008b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4018b1b81beSAndreas Gohr * @return bool mode handled? 4028b1b81beSAndreas Gohr */ 4038b1b81beSAndreas Gohr public function emphasis($match, $state, $pos) { 4048b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'emphasis'); 4058b1b81beSAndreas Gohr return true; 4068b1b81beSAndreas Gohr } 4078b1b81beSAndreas Gohr 4088b1b81beSAndreas Gohr /** 4098b1b81beSAndreas Gohr * @param string $match matched syntax 4108b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4118b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4128b1b81beSAndreas Gohr * @return bool mode handled? 4138b1b81beSAndreas Gohr */ 4148b1b81beSAndreas Gohr public function underline($match, $state, $pos) { 4158b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'underline'); 4168b1b81beSAndreas Gohr return true; 4178b1b81beSAndreas Gohr } 4188b1b81beSAndreas Gohr 4198b1b81beSAndreas Gohr /** 4208b1b81beSAndreas Gohr * @param string $match matched syntax 4218b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4228b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4238b1b81beSAndreas Gohr * @return bool mode handled? 4248b1b81beSAndreas Gohr */ 4258b1b81beSAndreas Gohr public function monospace($match, $state, $pos) { 4268b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'monospace'); 4278b1b81beSAndreas Gohr return true; 4288b1b81beSAndreas Gohr } 4298b1b81beSAndreas Gohr 4308b1b81beSAndreas Gohr /** 4318b1b81beSAndreas Gohr * @param string $match matched syntax 4328b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4338b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4348b1b81beSAndreas Gohr * @return bool mode handled? 4358b1b81beSAndreas Gohr */ 4368b1b81beSAndreas Gohr public function subscript($match, $state, $pos) { 4378b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'subscript'); 4388b1b81beSAndreas Gohr return true; 4398b1b81beSAndreas Gohr } 4408b1b81beSAndreas Gohr 4418b1b81beSAndreas Gohr /** 4428b1b81beSAndreas Gohr * @param string $match matched syntax 4438b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4448b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4458b1b81beSAndreas Gohr * @return bool mode handled? 4468b1b81beSAndreas Gohr */ 4478b1b81beSAndreas Gohr public function superscript($match, $state, $pos) { 4488b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'superscript'); 4498b1b81beSAndreas Gohr return true; 4508b1b81beSAndreas Gohr } 4518b1b81beSAndreas Gohr 4528b1b81beSAndreas Gohr /** 4538b1b81beSAndreas Gohr * @param string $match matched syntax 4548b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4558b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4568b1b81beSAndreas Gohr * @return bool mode handled? 4578b1b81beSAndreas Gohr */ 4588b1b81beSAndreas Gohr public function deleted($match, $state, $pos) { 4598b1b81beSAndreas Gohr $this->nestingTag($match, $state, $pos, 'deleted'); 4608b1b81beSAndreas Gohr return true; 4618b1b81beSAndreas Gohr } 4628b1b81beSAndreas Gohr 4638b1b81beSAndreas Gohr /** 4648b1b81beSAndreas Gohr * @param string $match matched syntax 4658b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 4668b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 4678b1b81beSAndreas Gohr * @return bool mode handled? 4688b1b81beSAndreas Gohr */ 4698b1b81beSAndreas Gohr public function footnote($match, $state, $pos) { 470*ac1d8211SAndreas Gohr if (!isset($this->footnote)) $this->footnote = false; 4718b1b81beSAndreas Gohr 4728b1b81beSAndreas Gohr switch ( $state ) { 4738b1b81beSAndreas Gohr case DOKU_LEXER_ENTER: 4748b1b81beSAndreas Gohr // footnotes can not be nested - however due to limitations in lexer it can't be prevented 4758b1b81beSAndreas Gohr // we will still enter a new footnote mode, we just do nothing 476*ac1d8211SAndreas Gohr if ($this->footnote) { 4778b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 4788b1b81beSAndreas Gohr break; 4798b1b81beSAndreas Gohr } 480*ac1d8211SAndreas Gohr $this->footnote = true; 4818b1b81beSAndreas Gohr 4828b1b81beSAndreas Gohr $this->callWriter = new Nest($this->callWriter, 'footnote_close'); 4838b1b81beSAndreas Gohr $this->addCall('footnote_open', array(), $pos); 4848b1b81beSAndreas Gohr break; 4858b1b81beSAndreas Gohr case DOKU_LEXER_EXIT: 4868b1b81beSAndreas Gohr // check whether we have already exitted the footnote mode, can happen if the modes were nested 487*ac1d8211SAndreas Gohr if (!$this->footnote) { 4888b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 4898b1b81beSAndreas Gohr break; 4908b1b81beSAndreas Gohr } 4918b1b81beSAndreas Gohr 492*ac1d8211SAndreas Gohr $this->footnote = false; 4938b1b81beSAndreas Gohr $this->addCall('footnote_close', array(), $pos); 4948b1b81beSAndreas Gohr 4958b1b81beSAndreas Gohr /** @var Nest $reWriter */ 4968b1b81beSAndreas Gohr $reWriter = $this->callWriter; 4978b1b81beSAndreas Gohr $this->callWriter = $reWriter->process(); 4988b1b81beSAndreas Gohr break; 4998b1b81beSAndreas Gohr case DOKU_LEXER_UNMATCHED: 5008b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 5018b1b81beSAndreas Gohr break; 5028b1b81beSAndreas Gohr } 5038b1b81beSAndreas Gohr return true; 5048b1b81beSAndreas Gohr } 5058b1b81beSAndreas Gohr 5068b1b81beSAndreas Gohr /** 5078b1b81beSAndreas Gohr * @param string $match matched syntax 5088b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 5098b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 5108b1b81beSAndreas Gohr * @return bool mode handled? 5118b1b81beSAndreas Gohr */ 5128b1b81beSAndreas Gohr public function listblock($match, $state, $pos) { 5138b1b81beSAndreas Gohr switch ( $state ) { 5148b1b81beSAndreas Gohr case DOKU_LEXER_ENTER: 5158b1b81beSAndreas Gohr $this->callWriter = new Lists($this->callWriter); 5168b1b81beSAndreas Gohr $this->addCall('list_open', array($match), $pos); 5178b1b81beSAndreas Gohr break; 5188b1b81beSAndreas Gohr case DOKU_LEXER_EXIT: 5198b1b81beSAndreas Gohr $this->addCall('list_close', array(), $pos); 5208b1b81beSAndreas Gohr /** @var Lists $reWriter */ 5218b1b81beSAndreas Gohr $reWriter = $this->callWriter; 5228b1b81beSAndreas Gohr $this->callWriter = $reWriter->process(); 5238b1b81beSAndreas Gohr break; 5248b1b81beSAndreas Gohr case DOKU_LEXER_MATCHED: 5258b1b81beSAndreas Gohr $this->addCall('list_item', array($match), $pos); 5268b1b81beSAndreas Gohr break; 5278b1b81beSAndreas Gohr case DOKU_LEXER_UNMATCHED: 5288b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 5298b1b81beSAndreas Gohr break; 5308b1b81beSAndreas Gohr } 5318b1b81beSAndreas Gohr return true; 5328b1b81beSAndreas Gohr } 5338b1b81beSAndreas Gohr 5348b1b81beSAndreas Gohr /** 5358b1b81beSAndreas Gohr * @param string $match matched syntax 5368b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 5378b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 5388b1b81beSAndreas Gohr * @return bool mode handled? 5398b1b81beSAndreas Gohr */ 5408b1b81beSAndreas Gohr public function unformatted($match, $state, $pos) { 5418b1b81beSAndreas Gohr if ( $state == DOKU_LEXER_UNMATCHED ) { 5428b1b81beSAndreas Gohr $this->addCall('unformatted', array($match), $pos); 5438b1b81beSAndreas Gohr } 5448b1b81beSAndreas Gohr return true; 5458b1b81beSAndreas Gohr } 5468b1b81beSAndreas Gohr 5478b1b81beSAndreas Gohr /** 5488b1b81beSAndreas Gohr * @param string $match matched syntax 5498b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 5508b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 5518b1b81beSAndreas Gohr * @return bool mode handled? 5528b1b81beSAndreas Gohr */ 5538b1b81beSAndreas Gohr public function preformatted($match, $state, $pos) { 5548b1b81beSAndreas Gohr switch ( $state ) { 5558b1b81beSAndreas Gohr case DOKU_LEXER_ENTER: 5568b1b81beSAndreas Gohr $this->callWriter = new Preformatted($this->callWriter); 5578b1b81beSAndreas Gohr $this->addCall('preformatted_start', array(), $pos); 5588b1b81beSAndreas Gohr break; 5598b1b81beSAndreas Gohr case DOKU_LEXER_EXIT: 5608b1b81beSAndreas Gohr $this->addCall('preformatted_end', array(), $pos); 5618b1b81beSAndreas Gohr /** @var Preformatted $reWriter */ 5628b1b81beSAndreas Gohr $reWriter = $this->callWriter; 5638b1b81beSAndreas Gohr $this->callWriter = $reWriter->process(); 5648b1b81beSAndreas Gohr break; 5658b1b81beSAndreas Gohr case DOKU_LEXER_MATCHED: 5668b1b81beSAndreas Gohr $this->addCall('preformatted_newline', array(), $pos); 5678b1b81beSAndreas Gohr break; 5688b1b81beSAndreas Gohr case DOKU_LEXER_UNMATCHED: 5698b1b81beSAndreas Gohr $this->addCall('preformatted_content', array($match), $pos); 5708b1b81beSAndreas Gohr break; 5718b1b81beSAndreas Gohr } 5728b1b81beSAndreas Gohr 5738b1b81beSAndreas Gohr return true; 5748b1b81beSAndreas Gohr } 5758b1b81beSAndreas Gohr 5768b1b81beSAndreas Gohr /** 5778b1b81beSAndreas Gohr * @param string $match matched syntax 5788b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 5798b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 5808b1b81beSAndreas Gohr * @return bool mode handled? 5818b1b81beSAndreas Gohr */ 5828b1b81beSAndreas Gohr public function quote($match, $state, $pos) { 5838b1b81beSAndreas Gohr 5848b1b81beSAndreas Gohr switch ( $state ) { 5858b1b81beSAndreas Gohr 5868b1b81beSAndreas Gohr case DOKU_LEXER_ENTER: 5878b1b81beSAndreas Gohr $this->callWriter = new Quote($this->callWriter); 5888b1b81beSAndreas Gohr $this->addCall('quote_start', array($match), $pos); 5898b1b81beSAndreas Gohr break; 5908b1b81beSAndreas Gohr 5918b1b81beSAndreas Gohr case DOKU_LEXER_EXIT: 5928b1b81beSAndreas Gohr $this->addCall('quote_end', array(), $pos); 5938b1b81beSAndreas Gohr /** @var Lists $reWriter */ 5948b1b81beSAndreas Gohr $reWriter = $this->callWriter; 5958b1b81beSAndreas Gohr $this->callWriter = $reWriter->process(); 5968b1b81beSAndreas Gohr break; 5978b1b81beSAndreas Gohr 5988b1b81beSAndreas Gohr case DOKU_LEXER_MATCHED: 5998b1b81beSAndreas Gohr $this->addCall('quote_newline', array($match), $pos); 6008b1b81beSAndreas Gohr break; 6018b1b81beSAndreas Gohr 6028b1b81beSAndreas Gohr case DOKU_LEXER_UNMATCHED: 6038b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 6048b1b81beSAndreas Gohr break; 6058b1b81beSAndreas Gohr 6068b1b81beSAndreas Gohr } 6078b1b81beSAndreas Gohr 6088b1b81beSAndreas Gohr return true; 6098b1b81beSAndreas Gohr } 6108b1b81beSAndreas Gohr 6118b1b81beSAndreas Gohr /** 6128b1b81beSAndreas Gohr * @param string $match matched syntax 6138b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6148b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6158b1b81beSAndreas Gohr * @return bool mode handled? 6168b1b81beSAndreas Gohr */ 6178b1b81beSAndreas Gohr public function file($match, $state, $pos) { 6183d491f75SAndreas Gohr return $this->code($match, $state, $pos, 'file'); 6193d491f75SAndreas Gohr } 6203d491f75SAndreas Gohr 6218b1b81beSAndreas Gohr /** 6228b1b81beSAndreas Gohr * @param string $match matched syntax 6238b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6248b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6258b1b81beSAndreas Gohr * @param string $type either 'code' or 'file' 6268b1b81beSAndreas Gohr * @return bool mode handled? 6278b1b81beSAndreas Gohr */ 6288b1b81beSAndreas Gohr public function code($match, $state, $pos, $type='code') { 6293d491f75SAndreas Gohr if ( $state == DOKU_LEXER_UNMATCHED ) { 630ec34bb30SAndreas Gohr $matches = sexplode('>',$match,2,''); 631e2d88156SLarsDW223 // Cut out variable options enclosed in [] 632e2d88156SLarsDW223 preg_match('/\[.*\]/', $matches[0], $options); 633e2d88156SLarsDW223 if (!empty($options[0])) { 634e2d88156SLarsDW223 $matches[0] = str_replace($options[0], '', $matches[0]); 635e2d88156SLarsDW223 } 6360139312bSAdrian Lang $param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY); 6370139312bSAdrian Lang while(count($param) < 2) array_push($param, null); 6380139312bSAdrian Lang // We shortcut html here. 6390139312bSAdrian Lang if ($param[0] == 'html') $param[0] = 'html4strict'; 6400139312bSAdrian Lang if ($param[0] == '-') $param[0] = null; 6410139312bSAdrian Lang array_unshift($param, $matches[1]); 642e2d88156SLarsDW223 if (!empty($options[0])) { 643e2d88156SLarsDW223 $param [] = $this->parse_highlight_options ($options[0]); 644e2d88156SLarsDW223 } 6458b1b81beSAndreas Gohr $this->addCall($type, $param, $pos); 6460cecf9d5Sandi } 64744881bd0Shenning.noren return true; 6480cecf9d5Sandi } 6490cecf9d5Sandi 6508b1b81beSAndreas Gohr /** 6518b1b81beSAndreas Gohr * @param string $match matched syntax 6528b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6538b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6548b1b81beSAndreas Gohr * @return bool mode handled? 6558b1b81beSAndreas Gohr */ 6568b1b81beSAndreas Gohr public function acronym($match, $state, $pos) { 6578b1b81beSAndreas Gohr $this->addCall('acronym', array($match), $pos); 65844881bd0Shenning.noren return true; 6590cecf9d5Sandi } 6600cecf9d5Sandi 6618b1b81beSAndreas Gohr /** 6628b1b81beSAndreas Gohr * @param string $match matched syntax 6638b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6648b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6658b1b81beSAndreas Gohr * @return bool mode handled? 6668b1b81beSAndreas Gohr */ 6678b1b81beSAndreas Gohr public function smiley($match, $state, $pos) { 6688b1b81beSAndreas Gohr $this->addCall('smiley', array($match), $pos); 66944881bd0Shenning.noren return true; 6700cecf9d5Sandi } 6710cecf9d5Sandi 6728b1b81beSAndreas Gohr /** 6738b1b81beSAndreas Gohr * @param string $match matched syntax 6748b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6758b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6768b1b81beSAndreas Gohr * @return bool mode handled? 6778b1b81beSAndreas Gohr */ 6788b1b81beSAndreas Gohr public function wordblock($match, $state, $pos) { 6798b1b81beSAndreas Gohr $this->addCall('wordblock', array($match), $pos); 68044881bd0Shenning.noren return true; 6810cecf9d5Sandi } 6820cecf9d5Sandi 6838b1b81beSAndreas Gohr /** 6848b1b81beSAndreas Gohr * @param string $match matched syntax 6858b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6868b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6878b1b81beSAndreas Gohr * @return bool mode handled? 6888b1b81beSAndreas Gohr */ 6898b1b81beSAndreas Gohr public function entity($match, $state, $pos) { 6908b1b81beSAndreas Gohr $this->addCall('entity', array($match), $pos); 69144881bd0Shenning.noren return true; 6920cecf9d5Sandi } 6930cecf9d5Sandi 6948b1b81beSAndreas Gohr /** 6958b1b81beSAndreas Gohr * @param string $match matched syntax 6968b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 6978b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 6988b1b81beSAndreas Gohr * @return bool mode handled? 6998b1b81beSAndreas Gohr */ 7008b1b81beSAndreas Gohr public function multiplyentity($match, $state, $pos) { 7010cecf9d5Sandi preg_match_all('/\d+/',$match,$matches); 7028b1b81beSAndreas Gohr $this->addCall('multiplyentity', array($matches[0][0], $matches[0][1]), $pos); 70344881bd0Shenning.noren return true; 7040cecf9d5Sandi } 7050cecf9d5Sandi 7068b1b81beSAndreas Gohr /** 7078b1b81beSAndreas Gohr * @param string $match matched syntax 7088b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7098b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7108b1b81beSAndreas Gohr * @return bool mode handled? 7118b1b81beSAndreas Gohr */ 7128b1b81beSAndreas Gohr public function singlequoteopening($match, $state, $pos) { 7138b1b81beSAndreas Gohr $this->addCall('singlequoteopening', array(), $pos); 71444881bd0Shenning.noren return true; 7150cecf9d5Sandi } 7160cecf9d5Sandi 7178b1b81beSAndreas Gohr /** 7188b1b81beSAndreas Gohr * @param string $match matched syntax 7198b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7208b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7218b1b81beSAndreas Gohr * @return bool mode handled? 7228b1b81beSAndreas Gohr */ 7238b1b81beSAndreas Gohr public function singlequoteclosing($match, $state, $pos) { 7248b1b81beSAndreas Gohr $this->addCall('singlequoteclosing', array(), $pos); 72544881bd0Shenning.noren return true; 7260cecf9d5Sandi } 7270cecf9d5Sandi 7288b1b81beSAndreas Gohr /** 7298b1b81beSAndreas Gohr * @param string $match matched syntax 7308b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7318b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7328b1b81beSAndreas Gohr * @return bool mode handled? 7338b1b81beSAndreas Gohr */ 7348b1b81beSAndreas Gohr public function apostrophe($match, $state, $pos) { 7358b1b81beSAndreas Gohr $this->addCall('apostrophe', array(), $pos); 73657d757d1SAndreas Gohr return true; 73757d757d1SAndreas Gohr } 73857d757d1SAndreas Gohr 7398b1b81beSAndreas Gohr /** 7408b1b81beSAndreas Gohr * @param string $match matched syntax 7418b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7428b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7438b1b81beSAndreas Gohr * @return bool mode handled? 7448b1b81beSAndreas Gohr */ 7458b1b81beSAndreas Gohr public function doublequoteopening($match, $state, $pos) { 7468b1b81beSAndreas Gohr $this->addCall('doublequoteopening', array(), $pos); 747e950d12fSChristopher Smith $this->status['doublequote']++; 74844881bd0Shenning.noren return true; 7490cecf9d5Sandi } 7500cecf9d5Sandi 7518b1b81beSAndreas Gohr /** 7528b1b81beSAndreas Gohr * @param string $match matched syntax 7538b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7548b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7558b1b81beSAndreas Gohr * @return bool mode handled? 7568b1b81beSAndreas Gohr */ 7578b1b81beSAndreas Gohr public function doublequoteclosing($match, $state, $pos) { 758e950d12fSChristopher Smith if ($this->status['doublequote'] <= 0) { 759e950d12fSChristopher Smith $this->doublequoteopening($match, $state, $pos); 760e950d12fSChristopher Smith } else { 7618b1b81beSAndreas Gohr $this->addCall('doublequoteclosing', array(), $pos); 762e950d12fSChristopher Smith $this->status['doublequote'] = max(0, --$this->status['doublequote']); 763e950d12fSChristopher Smith } 76444881bd0Shenning.noren return true; 7650cecf9d5Sandi } 7660cecf9d5Sandi 7678b1b81beSAndreas Gohr /** 7688b1b81beSAndreas Gohr * @param string $match matched syntax 7698b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7708b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7718b1b81beSAndreas Gohr * @return bool mode handled? 7728b1b81beSAndreas Gohr */ 7738b1b81beSAndreas Gohr public function camelcaselink($match, $state, $pos) { 7748b1b81beSAndreas Gohr $this->addCall('camelcaselink', array($match), $pos); 77544881bd0Shenning.noren return true; 7760cecf9d5Sandi } 7770cecf9d5Sandi 7788b1b81beSAndreas Gohr /** 7798b1b81beSAndreas Gohr * @param string $match matched syntax 7808b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 7818b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 7828b1b81beSAndreas Gohr * @return bool mode handled? 7830cecf9d5Sandi */ 7848b1b81beSAndreas Gohr public function internallink($match, $state, $pos) { 7850cecf9d5Sandi // Strip the opening and closing markup 7860cecf9d5Sandi $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match); 7870cecf9d5Sandi 7880cecf9d5Sandi // Split title from URL 789ec34bb30SAndreas Gohr $link = sexplode('|',$link,2); 790ec34bb30SAndreas Gohr if ( $link[1] === null ) { 7910ea51e63SMatt Perry $link[1] = null; 7920cecf9d5Sandi } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) { 7935578eb8fSandi // If the title is an image, convert it to an array containing the image details 794b625487dSandi $link[1] = Doku_Handler_Parse_Media($link[1]); 7950cecf9d5Sandi } 7960b7c14c2Sandi $link[0] = trim($link[0]); 7970cecf9d5Sandi 7980e1c636eSandi //decide which kind of link it is 7990e1c636eSandi 8006efc45a2SDmitry Katsubo if ( link_isinterwiki($link[0]) ) { 8010e1c636eSandi // Interwiki 802ec34bb30SAndreas Gohr $interwiki = sexplode('>',$link[0],2,''); 8038b1b81beSAndreas Gohr $this->addCall( 8040cecf9d5Sandi 'interwikilink', 8050cecf9d5Sandi array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]), 8060cecf9d5Sandi $pos 8070cecf9d5Sandi ); 80815f1b77cSAndreas Gohr }elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) { 8090e1c636eSandi // Windows Share 8108b1b81beSAndreas Gohr $this->addCall( 8110cecf9d5Sandi 'windowssharelink', 8120cecf9d5Sandi array($link[0],$link[1]), 8130cecf9d5Sandi $pos 8140cecf9d5Sandi ); 8154468cb4cSAndreas Gohr }elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) { 8160e1c636eSandi // external link (accepts all protocols) 8178b1b81beSAndreas Gohr $this->addCall( 8180cecf9d5Sandi 'externallink', 8190cecf9d5Sandi array($link[0],$link[1]), 8200cecf9d5Sandi $pos 8210cecf9d5Sandi ); 8220a1d30bfSchris }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) { 8230a1d30bfSchris // E-Mail (pattern above is defined in inc/mail.php) 8248b1b81beSAndreas Gohr $this->addCall( 825a6755281Sandi 'emaillink', 826a6755281Sandi array($link[0],$link[1]), 827a6755281Sandi $pos 828a6755281Sandi ); 8290b7c14c2Sandi }elseif ( preg_match('!^#.+!',$link[0]) ){ 8300b7c14c2Sandi // local link 8318b1b81beSAndreas Gohr $this->addCall( 8320b7c14c2Sandi 'locallink', 8330b7c14c2Sandi array(substr($link[0],1),$link[1]), 8340b7c14c2Sandi $pos 8350b7c14c2Sandi ); 8360e1c636eSandi }else{ 8370e1c636eSandi // internal link 8388b1b81beSAndreas Gohr $this->addCall( 8390e1c636eSandi 'internallink', 8400e1c636eSandi array($link[0],$link[1]), 8410e1c636eSandi $pos 8420e1c636eSandi ); 8430cecf9d5Sandi } 8440e1c636eSandi 84544881bd0Shenning.noren return true; 8460cecf9d5Sandi } 8470cecf9d5Sandi 8488b1b81beSAndreas Gohr /** 8498b1b81beSAndreas Gohr * @param string $match matched syntax 8508b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 8518b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 8528b1b81beSAndreas Gohr * @return bool mode handled? 8538b1b81beSAndreas Gohr */ 8548b1b81beSAndreas Gohr public function filelink($match, $state, $pos) { 8558b1b81beSAndreas Gohr $this->addCall('filelink', array($match, null), $pos); 85644881bd0Shenning.noren return true; 8570cecf9d5Sandi } 8580cecf9d5Sandi 8598b1b81beSAndreas Gohr /** 8608b1b81beSAndreas Gohr * @param string $match matched syntax 8618b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 8628b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 8638b1b81beSAndreas Gohr * @return bool mode handled? 8648b1b81beSAndreas Gohr */ 8658b1b81beSAndreas Gohr public function windowssharelink($match, $state, $pos) { 8668b1b81beSAndreas Gohr $this->addCall('windowssharelink', array($match, null), $pos); 86744881bd0Shenning.noren return true; 8680cecf9d5Sandi } 8690cecf9d5Sandi 8708b1b81beSAndreas Gohr /** 8718b1b81beSAndreas Gohr * @param string $match matched syntax 8728b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 8738b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 8748b1b81beSAndreas Gohr * @return bool mode handled? 8758b1b81beSAndreas Gohr */ 8768b1b81beSAndreas Gohr public function media($match, $state, $pos) { 8770cecf9d5Sandi $p = Doku_Handler_Parse_Media($match); 8780cecf9d5Sandi 8798b1b81beSAndreas Gohr $this->addCall( 8800cecf9d5Sandi $p['type'], 881dc673a5bSjoe.lapp array($p['src'], $p['title'], $p['align'], $p['width'], 882d8ab8746SAndreas Gohr $p['height'], $p['cache'], $p['linking']), 8830cecf9d5Sandi $pos 8840cecf9d5Sandi ); 88544881bd0Shenning.noren return true; 8860cecf9d5Sandi } 8870cecf9d5Sandi 8888b1b81beSAndreas Gohr /** 8898b1b81beSAndreas Gohr * @param string $match matched syntax 8908b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 8918b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 8928b1b81beSAndreas Gohr * @return bool mode handled? 8938b1b81beSAndreas Gohr */ 8948b1b81beSAndreas Gohr public function rss($match, $state, $pos) { 895b625487dSandi $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match); 8963db95becSAndreas Gohr 8973db95becSAndreas Gohr // get params 898ec34bb30SAndreas Gohr list($link, $params) = sexplode(' ', $link, 2, ''); 8993db95becSAndreas Gohr 9003db95becSAndreas Gohr $p = array(); 9013db95becSAndreas Gohr if(preg_match('/\b(\d+)\b/',$params,$match)){ 9023db95becSAndreas Gohr $p['max'] = $match[1]; 9033db95becSAndreas Gohr }else{ 9043db95becSAndreas Gohr $p['max'] = 8; 9053db95becSAndreas Gohr } 9063db95becSAndreas Gohr $p['reverse'] = (preg_match('/rev/',$params)); 9073db95becSAndreas Gohr $p['author'] = (preg_match('/\b(by|author)/',$params)); 9083db95becSAndreas Gohr $p['date'] = (preg_match('/\b(date)/',$params)); 9093db95becSAndreas Gohr $p['details'] = (preg_match('/\b(desc|detail)/',$params)); 91038c6f603SRobin H. Johnson $p['nosort'] = (preg_match('/\b(nosort)\b/',$params)); 9113db95becSAndreas Gohr 9120a69dff7Schris if (preg_match('/\b(\d+)([dhm])\b/',$params,$match)) { 9130a69dff7Schris $period = array('d' => 86400, 'h' => 3600, 'm' => 60); 9140a69dff7Schris $p['refresh'] = max(600,$match[1]*$period[$match[2]]); // n * period in seconds, minimum 10 minutes 9150a69dff7Schris } else { 9160a69dff7Schris $p['refresh'] = 14400; // default to 4 hours 9170a69dff7Schris } 9180a69dff7Schris 9198b1b81beSAndreas Gohr $this->addCall('rss', array($link, $p), $pos); 92044881bd0Shenning.noren return true; 921b625487dSandi } 922b625487dSandi 9238b1b81beSAndreas Gohr /** 9248b1b81beSAndreas Gohr * @param string $match matched syntax 9258b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 9268b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 9278b1b81beSAndreas Gohr * @return bool mode handled? 9288b1b81beSAndreas Gohr */ 9298b1b81beSAndreas Gohr public function externallink($match, $state, $pos) { 930da9f31c5SAndreas Gohr $url = $match; 931da9f31c5SAndreas Gohr $title = null; 9320cecf9d5Sandi 933da9f31c5SAndreas Gohr // add protocol on simple short URLs 934da9f31c5SAndreas Gohr if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')){ 935da9f31c5SAndreas Gohr $title = $url; 936da9f31c5SAndreas Gohr $url = 'ftp://'.$url; 937da9f31c5SAndreas Gohr } 938da9f31c5SAndreas Gohr if(substr($url,0,3) == 'www' && (substr($url,0,7) != 'http://')){ 939da9f31c5SAndreas Gohr $title = $url; 940da9f31c5SAndreas Gohr $url = 'http://'.$url; 941da9f31c5SAndreas Gohr } 942da9f31c5SAndreas Gohr 9438b1b81beSAndreas Gohr $this->addCall('externallink', array($url, $title), $pos); 94444881bd0Shenning.noren return true; 9450cecf9d5Sandi } 9460cecf9d5Sandi 9478b1b81beSAndreas Gohr /** 9488b1b81beSAndreas Gohr * @param string $match matched syntax 9498b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 9508b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 9518b1b81beSAndreas Gohr * @return bool mode handled? 9528b1b81beSAndreas Gohr */ 9538b1b81beSAndreas Gohr public function emaillink($match, $state, $pos) { 9540cecf9d5Sandi $email = preg_replace(array('/^</','/>$/'),'',$match); 9558b1b81beSAndreas Gohr $this->addCall('emaillink', array($email, null), $pos); 95644881bd0Shenning.noren return true; 9570cecf9d5Sandi } 9580cecf9d5Sandi 9598b1b81beSAndreas Gohr /** 9608b1b81beSAndreas Gohr * @param string $match matched syntax 9618b1b81beSAndreas Gohr * @param int $state a LEXER_STATE_* constant 9628b1b81beSAndreas Gohr * @param int $pos byte position in the original source file 9638b1b81beSAndreas Gohr * @return bool mode handled? 9648b1b81beSAndreas Gohr */ 9658b1b81beSAndreas Gohr public function table($match, $state, $pos) { 9660cecf9d5Sandi switch ( $state ) { 9670cecf9d5Sandi 9680cecf9d5Sandi case DOKU_LEXER_ENTER: 9690cecf9d5Sandi 9708b1b81beSAndreas Gohr $this->callWriter = new Table($this->callWriter); 9710cecf9d5Sandi 9728b1b81beSAndreas Gohr $this->addCall('table_start', array($pos + 1), $pos); 9730cecf9d5Sandi if ( trim($match) == '^' ) { 9748b1b81beSAndreas Gohr $this->addCall('tableheader', array(), $pos); 9750cecf9d5Sandi } else { 9768b1b81beSAndreas Gohr $this->addCall('tablecell', array(), $pos); 9770cecf9d5Sandi } 9780cecf9d5Sandi break; 9790cecf9d5Sandi 9800cecf9d5Sandi case DOKU_LEXER_EXIT: 9818b1b81beSAndreas Gohr $this->addCall('table_end', array($pos), $pos); 9825c2aad12SAndreas Gohr /** @var Table $reWriter */ 9838b1b81beSAndreas Gohr $reWriter = $this->callWriter; 9848b1b81beSAndreas Gohr $this->callWriter = $reWriter->process(); 9850cecf9d5Sandi break; 9860cecf9d5Sandi 9870cecf9d5Sandi case DOKU_LEXER_UNMATCHED: 9880cecf9d5Sandi if ( trim($match) != '' ) { 9898b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 9900cecf9d5Sandi } 9910cecf9d5Sandi break; 9920cecf9d5Sandi 9930cecf9d5Sandi case DOKU_LEXER_MATCHED: 9949ab75d9eSAndreas Gohr if ( $match == ' ' ){ 9958b1b81beSAndreas Gohr $this->addCall('cdata', array($match), $pos); 99625b97867Shakan.sandell } else if ( preg_match('/:::/',$match) ) { 9978b1b81beSAndreas Gohr $this->addCall('rowspan', array($match), $pos); 998e205b721SAndreas Gohr } else if ( preg_match('/\t+/',$match) ) { 9998b1b81beSAndreas Gohr $this->addCall('table_align', array($match), $pos); 1000e205b721SAndreas Gohr } else if ( preg_match('/ {2,}/',$match) ) { 10018b1b81beSAndreas Gohr $this->addCall('table_align', array($match), $pos); 10020cecf9d5Sandi } else if ( $match == "\n|" ) { 10038b1b81beSAndreas Gohr $this->addCall('table_row', array(), $pos); 10048b1b81beSAndreas Gohr $this->addCall('tablecell', array(), $pos); 10050cecf9d5Sandi } else if ( $match == "\n^" ) { 10068b1b81beSAndreas Gohr $this->addCall('table_row', array(), $pos); 10078b1b81beSAndreas Gohr $this->addCall('tableheader', array(), $pos); 10080cecf9d5Sandi } else if ( $match == '|' ) { 10098b1b81beSAndreas Gohr $this->addCall('tablecell', array(), $pos); 10100cecf9d5Sandi } else if ( $match == '^' ) { 10118b1b81beSAndreas Gohr $this->addCall('tableheader', array(), $pos); 10120cecf9d5Sandi } 10130cecf9d5Sandi break; 10140cecf9d5Sandi } 101544881bd0Shenning.noren return true; 10160cecf9d5Sandi } 10178b1b81beSAndreas Gohr 10188b1b81beSAndreas Gohr // endregion modes 10190cecf9d5Sandi} 10200cecf9d5Sandi 10210cecf9d5Sandi//------------------------------------------------------------------------ 10220cecf9d5Sandifunction Doku_Handler_Parse_Media($match) { 1023d8ab8746SAndreas Gohr 10240cecf9d5Sandi // Strip the opening and closing markup 10250cecf9d5Sandi $link = preg_replace(array('/^\{\{/','/\}\}$/u'),'',$match); 10260cecf9d5Sandi 10270cecf9d5Sandi // Split title from URL 1028ec34bb30SAndreas Gohr $link = sexplode('|', $link, 2); 10290cecf9d5Sandi 10300cecf9d5Sandi // Check alignment 10310cecf9d5Sandi $ralign = (bool)preg_match('/^ /',$link[0]); 10320cecf9d5Sandi $lalign = (bool)preg_match('/ $/',$link[0]); 10330cecf9d5Sandi 10340cecf9d5Sandi // Logic = what's that ;)... 10350cecf9d5Sandi if ( $lalign & $ralign ) { 10360cecf9d5Sandi $align = 'center'; 10370cecf9d5Sandi } else if ( $ralign ) { 10380cecf9d5Sandi $align = 'right'; 10390cecf9d5Sandi } else if ( $lalign ) { 10400cecf9d5Sandi $align = 'left'; 10410cecf9d5Sandi } else { 10420ea51e63SMatt Perry $align = null; 10430cecf9d5Sandi } 10440cecf9d5Sandi 10450cecf9d5Sandi // The title... 10460cecf9d5Sandi if ( !isset($link[1]) ) { 10470ea51e63SMatt Perry $link[1] = null; 10480cecf9d5Sandi } 10490cecf9d5Sandi 10504826ab45Sandi //remove aligning spaces 10514826ab45Sandi $link[0] = trim($link[0]); 10520cecf9d5Sandi 10534826ab45Sandi //split into src and parameters (using the very last questionmark) 10544826ab45Sandi $pos = strrpos($link[0], '?'); 10554826ab45Sandi if($pos !== false){ 10564826ab45Sandi $src = substr($link[0],0,$pos); 10574826ab45Sandi $param = substr($link[0],$pos+1); 10580cecf9d5Sandi }else{ 10594826ab45Sandi $src = $link[0]; 10604826ab45Sandi $param = ''; 10610cecf9d5Sandi } 10620cecf9d5Sandi 10634826ab45Sandi //parse width and height 10644826ab45Sandi if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){ 1065c48d6608SAndreas Gohr !empty($size[1]) ? $w = $size[1] : $w = null; 1066c48d6608SAndreas Gohr !empty($size[3]) ? $h = $size[3] : $h = null; 1067fc1c55b1Shfuecks } else { 10680ea51e63SMatt Perry $w = null; 10690ea51e63SMatt Perry $h = null; 10700cecf9d5Sandi } 10710cecf9d5Sandi 1072dc673a5bSjoe.lapp //get linking command 1073d35ab615Shenning.noren if(preg_match('/nolink/i',$param)){ 1074dc673a5bSjoe.lapp $linking = 'nolink'; 1075d35ab615Shenning.noren }else if(preg_match('/direct/i',$param)){ 1076dc673a5bSjoe.lapp $linking = 'direct'; 10778acb3108SAndreas Gohr }else if(preg_match('/linkonly/i',$param)){ 10788acb3108SAndreas Gohr $linking = 'linkonly'; 1079dc673a5bSjoe.lapp }else{ 1080dc673a5bSjoe.lapp $linking = 'details'; 1081dc673a5bSjoe.lapp } 1082dc673a5bSjoe.lapp 10834826ab45Sandi //get caching command 10844826ab45Sandi if (preg_match('/(nocache|recache)/i',$param,$cachemode)){ 10854826ab45Sandi $cache = $cachemode[1]; 10860cecf9d5Sandi }else{ 10874826ab45Sandi $cache = 'cache'; 10880cecf9d5Sandi } 1089d8ab8746SAndreas Gohr 10906efc45a2SDmitry Katsubo // Check whether this is a local or remote image or interwiki 10916efc45a2SDmitry Katsubo if (media_isexternal($src) || link_isinterwiki($src)){ 10924826ab45Sandi $call = 'externalmedia'; 10930cecf9d5Sandi } else { 10944826ab45Sandi $call = 'internalmedia'; 10950cecf9d5Sandi } 10960cecf9d5Sandi 10970cecf9d5Sandi $params = array( 10980cecf9d5Sandi 'type'=>$call, 10994826ab45Sandi 'src'=>$src, 11000cecf9d5Sandi 'title'=>$link[1], 11010cecf9d5Sandi 'align'=>$align, 11024826ab45Sandi 'width'=>$w, 11034826ab45Sandi 'height'=>$h, 11040cecf9d5Sandi 'cache'=>$cache, 1105dc673a5bSjoe.lapp 'linking'=>$linking, 11060cecf9d5Sandi ); 11070cecf9d5Sandi 11080cecf9d5Sandi return $params; 11090cecf9d5Sandi} 11100cecf9d5Sandi 1111