1<?php 2/** 3 * Plugin Linebreak: Inserts a line break 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Christopher Smith <chris@jalakai.co.uk> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13require_once(DOKU_PLUGIN.'syntax.php'); 14 15/** 16 * All DokuWiki plugins to extend the parser/rendering mechanism 17 * need to inherit from this class 18 */ 19class syntax_plugin_linebreak extends DokuWiki_Syntax_Plugin { 20 21 var $no_quotes = array(300, '(?<!^|\n)\n(?!\n)'); 22 var $in_quotes = array(100, '(?<!^|\n)\n(?!\n|>)'); 23# var $no_quotes = array(300, '(?<!\n)\n(?!\n)'); 24# var $in_quotes = array(100, '(?<!\n)\n(?!\n|>)'); 25 var $ptn_pageon = '~~LINEBREAK~~'; 26 var $ptn_pageoff = '~~NOLINEBREAK~~'; 27 28 function getInfo(){ 29 return array( 30 'author' => 'Christopher Smith', 31 'email' => 'chris@jalakai.co.uk', 32 'date' => '2007-01-20', 33 'name' => 'Linebreak Plugin', 34 'desc' => 'Provide a line break for a new line in the raw wiki data', 35 'url' => 'http://wiki.splitbrain.org/plugin:linebreak', 36 ); 37 } 38 39 function getType() { return 'substition'; } 40 function getSort() { return ($this->getConf('in_quotes') ? $this->in_quotes[0] : $this->no_quotes[0]); } 41 function connectTo($mode) { 42 43 $ptn = $this->getConf('in_quotes') ? $this->in_quotes[1] : $this->no_quotes[1]; 44 $this->Lexer->addSpecialPattern($ptn,$mode,'plugin_linebreak'); 45 46 $this->Lexer->addSpecialPattern($this->ptn_pageon,$mode,'plugin_linebreak'); 47 $this->Lexer->addSpecialPattern($this->ptn_pageoff,$mode,'plugin_linebreak'); 48 49 $this->Lexer->addSpecialPattern('~~LINEBREAK#.+~~\n',$mode,'plugin_linebreak'); 50 } 51 52 function handle($match, $state, $pos, &$handler){ 53 54 if (substr($match, 0, 12) == '~~LINEBREAK#') { 55 $marker = substr($match, 12,-3); 56 return array('marker' => $marker); 57 } 58 59 if (!isset($handler->status['plugin_linebreak'])) { 60 $handler->status['plugin_linebreak'] = $this->getConf('automatic'); 61 } 62 63 if ($match == "\n") return array($handler->status['plugin_linebreak']); 64 65 if ($match == $this->ptn_pageon) { 66 $handler->status['plugin_linebreak'] = true; 67 } else if ($match == $this->ptn_pageoff) { 68 $handler->status['plugin_linebreak'] = false; 69 } 70 71 return array(false); 72 } 73 74 function render($mode, &$renderer, $data) { 75 76 if($mode == 'xhtml'){ 77 if ($data[0]) $renderer->doc .= "<br />"; 78 return true; 79 } 80 return false; 81 } 82 83}