10cecf9d5Sandi<?php 2fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 30cecf9d5Sandirequire_once DOKU_INC . 'inc/parser/lexer.php'; 40cecf9d5Sandirequire_once DOKU_INC . 'inc/parser/handler.php'; 50cecf9d5Sandi 6ee20e7d1Sandi 7ee20e7d1Sandi/** 8ee20e7d1Sandi * Define various types of modes used by the parser - they are used to 9ee20e7d1Sandi * populate the list of modes another mode accepts 10ee20e7d1Sandi */ 11ee20e7d1Sandiglobal $PARSER_MODES; 12ee20e7d1Sandi$PARSER_MODES = array( 13ee20e7d1Sandi // containers are complex modes that can contain many other modes 14ee20e7d1Sandi // hr breaks the principle but they shouldn't be used in tables / lists 15ee20e7d1Sandi // so they are put here 16ee20e7d1Sandi 'container' => array('listblock','table','quote','hr'), 17ee20e7d1Sandi 18ee20e7d1Sandi // some mode are allowed inside the base mode only 19ee20e7d1Sandi 'baseonly' => array('header'), 20ee20e7d1Sandi 21ee20e7d1Sandi // modes for styling text -- footnote behaves similar to styling 22ee20e7d1Sandi 'formatting' => array('strong', 'emphasis', 'underline', 'monospace', 23ee20e7d1Sandi 'subscript', 'superscript', 'deleted', 'footnote'), 24ee20e7d1Sandi 25ee20e7d1Sandi // modes where the token is simply replaced - they can not contain any 26ee20e7d1Sandi // other modes 27ee20e7d1Sandi 'substition' => array('acronym','smiley','wordblock','entity', 28ee20e7d1Sandi 'camelcaselink', 'internallink','media', 29ee20e7d1Sandi 'externallink','linebreak','emaillink', 30ee20e7d1Sandi 'windowssharelink','filelink','notoc', 31ee20e7d1Sandi 'nocache','multiplyentity','quotes','rss'), 32ee20e7d1Sandi 33ee20e7d1Sandi // modes which have a start and end token but inside which 34ee20e7d1Sandi // no other modes should be applied 3507f89c3cSAnika Henke 'protected' => array('preformatted','code','file','php','html','htmlblock','phpblock'), 36ee20e7d1Sandi 37ee20e7d1Sandi // inside this mode no wiki markup should be applied but lineendings 38ee20e7d1Sandi // and whitespace isn't preserved 39ee20e7d1Sandi 'disabled' => array('unformatted'), 40ee20e7d1Sandi 41ee20e7d1Sandi // used to mark paragraph boundaries 42ee20e7d1Sandi 'paragraphs' => array('eol') 43ee20e7d1Sandi); 44ee20e7d1Sandi 450cecf9d5Sandi//------------------------------------------------------------------- 460cecf9d5Sandi 470cecf9d5Sandi/** 480cecf9d5Sandi * Sets up the Lexer with modes and points it to the Handler 490cecf9d5Sandi * For an intro to the Lexer see: wiki:parser 500cecf9d5Sandi */ 510cecf9d5Sandiclass Doku_Parser { 520cecf9d5Sandi 530cecf9d5Sandi var $Handler; 540cecf9d5Sandi 55e3ab6fc5SMichael Hamann /** 56e3ab6fc5SMichael Hamann * @var Doku_Lexer $Lexer 57e3ab6fc5SMichael Hamann */ 580cecf9d5Sandi var $Lexer; 590cecf9d5Sandi 600cecf9d5Sandi var $modes = array(); 610cecf9d5Sandi 6244881bd0Shenning.noren var $connected = false; 630cecf9d5Sandi 64276820f7SScrutinizer Auto-Fixer /** 65276820f7SScrutinizer Auto-Fixer * @param Doku_Parser_Mode_base $BaseMode 66276820f7SScrutinizer Auto-Fixer */ 67b7c441b9SHarry Fuecks function addBaseMode(& $BaseMode) { 68b7c441b9SHarry Fuecks $this->modes['base'] =& $BaseMode; 690cecf9d5Sandi if ( !$this->Lexer ) { 7067f9913dSAndreas Gohr $this->Lexer = new Doku_Lexer($this->Handler,'base', true); 710cecf9d5Sandi } 720cecf9d5Sandi $this->modes['base']->Lexer =& $this->Lexer; 730cecf9d5Sandi } 740cecf9d5Sandi 750cecf9d5Sandi /** 760cecf9d5Sandi * PHP preserves order of associative elements 770cecf9d5Sandi * Mode sequence is important 780cecf9d5Sandi */ 790cecf9d5Sandi function addMode($name, & $Mode) { 800cecf9d5Sandi if ( !isset($this->modes['base']) ) { 81107b01d6Sandi $this->addBaseMode(new Doku_Parser_Mode_base()); 820cecf9d5Sandi } 830cecf9d5Sandi $Mode->Lexer = & $this->Lexer; 840cecf9d5Sandi $this->modes[$name] =& $Mode; 850cecf9d5Sandi } 860cecf9d5Sandi 870cecf9d5Sandi function connectModes() { 880cecf9d5Sandi 890cecf9d5Sandi if ( $this->connected ) { 900cecf9d5Sandi return; 910cecf9d5Sandi } 920cecf9d5Sandi 930cecf9d5Sandi foreach ( array_keys($this->modes) as $mode ) { 940cecf9d5Sandi 950cecf9d5Sandi // Base isn't connected to anything 960cecf9d5Sandi if ( $mode == 'base' ) { 970cecf9d5Sandi continue; 980cecf9d5Sandi } 990cecf9d5Sandi $this->modes[$mode]->preConnect(); 1000cecf9d5Sandi 1010cecf9d5Sandi foreach ( array_keys($this->modes) as $cm ) { 1020cecf9d5Sandi 1030cecf9d5Sandi if ( $this->modes[$cm]->accepts($mode) ) { 1040cecf9d5Sandi $this->modes[$mode]->connectTo($cm); 1050cecf9d5Sandi } 1060cecf9d5Sandi 1070cecf9d5Sandi } 1080cecf9d5Sandi 1090cecf9d5Sandi $this->modes[$mode]->postConnect(); 1100cecf9d5Sandi } 1110cecf9d5Sandi 11244881bd0Shenning.noren $this->connected = true; 1130cecf9d5Sandi } 1140cecf9d5Sandi 1150cecf9d5Sandi function parse($doc) { 1160cecf9d5Sandi if ( $this->Lexer ) { 1170cecf9d5Sandi $this->connectModes(); 1180cecf9d5Sandi // Normalize CRs and pad doc 1190cecf9d5Sandi $doc = "\n".str_replace("\r\n","\n",$doc)."\n"; 1200cecf9d5Sandi $this->Lexer->parse($doc); 121433bef32Sandi $this->Handler->_finalize(); 1220cecf9d5Sandi return $this->Handler->calls; 1230cecf9d5Sandi } else { 12444881bd0Shenning.noren return false; 1250cecf9d5Sandi } 1260cecf9d5Sandi } 1270cecf9d5Sandi 1280cecf9d5Sandi} 1290cecf9d5Sandi 1300cecf9d5Sandi//------------------------------------------------------------------- 1315a3e1f53SAndreas Gohr 1325a3e1f53SAndreas Gohr/** 1335a3e1f53SAndreas Gohr * Class Doku_Parser_Mode_Interface 1345a3e1f53SAndreas Gohr * 1355a3e1f53SAndreas Gohr * Defines a mode (syntax component) in the Parser 1365a3e1f53SAndreas Gohr */ 1375a3e1f53SAndreas Gohrinterface Doku_Parser_Mode_Interface { 1385a3e1f53SAndreas Gohr /** 1395a3e1f53SAndreas Gohr * returns a number used to determine in which order modes are added 1405a3e1f53SAndreas Gohr */ 1415a3e1f53SAndreas Gohr public function getSort(); 1425a3e1f53SAndreas Gohr 1435a3e1f53SAndreas Gohr /** 1445a3e1f53SAndreas Gohr * Called before any calls to connectTo 145276820f7SScrutinizer Auto-Fixer * @return void 1465a3e1f53SAndreas Gohr */ 1475a3e1f53SAndreas Gohr function preConnect(); 1485a3e1f53SAndreas Gohr 1495a3e1f53SAndreas Gohr /** 1505a3e1f53SAndreas Gohr * Connects the mode 1515a3e1f53SAndreas Gohr * 1525a3e1f53SAndreas Gohr * @param string $mode 153276820f7SScrutinizer Auto-Fixer * @return void 1545a3e1f53SAndreas Gohr */ 1555a3e1f53SAndreas Gohr function connectTo($mode); 1565a3e1f53SAndreas Gohr 1575a3e1f53SAndreas Gohr /** 1585a3e1f53SAndreas Gohr * Called after all calls to connectTo 159276820f7SScrutinizer Auto-Fixer * @return void 1605a3e1f53SAndreas Gohr */ 1615a3e1f53SAndreas Gohr function postConnect(); 1625a3e1f53SAndreas Gohr 1635a3e1f53SAndreas Gohr /** 1645a3e1f53SAndreas Gohr * Check if given mode is accepted inside this mode 1655a3e1f53SAndreas Gohr * 1665a3e1f53SAndreas Gohr * @param string $mode 1675a3e1f53SAndreas Gohr * @return bool 1685a3e1f53SAndreas Gohr */ 1695a3e1f53SAndreas Gohr function accepts($mode); 1705a3e1f53SAndreas Gohr} 1715a3e1f53SAndreas Gohr 1720cecf9d5Sandi/** 17372d89f96SAndreas Gohr * This class and all the subclasses below are used to reduce the effort required to register 17472d89f96SAndreas Gohr * modes with the Lexer. 17572d89f96SAndreas Gohr * 1760b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 1770cecf9d5Sandi */ 1785a3e1f53SAndreas Gohrclass Doku_Parser_Mode implements Doku_Parser_Mode_Interface { 179e3ab6fc5SMichael Hamann /** 180e3ab6fc5SMichael Hamann * @var Doku_Lexer $Lexer 181e3ab6fc5SMichael Hamann */ 1820cecf9d5Sandi var $Lexer; 1830cecf9d5Sandi var $allowedModes = array(); 1840cecf9d5Sandi 185107b01d6Sandi function getSort() { 186107b01d6Sandi trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); 187107b01d6Sandi } 188107b01d6Sandi 1890cecf9d5Sandi function preConnect() {} 1900cecf9d5Sandi function connectTo($mode) {} 1910cecf9d5Sandi function postConnect() {} 1920cecf9d5Sandi function accepts($mode) { 1936f9bd982SAndreas Gohr return in_array($mode, (array) $this->allowedModes ); 1940cecf9d5Sandi } 1955a3e1f53SAndreas Gohr} 1960cecf9d5Sandi 1975a3e1f53SAndreas Gohr/** 1985a3e1f53SAndreas Gohr * Basically the same as Doku_Parser_Mode but extends from DokuWiki_Plugin 1995a3e1f53SAndreas Gohr * 2005a3e1f53SAndreas Gohr * Adds additional functions to syntax plugins 2015a3e1f53SAndreas Gohr */ 2025a3e1f53SAndreas Gohrclass Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mode_Interface { 2035a3e1f53SAndreas Gohr /** 2045a3e1f53SAndreas Gohr * @var Doku_Lexer $Lexer 2055a3e1f53SAndreas Gohr */ 2065a3e1f53SAndreas Gohr var $Lexer; 2075a3e1f53SAndreas Gohr var $allowedModes = array(); 2085a3e1f53SAndreas Gohr 2097ac0b9feSAndreas Gohr /** 2107ac0b9feSAndreas Gohr * Sort for applying this mode 2117ac0b9feSAndreas Gohr * 2127ac0b9feSAndreas Gohr * @return int 2137ac0b9feSAndreas Gohr */ 2145a3e1f53SAndreas Gohr function getSort() { 2155a3e1f53SAndreas Gohr trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); 2165a3e1f53SAndreas Gohr } 2175a3e1f53SAndreas Gohr 2185a3e1f53SAndreas Gohr function preConnect() {} 2195a3e1f53SAndreas Gohr function connectTo($mode) {} 2205a3e1f53SAndreas Gohr function postConnect() {} 2215a3e1f53SAndreas Gohr function accepts($mode) { 2225a3e1f53SAndreas Gohr return in_array($mode, (array) $this->allowedModes ); 2235a3e1f53SAndreas Gohr } 2240cecf9d5Sandi} 2250cecf9d5Sandi 2260cecf9d5Sandi//------------------------------------------------------------------- 227107b01d6Sandiclass Doku_Parser_Mode_base extends Doku_Parser_Mode { 2280cecf9d5Sandi 229*26e22ab8SChristopher Smith function __construct() { 230ee20e7d1Sandi global $PARSER_MODES; 2310cecf9d5Sandi 2320cecf9d5Sandi $this->allowedModes = array_merge ( 233ee20e7d1Sandi $PARSER_MODES['container'], 234ee20e7d1Sandi $PARSER_MODES['baseonly'], 235ee20e7d1Sandi $PARSER_MODES['paragraphs'], 236ee20e7d1Sandi $PARSER_MODES['formatting'], 237ee20e7d1Sandi $PARSER_MODES['substition'], 238ee20e7d1Sandi $PARSER_MODES['protected'], 239ee20e7d1Sandi $PARSER_MODES['disabled'] 2400cecf9d5Sandi ); 2410cecf9d5Sandi } 242107b01d6Sandi 243107b01d6Sandi function getSort() { 244107b01d6Sandi return 0; 245107b01d6Sandi } 2460cecf9d5Sandi} 2470cecf9d5Sandi 2480cecf9d5Sandi//------------------------------------------------------------------- 249107b01d6Sandiclass Doku_Parser_Mode_footnote extends Doku_Parser_Mode { 2500cecf9d5Sandi 251*26e22ab8SChristopher Smith function __construct() { 252ee20e7d1Sandi global $PARSER_MODES; 2530cecf9d5Sandi 2540cecf9d5Sandi $this->allowedModes = array_merge ( 255ee20e7d1Sandi $PARSER_MODES['container'], 256ee20e7d1Sandi $PARSER_MODES['formatting'], 257ee20e7d1Sandi $PARSER_MODES['substition'], 258ee20e7d1Sandi $PARSER_MODES['protected'], 259ee20e7d1Sandi $PARSER_MODES['disabled'] 2600cecf9d5Sandi ); 2610cecf9d5Sandi 2622fe7363dSchris unset($this->allowedModes[array_search('footnote', $this->allowedModes)]); 2630cecf9d5Sandi } 2640cecf9d5Sandi 2650cecf9d5Sandi function connectTo($mode) { 2660cecf9d5Sandi $this->Lexer->addEntryPattern( 2670cecf9d5Sandi '\x28\x28(?=.*\x29\x29)',$mode,'footnote' 2680cecf9d5Sandi ); 2690cecf9d5Sandi } 2700cecf9d5Sandi 2710cecf9d5Sandi function postConnect() { 2720cecf9d5Sandi $this->Lexer->addExitPattern( 2730cecf9d5Sandi '\x29\x29','footnote' 2740cecf9d5Sandi ); 2750cecf9d5Sandi } 2760cecf9d5Sandi 277107b01d6Sandi function getSort() { 278107b01d6Sandi return 150; 279107b01d6Sandi } 2800cecf9d5Sandi} 2810cecf9d5Sandi 2820cecf9d5Sandi//------------------------------------------------------------------- 283107b01d6Sandiclass Doku_Parser_Mode_header extends Doku_Parser_Mode { 2840cecf9d5Sandi 2859fa736b0SAndreas Gohr function connectTo($mode) { 286506ae684Sandi //we're not picky about the closing ones, two are enough 2870cecf9d5Sandi $this->Lexer->addSpecialPattern( 28830fe9cd6SAndreas Gohr '[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)', 2899fa736b0SAndreas Gohr $mode, 2900cecf9d5Sandi 'header' 2910cecf9d5Sandi ); 2920cecf9d5Sandi } 2930cecf9d5Sandi 294107b01d6Sandi function getSort() { 295107b01d6Sandi return 50; 296107b01d6Sandi } 2970cecf9d5Sandi} 2980cecf9d5Sandi 2990cecf9d5Sandi//------------------------------------------------------------------- 300107b01d6Sandiclass Doku_Parser_Mode_notoc extends Doku_Parser_Mode { 3010cecf9d5Sandi 3020cecf9d5Sandi function connectTo($mode) { 3030cecf9d5Sandi $this->Lexer->addSpecialPattern('~~NOTOC~~',$mode,'notoc'); 3040cecf9d5Sandi } 3050cecf9d5Sandi 306107b01d6Sandi function getSort() { 307107b01d6Sandi return 30; 308107b01d6Sandi } 3090cecf9d5Sandi} 3100cecf9d5Sandi 3110cecf9d5Sandi//------------------------------------------------------------------- 312107b01d6Sandiclass Doku_Parser_Mode_nocache extends Doku_Parser_Mode { 3139dc2c2afSandi 3149dc2c2afSandi function connectTo($mode) { 3159dc2c2afSandi $this->Lexer->addSpecialPattern('~~NOCACHE~~',$mode,'nocache'); 3169dc2c2afSandi } 3179dc2c2afSandi 318107b01d6Sandi function getSort() { 319107b01d6Sandi return 40; 320107b01d6Sandi } 3219dc2c2afSandi} 3229dc2c2afSandi 3239dc2c2afSandi//------------------------------------------------------------------- 324107b01d6Sandiclass Doku_Parser_Mode_linebreak extends Doku_Parser_Mode { 3250cecf9d5Sandi 3260cecf9d5Sandi function connectTo($mode) { 32730897fecSChris Smith $this->Lexer->addSpecialPattern('\x5C{2}(?:[ \t]|(?=\n))',$mode,'linebreak'); 3280cecf9d5Sandi } 329107b01d6Sandi 330107b01d6Sandi function getSort() { 331107b01d6Sandi return 140; 332107b01d6Sandi } 3330cecf9d5Sandi} 3340cecf9d5Sandi 3350cecf9d5Sandi//------------------------------------------------------------------- 336107b01d6Sandiclass Doku_Parser_Mode_eol extends Doku_Parser_Mode { 3370cecf9d5Sandi 3380cecf9d5Sandi function connectTo($mode) { 3390cecf9d5Sandi $badModes = array('listblock','table'); 3400cecf9d5Sandi if ( in_array($mode, $badModes) ) { 3410cecf9d5Sandi return; 3420cecf9d5Sandi } 34395c19ce7SChris Smith // see FS#1652, pattern extended to swallow preceding whitespace to avoid issues with lines that only contain whitespace 34495c19ce7SChris Smith $this->Lexer->addSpecialPattern('(?:^[ \t]*)?\n',$mode,'eol'); 3450cecf9d5Sandi } 346107b01d6Sandi 347107b01d6Sandi function getSort() { 348107b01d6Sandi return 370; 349107b01d6Sandi } 3500cecf9d5Sandi} 3510cecf9d5Sandi 3520cecf9d5Sandi//------------------------------------------------------------------- 353107b01d6Sandiclass Doku_Parser_Mode_hr extends Doku_Parser_Mode { 3540cecf9d5Sandi 3550cecf9d5Sandi function connectTo($mode) { 3566f0c5dbfSandi $this->Lexer->addSpecialPattern('\n[ \t]*-{4,}[ \t]*(?=\n)',$mode,'hr'); 3570cecf9d5Sandi } 3580cecf9d5Sandi 359107b01d6Sandi function getSort() { 360107b01d6Sandi return 160; 361107b01d6Sandi } 3620cecf9d5Sandi} 3630cecf9d5Sandi 3640cecf9d5Sandi//------------------------------------------------------------------- 36503b54bb0SThorsten Staerk/** 36603b54bb0SThorsten Staerk * This class sets the markup for bold (=strong), 36703b54bb0SThorsten Staerk * italic (=emphasis), underline etc. 36803b54bb0SThorsten Staerk */ 369107b01d6Sandiclass Doku_Parser_Mode_formatting extends Doku_Parser_Mode { 3700cecf9d5Sandi var $type; 3710cecf9d5Sandi 3720cecf9d5Sandi var $formatting = array ( 3730cecf9d5Sandi 'strong' => array ( 3740cecf9d5Sandi 'entry'=>'\*\*(?=.*\*\*)', 3750cecf9d5Sandi 'exit'=>'\*\*', 376107b01d6Sandi 'sort'=>70 3770cecf9d5Sandi ), 3780cecf9d5Sandi 3790cecf9d5Sandi 'emphasis'=> array ( 38024b0ff2aSAndreas Gohr 'entry'=>'//(?=[^\x00]*[^:])', //hack for bugs #384 #763 #1468 3810cecf9d5Sandi 'exit'=>'//', 382107b01d6Sandi 'sort'=>80 3830cecf9d5Sandi ), 3840cecf9d5Sandi 3850cecf9d5Sandi 'underline'=> array ( 3860cecf9d5Sandi 'entry'=>'__(?=.*__)', 3870cecf9d5Sandi 'exit'=>'__', 388107b01d6Sandi 'sort'=>90 3890cecf9d5Sandi ), 3900cecf9d5Sandi 3910cecf9d5Sandi 'monospace'=> array ( 3920cecf9d5Sandi 'entry'=>'\x27\x27(?=.*\x27\x27)', 3930cecf9d5Sandi 'exit'=>'\x27\x27', 394107b01d6Sandi 'sort'=>100 3950cecf9d5Sandi ), 3960cecf9d5Sandi 3970cecf9d5Sandi 'subscript'=> array ( 39887858f84Schris 'entry'=>'<sub>(?=.*</sub>)', 3990cecf9d5Sandi 'exit'=>'</sub>', 400107b01d6Sandi 'sort'=>110 4010cecf9d5Sandi ), 4020cecf9d5Sandi 4030cecf9d5Sandi 'superscript'=> array ( 40487858f84Schris 'entry'=>'<sup>(?=.*</sup>)', 4050cecf9d5Sandi 'exit'=>'</sup>', 406107b01d6Sandi 'sort'=>120 4070cecf9d5Sandi ), 4080cecf9d5Sandi 4090cecf9d5Sandi 'deleted'=> array ( 41087858f84Schris 'entry'=>'<del>(?=.*</del>)', 4110cecf9d5Sandi 'exit'=>'</del>', 412107b01d6Sandi 'sort'=>130 4130cecf9d5Sandi ), 4140cecf9d5Sandi ); 4150cecf9d5Sandi 416276820f7SScrutinizer Auto-Fixer /** 417276820f7SScrutinizer Auto-Fixer * @param string $type 418276820f7SScrutinizer Auto-Fixer */ 419*26e22ab8SChristopher Smith function __construct($type) { 420ee20e7d1Sandi global $PARSER_MODES; 4210cecf9d5Sandi 4220cecf9d5Sandi if ( !array_key_exists($type, $this->formatting) ) { 4230cecf9d5Sandi trigger_error('Invalid formatting type '.$type, E_USER_WARNING); 4240cecf9d5Sandi } 4250cecf9d5Sandi 4260cecf9d5Sandi $this->type = $type; 4270cecf9d5Sandi 428ee20e7d1Sandi // formatting may contain other formatting but not it self 429ee20e7d1Sandi $modes = $PARSER_MODES['formatting']; 430ee20e7d1Sandi $key = array_search($type, $modes); 431ee20e7d1Sandi if ( is_int($key) ) { 432ee20e7d1Sandi unset($modes[$key]); 433ee20e7d1Sandi } 4340cecf9d5Sandi 435ee20e7d1Sandi $this->allowedModes = array_merge ( 436ee20e7d1Sandi $modes, 437ee20e7d1Sandi $PARSER_MODES['substition'], 438ee20e7d1Sandi $PARSER_MODES['disabled'] 439ee20e7d1Sandi ); 4400cecf9d5Sandi } 4410cecf9d5Sandi 4420cecf9d5Sandi function connectTo($mode) { 4430cecf9d5Sandi 4440cecf9d5Sandi // Can't nest formatting in itself 4450cecf9d5Sandi if ( $mode == $this->type ) { 4460cecf9d5Sandi return; 4470cecf9d5Sandi } 4480cecf9d5Sandi 4490cecf9d5Sandi $this->Lexer->addEntryPattern( 4500cecf9d5Sandi $this->formatting[$this->type]['entry'], 4510cecf9d5Sandi $mode, 4520cecf9d5Sandi $this->type 4530cecf9d5Sandi ); 4540cecf9d5Sandi } 4550cecf9d5Sandi 4560cecf9d5Sandi function postConnect() { 4570cecf9d5Sandi 4580cecf9d5Sandi $this->Lexer->addExitPattern( 4590cecf9d5Sandi $this->formatting[$this->type]['exit'], 4600cecf9d5Sandi $this->type 4610cecf9d5Sandi ); 4620cecf9d5Sandi 4630cecf9d5Sandi } 464107b01d6Sandi 465107b01d6Sandi function getSort() { 466107b01d6Sandi return $this->formatting[$this->type]['sort']; 467107b01d6Sandi } 4680cecf9d5Sandi} 4690cecf9d5Sandi 4700cecf9d5Sandi//------------------------------------------------------------------- 471107b01d6Sandiclass Doku_Parser_Mode_listblock extends Doku_Parser_Mode { 4720cecf9d5Sandi 473*26e22ab8SChristopher Smith function __construct() { 474ee20e7d1Sandi global $PARSER_MODES; 4750cecf9d5Sandi 4760cecf9d5Sandi $this->allowedModes = array_merge ( 477ee20e7d1Sandi $PARSER_MODES['formatting'], 478ee20e7d1Sandi $PARSER_MODES['substition'], 479ee20e7d1Sandi $PARSER_MODES['disabled'], 480ee20e7d1Sandi $PARSER_MODES['protected'] #XXX new 4810cecf9d5Sandi ); 482702eb898Sandi 483ee20e7d1Sandi // $this->allowedModes[] = 'footnote'; 4840cecf9d5Sandi } 4850cecf9d5Sandi 4860cecf9d5Sandi function connectTo($mode) { 48713ebcbe5SChristopher Smith $this->Lexer->addEntryPattern('[ \t]*\n {2,}[\-\*]',$mode,'listblock'); 48813ebcbe5SChristopher Smith $this->Lexer->addEntryPattern('[ \t]*\n\t{1,}[\-\*]',$mode,'listblock'); 4890cecf9d5Sandi 4900cecf9d5Sandi $this->Lexer->addPattern('\n {2,}[\-\*]','listblock'); 4910cecf9d5Sandi $this->Lexer->addPattern('\n\t{1,}[\-\*]','listblock'); 4920cecf9d5Sandi 4930cecf9d5Sandi } 4940cecf9d5Sandi 4950cecf9d5Sandi function postConnect() { 4960cecf9d5Sandi $this->Lexer->addExitPattern('\n','listblock'); 4970cecf9d5Sandi } 498107b01d6Sandi 499107b01d6Sandi function getSort() { 500107b01d6Sandi return 10; 501107b01d6Sandi } 5020cecf9d5Sandi} 5030cecf9d5Sandi 5040cecf9d5Sandi//------------------------------------------------------------------- 505107b01d6Sandiclass Doku_Parser_Mode_table extends Doku_Parser_Mode { 5060cecf9d5Sandi 507*26e22ab8SChristopher Smith function __construct() { 508ee20e7d1Sandi global $PARSER_MODES; 5090cecf9d5Sandi 5100cecf9d5Sandi $this->allowedModes = array_merge ( 511ee20e7d1Sandi $PARSER_MODES['formatting'], 512ee20e7d1Sandi $PARSER_MODES['substition'], 513ee20e7d1Sandi $PARSER_MODES['disabled'], 514107b01d6Sandi $PARSER_MODES['protected'] 5150cecf9d5Sandi ); 5160cecf9d5Sandi } 5170cecf9d5Sandi 5180cecf9d5Sandi function connectTo($mode) { 5195a41afe6SChristopher Smith $this->Lexer->addEntryPattern('[\t ]*\n\^',$mode,'table'); 5205a41afe6SChristopher Smith $this->Lexer->addEntryPattern('[\t ]*\n\|',$mode,'table'); 5210cecf9d5Sandi } 5220cecf9d5Sandi 5230cecf9d5Sandi function postConnect() { 5240cecf9d5Sandi $this->Lexer->addPattern('\n\^','table'); 5250cecf9d5Sandi $this->Lexer->addPattern('\n\|','table'); 52625b97867Shakan.sandell $this->Lexer->addPattern('[\t ]*:::[\t ]*(?=[\|\^])','table'); 5279ab75d9eSAndreas Gohr $this->Lexer->addPattern('[\t ]+','table'); 5280cecf9d5Sandi $this->Lexer->addPattern('\^','table'); 5290cecf9d5Sandi $this->Lexer->addPattern('\|','table'); 5300cecf9d5Sandi $this->Lexer->addExitPattern('\n','table'); 5310cecf9d5Sandi } 532107b01d6Sandi 533107b01d6Sandi function getSort() { 534107b01d6Sandi return 60; 535107b01d6Sandi } 5360cecf9d5Sandi} 5370cecf9d5Sandi 5380cecf9d5Sandi//------------------------------------------------------------------- 539107b01d6Sandiclass Doku_Parser_Mode_unformatted extends Doku_Parser_Mode { 5400cecf9d5Sandi 5410cecf9d5Sandi function connectTo($mode) { 54287858f84Schris $this->Lexer->addEntryPattern('<nowiki>(?=.*</nowiki>)',$mode,'unformatted'); 5430cecf9d5Sandi $this->Lexer->addEntryPattern('%%(?=.*%%)',$mode,'unformattedalt'); 5440cecf9d5Sandi } 5450cecf9d5Sandi 5460cecf9d5Sandi function postConnect() { 5470cecf9d5Sandi $this->Lexer->addExitPattern('</nowiki>','unformatted'); 5480cecf9d5Sandi $this->Lexer->addExitPattern('%%','unformattedalt'); 5490cecf9d5Sandi $this->Lexer->mapHandler('unformattedalt','unformatted'); 5500cecf9d5Sandi } 5510cecf9d5Sandi 552107b01d6Sandi function getSort() { 553107b01d6Sandi return 170; 554107b01d6Sandi } 5550cecf9d5Sandi} 5560cecf9d5Sandi 5570cecf9d5Sandi//------------------------------------------------------------------- 558107b01d6Sandiclass Doku_Parser_Mode_php extends Doku_Parser_Mode { 5590cecf9d5Sandi 5600cecf9d5Sandi function connectTo($mode) { 56187858f84Schris $this->Lexer->addEntryPattern('<php>(?=.*</php>)',$mode,'php'); 56207f89c3cSAnika Henke $this->Lexer->addEntryPattern('<PHP>(?=.*</PHP>)',$mode,'phpblock'); 5630cecf9d5Sandi } 5640cecf9d5Sandi 5650cecf9d5Sandi function postConnect() { 5660cecf9d5Sandi $this->Lexer->addExitPattern('</php>','php'); 56707f89c3cSAnika Henke $this->Lexer->addExitPattern('</PHP>','phpblock'); 5680cecf9d5Sandi } 5690cecf9d5Sandi 570107b01d6Sandi function getSort() { 571107b01d6Sandi return 180; 572107b01d6Sandi } 5730cecf9d5Sandi} 5740cecf9d5Sandi 5750cecf9d5Sandi//------------------------------------------------------------------- 576107b01d6Sandiclass Doku_Parser_Mode_html extends Doku_Parser_Mode { 5770cecf9d5Sandi 5780cecf9d5Sandi function connectTo($mode) { 57987858f84Schris $this->Lexer->addEntryPattern('<html>(?=.*</html>)',$mode,'html'); 58007f89c3cSAnika Henke $this->Lexer->addEntryPattern('<HTML>(?=.*</HTML>)',$mode,'htmlblock'); 5810cecf9d5Sandi } 5820cecf9d5Sandi 5830cecf9d5Sandi function postConnect() { 5840cecf9d5Sandi $this->Lexer->addExitPattern('</html>','html'); 58507f89c3cSAnika Henke $this->Lexer->addExitPattern('</HTML>','htmlblock'); 5860cecf9d5Sandi } 5870cecf9d5Sandi 588107b01d6Sandi function getSort() { 589107b01d6Sandi return 190; 590107b01d6Sandi } 5910cecf9d5Sandi} 5920cecf9d5Sandi 5930cecf9d5Sandi//------------------------------------------------------------------- 594107b01d6Sandiclass Doku_Parser_Mode_preformatted extends Doku_Parser_Mode { 5950cecf9d5Sandi 5960cecf9d5Sandi function connectTo($mode) { 5970cecf9d5Sandi // Has hard coded awareness of lists... 5980cecf9d5Sandi $this->Lexer->addEntryPattern('\n (?![\*\-])',$mode,'preformatted'); 5990cecf9d5Sandi $this->Lexer->addEntryPattern('\n\t(?![\*\-])',$mode,'preformatted'); 6000cecf9d5Sandi 6010cecf9d5Sandi // How to effect a sub pattern with the Lexer! 6020cecf9d5Sandi $this->Lexer->addPattern('\n ','preformatted'); 6030cecf9d5Sandi $this->Lexer->addPattern('\n\t','preformatted'); 6040cecf9d5Sandi 6050cecf9d5Sandi } 6060cecf9d5Sandi 6070cecf9d5Sandi function postConnect() { 6080cecf9d5Sandi $this->Lexer->addExitPattern('\n','preformatted'); 6090cecf9d5Sandi } 6100cecf9d5Sandi 611107b01d6Sandi function getSort() { 612107b01d6Sandi return 20; 613107b01d6Sandi } 6140cecf9d5Sandi} 6150cecf9d5Sandi 6160cecf9d5Sandi//------------------------------------------------------------------- 617107b01d6Sandiclass Doku_Parser_Mode_code extends Doku_Parser_Mode { 6180cecf9d5Sandi 6190cecf9d5Sandi function connectTo($mode) { 620fc498a42SChristopher Smith $this->Lexer->addEntryPattern('<code\b(?=.*</code>)',$mode,'code'); 6210cecf9d5Sandi } 6220cecf9d5Sandi 6230cecf9d5Sandi function postConnect() { 6240cecf9d5Sandi $this->Lexer->addExitPattern('</code>','code'); 6250cecf9d5Sandi } 6260cecf9d5Sandi 627107b01d6Sandi function getSort() { 628107b01d6Sandi return 200; 629107b01d6Sandi } 6300cecf9d5Sandi} 6310cecf9d5Sandi 6320cecf9d5Sandi//------------------------------------------------------------------- 633107b01d6Sandiclass Doku_Parser_Mode_file extends Doku_Parser_Mode { 6340cecf9d5Sandi 6350cecf9d5Sandi function connectTo($mode) { 636fc498a42SChristopher Smith $this->Lexer->addEntryPattern('<file\b(?=.*</file>)',$mode,'file'); 6370cecf9d5Sandi } 6380cecf9d5Sandi 6390cecf9d5Sandi function postConnect() { 6400cecf9d5Sandi $this->Lexer->addExitPattern('</file>','file'); 6410cecf9d5Sandi } 6420cecf9d5Sandi 643107b01d6Sandi function getSort() { 644107b01d6Sandi return 210; 645107b01d6Sandi } 6460cecf9d5Sandi} 6470cecf9d5Sandi 6480cecf9d5Sandi//------------------------------------------------------------------- 649107b01d6Sandiclass Doku_Parser_Mode_quote extends Doku_Parser_Mode { 6500cecf9d5Sandi 651*26e22ab8SChristopher Smith function __construct() { 652ee20e7d1Sandi global $PARSER_MODES; 6530cecf9d5Sandi 6540cecf9d5Sandi $this->allowedModes = array_merge ( 655ee20e7d1Sandi $PARSER_MODES['formatting'], 656ee20e7d1Sandi $PARSER_MODES['substition'], 657ee20e7d1Sandi $PARSER_MODES['disabled'], 658ee20e7d1Sandi $PARSER_MODES['protected'] #XXX new 6590cecf9d5Sandi ); 660ee20e7d1Sandi #$this->allowedModes[] = 'footnote'; 661ee20e7d1Sandi #$this->allowedModes[] = 'preformatted'; 662ee20e7d1Sandi #$this->allowedModes[] = 'unformatted'; 6630cecf9d5Sandi } 6640cecf9d5Sandi 6650cecf9d5Sandi function connectTo($mode) { 6660cecf9d5Sandi $this->Lexer->addEntryPattern('\n>{1,}',$mode,'quote'); 6670cecf9d5Sandi } 6680cecf9d5Sandi 6690cecf9d5Sandi function postConnect() { 6700cecf9d5Sandi $this->Lexer->addPattern('\n>{1,}','quote'); 6710cecf9d5Sandi $this->Lexer->addExitPattern('\n','quote'); 6720cecf9d5Sandi } 6730cecf9d5Sandi 674107b01d6Sandi function getSort() { 675107b01d6Sandi return 220; 676107b01d6Sandi } 6770cecf9d5Sandi} 6780cecf9d5Sandi 6790cecf9d5Sandi//------------------------------------------------------------------- 680107b01d6Sandiclass Doku_Parser_Mode_acronym extends Doku_Parser_Mode { 6810cecf9d5Sandi // A list 6820cecf9d5Sandi var $acronyms = array(); 6830cecf9d5Sandi var $pattern = ''; 6840cecf9d5Sandi 685*26e22ab8SChristopher Smith function __construct($acronyms) { 6867cc4b757SChris Smith usort($acronyms,array($this,'_compare')); 6870cecf9d5Sandi $this->acronyms = $acronyms; 6880cecf9d5Sandi } 6890cecf9d5Sandi 6900cecf9d5Sandi function preConnect() { 691901c1c87SAndreas Gohr if(!count($this->acronyms)) return; 692901c1c87SAndreas Gohr 6938e266198SAndreas Gohr $bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]'; 694e6258e07SAndreas Gohr $acronyms = array_map('Doku_Lexer_Escape',$this->acronyms); 6958e266198SAndreas Gohr $this->pattern = '(?<=^|'.$bound.')(?:'.join('|',$acronyms).')(?='.$bound.')'; 6960cecf9d5Sandi } 6970cecf9d5Sandi 6980cecf9d5Sandi function connectTo($mode) { 699901c1c87SAndreas Gohr if(!count($this->acronyms)) return; 700901c1c87SAndreas Gohr 7010cecf9d5Sandi if ( strlen($this->pattern) > 0 ) { 7020cecf9d5Sandi $this->Lexer->addSpecialPattern($this->pattern,$mode,'acronym'); 7030cecf9d5Sandi } 7040cecf9d5Sandi } 7050cecf9d5Sandi 706107b01d6Sandi function getSort() { 707107b01d6Sandi return 240; 708107b01d6Sandi } 7097cc4b757SChris Smith 7107cc4b757SChris Smith /** 7117cc4b757SChris Smith * sort callback to order by string length descending 7127cc4b757SChris Smith */ 7137cc4b757SChris Smith function _compare($a,$b) { 7147cc4b757SChris Smith $a_len = strlen($a); 7157cc4b757SChris Smith $b_len = strlen($b); 7167cc4b757SChris Smith if ($a_len > $b_len) { 7177cc4b757SChris Smith return -1; 7187cc4b757SChris Smith } else if ($a_len < $b_len) { 7197cc4b757SChris Smith return 1; 7207cc4b757SChris Smith } 7217cc4b757SChris Smith 7227cc4b757SChris Smith return 0; 7237cc4b757SChris Smith } 7240cecf9d5Sandi} 7250cecf9d5Sandi 7260cecf9d5Sandi//------------------------------------------------------------------- 727107b01d6Sandiclass Doku_Parser_Mode_smiley extends Doku_Parser_Mode { 7280cecf9d5Sandi // A list 7290cecf9d5Sandi var $smileys = array(); 7300cecf9d5Sandi var $pattern = ''; 7310cecf9d5Sandi 732*26e22ab8SChristopher Smith function __construct($smileys) { 7330cecf9d5Sandi $this->smileys = $smileys; 7340cecf9d5Sandi } 7350cecf9d5Sandi 7360cecf9d5Sandi function preConnect() { 737d4834a19SStephane Chazelas if(!count($this->smileys) || $this->pattern != '') return; 738901c1c87SAndreas Gohr 7390cecf9d5Sandi $sep = ''; 7400cecf9d5Sandi foreach ( $this->smileys as $smiley ) { 7411b26635bSAndreas Gohr $this->pattern .= $sep.'(?<=\W|^)'.Doku_Lexer_Escape($smiley).'(?=\W|$)'; 7420cecf9d5Sandi $sep = '|'; 7430cecf9d5Sandi } 7440cecf9d5Sandi } 7450cecf9d5Sandi 7460cecf9d5Sandi function connectTo($mode) { 747901c1c87SAndreas Gohr if(!count($this->smileys)) return; 748901c1c87SAndreas Gohr 7490cecf9d5Sandi if ( strlen($this->pattern) > 0 ) { 7500cecf9d5Sandi $this->Lexer->addSpecialPattern($this->pattern,$mode,'smiley'); 7510cecf9d5Sandi } 7520cecf9d5Sandi } 7530cecf9d5Sandi 754107b01d6Sandi function getSort() { 755107b01d6Sandi return 230; 756107b01d6Sandi } 7570cecf9d5Sandi} 7580cecf9d5Sandi 7590cecf9d5Sandi//------------------------------------------------------------------- 760107b01d6Sandiclass Doku_Parser_Mode_wordblock extends Doku_Parser_Mode { 7610cecf9d5Sandi // A list 7620cecf9d5Sandi var $badwords = array(); 7630cecf9d5Sandi var $pattern = ''; 7640cecf9d5Sandi 765*26e22ab8SChristopher Smith function __construct($badwords) { 7660cecf9d5Sandi $this->badwords = $badwords; 7670cecf9d5Sandi } 7680cecf9d5Sandi 7690cecf9d5Sandi function preConnect() { 7700cecf9d5Sandi 771d4834a19SStephane Chazelas if ( count($this->badwords) == 0 || $this->pattern != '') { 7720cecf9d5Sandi return; 7730cecf9d5Sandi } 7740cecf9d5Sandi 7750cecf9d5Sandi $sep = ''; 7760cecf9d5Sandi foreach ( $this->badwords as $badword ) { 7770cecf9d5Sandi $this->pattern .= $sep.'(?<=\b)(?i)'.Doku_Lexer_Escape($badword).'(?-i)(?=\b)'; 7780cecf9d5Sandi $sep = '|'; 7790cecf9d5Sandi } 7800cecf9d5Sandi 7810cecf9d5Sandi } 7820cecf9d5Sandi 7830cecf9d5Sandi function connectTo($mode) { 7840cecf9d5Sandi if ( strlen($this->pattern) > 0 ) { 7850cecf9d5Sandi $this->Lexer->addSpecialPattern($this->pattern,$mode,'wordblock'); 7860cecf9d5Sandi } 7870cecf9d5Sandi } 7880cecf9d5Sandi 789107b01d6Sandi function getSort() { 790107b01d6Sandi return 250; 791107b01d6Sandi } 7920cecf9d5Sandi} 7930cecf9d5Sandi 7940cecf9d5Sandi//------------------------------------------------------------------- 795107b01d6Sandiclass Doku_Parser_Mode_entity extends Doku_Parser_Mode { 7960cecf9d5Sandi // A list 7970cecf9d5Sandi var $entities = array(); 7980cecf9d5Sandi var $pattern = ''; 7990cecf9d5Sandi 800*26e22ab8SChristopher Smith function __construct($entities) { 8010cecf9d5Sandi $this->entities = $entities; 8020cecf9d5Sandi } 8030cecf9d5Sandi 8040cecf9d5Sandi function preConnect() { 805d4834a19SStephane Chazelas if(!count($this->entities) || $this->pattern != '') return; 806901c1c87SAndreas Gohr 8070cecf9d5Sandi $sep = ''; 8080cecf9d5Sandi foreach ( $this->entities as $entity ) { 8090cecf9d5Sandi $this->pattern .= $sep.Doku_Lexer_Escape($entity); 8100cecf9d5Sandi $sep = '|'; 8110cecf9d5Sandi } 8120cecf9d5Sandi } 8130cecf9d5Sandi 8140cecf9d5Sandi function connectTo($mode) { 815901c1c87SAndreas Gohr if(!count($this->entities)) return; 816901c1c87SAndreas Gohr 8170cecf9d5Sandi if ( strlen($this->pattern) > 0 ) { 8180cecf9d5Sandi $this->Lexer->addSpecialPattern($this->pattern,$mode,'entity'); 8190cecf9d5Sandi } 8200cecf9d5Sandi } 8210cecf9d5Sandi 822107b01d6Sandi function getSort() { 823107b01d6Sandi return 260; 824107b01d6Sandi } 8250cecf9d5Sandi} 8260cecf9d5Sandi 8270cecf9d5Sandi//------------------------------------------------------------------- 8280cecf9d5Sandi// Implements the 640x480 replacement 829107b01d6Sandiclass Doku_Parser_Mode_multiplyentity extends Doku_Parser_Mode { 8300cecf9d5Sandi 8310cecf9d5Sandi function connectTo($mode) { 8320cecf9d5Sandi 8330cecf9d5Sandi $this->Lexer->addSpecialPattern( 83468df1afcSChris Smith '(?<=\b)(?:[1-9]|\d{2,})[xX]\d+(?=\b)',$mode,'multiplyentity' 8350cecf9d5Sandi ); 8360cecf9d5Sandi 8370cecf9d5Sandi } 8380cecf9d5Sandi 839107b01d6Sandi function getSort() { 840107b01d6Sandi return 270; 841107b01d6Sandi } 8420cecf9d5Sandi} 8430cecf9d5Sandi 8440cecf9d5Sandi//------------------------------------------------------------------- 845107b01d6Sandiclass Doku_Parser_Mode_quotes extends Doku_Parser_Mode { 8460cecf9d5Sandi 8470cecf9d5Sandi function connectTo($mode) { 8489426a41aSAndreas Gohr global $conf; 8499426a41aSAndreas Gohr 8505fc8a925SAndreas Gohr $ws = '\s/\#~:+=&%@\-\x28\x29\]\[{}><"\''; // whitespace 8515fc8a925SAndreas Gohr $punc = ';,\.?!'; 8520cecf9d5Sandi 8539426a41aSAndreas Gohr if($conf['typography'] == 2){ 8540cecf9d5Sandi $this->Lexer->addSpecialPattern( 8555fc8a925SAndreas Gohr "(?<=^|[$ws])'(?=[^$ws$punc])",$mode,'singlequoteopening' 8560cecf9d5Sandi ); 8570cecf9d5Sandi $this->Lexer->addSpecialPattern( 8585fc8a925SAndreas Gohr "(?<=^|[^$ws]|[$punc])'(?=$|[$ws$punc])",$mode,'singlequoteclosing' 8590cecf9d5Sandi ); 8600cecf9d5Sandi $this->Lexer->addSpecialPattern( 8615fc8a925SAndreas Gohr "(?<=^|[^$ws$punc])'(?=$|[^$ws$punc])",$mode,'apostrophe' 8620cecf9d5Sandi ); 8639426a41aSAndreas Gohr } 8649426a41aSAndreas Gohr 8650cecf9d5Sandi $this->Lexer->addSpecialPattern( 8665fc8a925SAndreas Gohr "(?<=^|[$ws])\"(?=[^$ws$punc])",$mode,'doublequoteopening' 8670cecf9d5Sandi ); 86857d757d1SAndreas Gohr $this->Lexer->addSpecialPattern( 8695fc8a925SAndreas Gohr "\"",$mode,'doublequoteclosing' 87057d757d1SAndreas Gohr ); 87157d757d1SAndreas Gohr 8720cecf9d5Sandi } 8730cecf9d5Sandi 874107b01d6Sandi function getSort() { 875107b01d6Sandi return 280; 876107b01d6Sandi } 8770cecf9d5Sandi} 8780cecf9d5Sandi 8790cecf9d5Sandi//------------------------------------------------------------------- 880107b01d6Sandiclass Doku_Parser_Mode_camelcaselink extends Doku_Parser_Mode { 8810cecf9d5Sandi 8820cecf9d5Sandi function connectTo($mode) { 8830cecf9d5Sandi $this->Lexer->addSpecialPattern( 8840cecf9d5Sandi '\b[A-Z]+[a-z]+[A-Z][A-Za-z]*\b',$mode,'camelcaselink' 8850cecf9d5Sandi ); 8860cecf9d5Sandi } 8870cecf9d5Sandi 888107b01d6Sandi function getSort() { 889107b01d6Sandi return 290; 890107b01d6Sandi } 8910cecf9d5Sandi} 8920cecf9d5Sandi 8930cecf9d5Sandi//------------------------------------------------------------------- 894107b01d6Sandiclass Doku_Parser_Mode_internallink extends Doku_Parser_Mode { 8950cecf9d5Sandi 8960cecf9d5Sandi function connectTo($mode) { 8970cecf9d5Sandi // Word boundaries? 89845a0fa15SAdrian Lang $this->Lexer->addSpecialPattern("\[\[(?:(?:[^[\]]*?\[.*?\])|.*?)\]\]",$mode,'internallink'); 8990cecf9d5Sandi } 9000cecf9d5Sandi 901107b01d6Sandi function getSort() { 902107b01d6Sandi return 300; 903107b01d6Sandi } 9040cecf9d5Sandi} 9050cecf9d5Sandi 9060cecf9d5Sandi//------------------------------------------------------------------- 907107b01d6Sandiclass Doku_Parser_Mode_media extends Doku_Parser_Mode { 9080cecf9d5Sandi 9090cecf9d5Sandi function connectTo($mode) { 9100cecf9d5Sandi // Word boundaries? 9110cecf9d5Sandi $this->Lexer->addSpecialPattern("\{\{[^\}]+\}\}",$mode,'media'); 9120cecf9d5Sandi } 9130cecf9d5Sandi 914107b01d6Sandi function getSort() { 915107b01d6Sandi return 320; 916107b01d6Sandi } 9170cecf9d5Sandi} 9180cecf9d5Sandi 9190cecf9d5Sandi//------------------------------------------------------------------- 920107b01d6Sandiclass Doku_Parser_Mode_rss extends Doku_Parser_Mode { 921b625487dSandi 922b625487dSandi function connectTo($mode) { 923b625487dSandi $this->Lexer->addSpecialPattern("\{\{rss>[^\}]+\}\}",$mode,'rss'); 924b625487dSandi } 925b625487dSandi 926107b01d6Sandi function getSort() { 927107b01d6Sandi return 310; 928107b01d6Sandi } 929b625487dSandi} 930b625487dSandi 931b625487dSandi//------------------------------------------------------------------- 932107b01d6Sandiclass Doku_Parser_Mode_externallink extends Doku_Parser_Mode { 93336f2d7c1SGina Haeussge var $schemes = array(); 9340cecf9d5Sandi var $patterns = array(); 9350cecf9d5Sandi 9360cecf9d5Sandi function preConnect() { 937d4834a19SStephane Chazelas if(count($this->patterns)) return; 9380cecf9d5Sandi 9390cecf9d5Sandi $ltrs = '\w'; 9405d190f12SAndreas Gohr $gunk = '/\#~:.?+=&%@!\-\[\]'; 9410cecf9d5Sandi $punc = '.:?\-;,'; 9420cecf9d5Sandi $host = $ltrs.$punc; 9430cecf9d5Sandi $any = $ltrs.$gunk.$punc; 9440cecf9d5Sandi 94536f2d7c1SGina Haeussge $this->schemes = getSchemes(); 9460cecf9d5Sandi foreach ( $this->schemes as $scheme ) { 9476f0c5dbfSandi $this->patterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; 9480cecf9d5Sandi } 9490cecf9d5Sandi 9506f0c5dbfSandi $this->patterns[] = '\b(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; 9516f0c5dbfSandi $this->patterns[] = '\b(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; 9520cecf9d5Sandi } 9530cecf9d5Sandi 9540cecf9d5Sandi function connectTo($mode) { 955d4834a19SStephane Chazelas 9560cecf9d5Sandi foreach ( $this->patterns as $pattern ) { 9570cecf9d5Sandi $this->Lexer->addSpecialPattern($pattern,$mode,'externallink'); 9580cecf9d5Sandi } 9590cecf9d5Sandi } 9600cecf9d5Sandi 961107b01d6Sandi function getSort() { 962107b01d6Sandi return 330; 963107b01d6Sandi } 9640cecf9d5Sandi} 9650cecf9d5Sandi 9660cecf9d5Sandi//------------------------------------------------------------------- 967107b01d6Sandiclass Doku_Parser_Mode_filelink extends Doku_Parser_Mode { 9680cecf9d5Sandi 9690cecf9d5Sandi var $pattern; 9700cecf9d5Sandi 9710cecf9d5Sandi function preConnect() { 9720cecf9d5Sandi 9730cecf9d5Sandi $ltrs = '\w'; 9740cecf9d5Sandi $gunk = '/\#~:.?+=&%@!\-'; 9750cecf9d5Sandi $punc = '.:?\-;,'; 9760cecf9d5Sandi $host = $ltrs.$punc; 9770cecf9d5Sandi $any = $ltrs.$gunk.$punc; 9780cecf9d5Sandi 9790cecf9d5Sandi $this->pattern = '\b(?i)file(?-i)://['.$any.']+?['. 9800cecf9d5Sandi $punc.']*[^'.$any.']'; 9810cecf9d5Sandi } 9820cecf9d5Sandi 9830cecf9d5Sandi function connectTo($mode) { 9840cecf9d5Sandi $this->Lexer->addSpecialPattern( 9850cecf9d5Sandi $this->pattern,$mode,'filelink'); 9860cecf9d5Sandi } 9870cecf9d5Sandi 988107b01d6Sandi function getSort() { 989107b01d6Sandi return 360; 990107b01d6Sandi } 9910cecf9d5Sandi} 9920cecf9d5Sandi 9930cecf9d5Sandi//------------------------------------------------------------------- 994107b01d6Sandiclass Doku_Parser_Mode_windowssharelink extends Doku_Parser_Mode { 9950cecf9d5Sandi 9960cecf9d5Sandi var $pattern; 9970cecf9d5Sandi 9980cecf9d5Sandi function preConnect() { 999bfdeb23fSlupo49 $this->pattern = "\\\\\\\\\w+?(?:\\\\[\w-$]+)+"; 10000cecf9d5Sandi } 10010cecf9d5Sandi 10020cecf9d5Sandi function connectTo($mode) { 10030cecf9d5Sandi $this->Lexer->addSpecialPattern( 10040cecf9d5Sandi $this->pattern,$mode,'windowssharelink'); 10050cecf9d5Sandi } 10060cecf9d5Sandi 1007107b01d6Sandi function getSort() { 1008107b01d6Sandi return 350; 1009107b01d6Sandi } 10100cecf9d5Sandi} 10110cecf9d5Sandi 10120cecf9d5Sandi//------------------------------------------------------------------- 1013107b01d6Sandiclass Doku_Parser_Mode_emaillink extends Doku_Parser_Mode { 10140cecf9d5Sandi 10150cecf9d5Sandi function connectTo($mode) { 10160a1d30bfSchris // pattern below is defined in inc/mail.php 10170a1d30bfSchris $this->Lexer->addSpecialPattern('<'.PREG_PATTERN_VALID_EMAIL.'>',$mode,'emaillink'); 10180cecf9d5Sandi } 10190cecf9d5Sandi 1020107b01d6Sandi function getSort() { 1021107b01d6Sandi return 340; 1022107b01d6Sandi } 10230cecf9d5Sandi} 10240cecf9d5Sandi 1025340756e4Sandi 1026e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1027