diff options
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/handler.php | 32 | ||||
-rw-r--r-- | inc/parser/renderer.php | 6 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 81 |
3 files changed, 66 insertions, 53 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 141cbcaf0..b5d2baaab 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -12,9 +12,6 @@ class Doku_Handler { var $status = array( 'section' => false, - 'section_edit_start' => -1, - 'section_edit_level' => 1, - 'section_edit_title' => '' ); var $rewriteBlocks = true; @@ -40,10 +37,6 @@ class Doku_Handler { if ( $this->status['section'] ) { $last_call = end($this->calls); array_push($this->calls,array('section_close',array(), $last_call[2])); - if ($this->status['section_edit_start']>1) { - // ignore last edit section if there is only one header - array_push($this->calls,array('section_edit',array($this->status['section_edit_start'], 0, $this->status['section_edit_level'], $this->status['section_edit_title']), $last_call[2])); - } } if ( $this->rewriteBlocks ) { @@ -97,8 +90,6 @@ class Doku_Handler { } function header($match, $state, $pos) { - global $conf; - // get level and title $title = trim($match); $level = 7 - strspn($title,'='); @@ -108,13 +99,6 @@ class Doku_Handler { if ($this->status['section']) $this->_addCall('section_close',array(),$pos); - if ($level<=$conf['maxseclevel']) { - $this->_addCall('section_edit',array($this->status['section_edit_start'], $pos-1, $this->status['section_edit_level'], $this->status['section_edit_title']), $pos); - $this->status['section_edit_start'] = $pos; - $this->status['section_edit_level'] = $level; - $this->status['section_edit_title'] = $title; - } - $this->_addCall('header',array($title,$level,$pos), $pos); $this->_addCall('section_open',array($level),$pos); @@ -583,17 +567,16 @@ class Doku_Handler { $ReWriter = new Doku_Handler_Table($this->CallWriter); $this->CallWriter = & $ReWriter; - $this->_addCall('table_start', array(), $pos); + $this->_addCall('table_start', array($pos + 1), $pos); if ( trim($match) == '^' ) { $this->_addCall('tableheader', array(), $pos); } else { $this->_addCall('tablecell', array(), $pos); } - $this->status['table_begin'] = $pos; break; case DOKU_LEXER_EXIT: - $this->_addCall('table_end', array($this->status['table_begin']+1, $pos), $pos); + $this->_addCall('table_end', array($pos), $pos); $this->CallWriter->process(); $ReWriter = & $this->CallWriter; $this->CallWriter = & $ReWriter->CallWriter; @@ -1217,7 +1200,7 @@ class Doku_Handler_Table { } function tableStart($call) { - $this->tableCalls[] = array('table_open',array(),$call[2]); + $this->tableCalls[] = array('table_open',$call[1],$call[2]); $this->tableCalls[] = array('tablerow_open',array(),$call[2]); $this->firstCell = true; } @@ -1288,6 +1271,7 @@ class Doku_Handler_Table { // Adjust to num cols not num col delimeters $this->tableCalls[0][1][] = $this->maxCols - 1; $this->tableCalls[0][1][] = $this->maxRows; + $this->tableCalls[0][1][] = array_shift($this->tableCalls[0][1]); } else { trigger_error('First element in table call list is not table_open'); } @@ -1505,13 +1489,7 @@ class Doku_Handler_Block { //remove the whole paragraph array_splice($this->calls,$i); }else{ - if ($this->calls[count($this->calls)-1][0] == 'section_edit') { - $tmp = array_pop($this->calls); - $this->calls[] = array('p_close',array(), $pos); - $this->calls[] = $tmp; - } else { - $this->calls[] = array('p_close',array(), $pos); - } + $this->calls[] = array('p_close',array(), $pos); } $this->inParagraph = false; diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 65dcaf8a1..393099003 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -85,8 +85,6 @@ class Doku_Renderer extends DokuWiki_Plugin { function header($text, $level, $pos) {} - function section_edit($start, $end, $level, $name) {} - function section_open($level) {} function section_close() {} @@ -231,9 +229,9 @@ class Doku_Renderer extends DokuWiki_Plugin { $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL ) {} - function table_open($maxcols = NULL, $numrows = NULL){} + function table_open($maxcols = NULL, $numrows = NULL, $pos){} - function table_close($begin, $end){} + function table_close($pos){} function tablerow_open(){} diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 4e848ec1d..ef62a3df9 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -29,6 +29,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { var $doc = ''; // will contain the whole document var $toc = array(); // will contain the Table of Contents + private $sectionedits = array(); // A stack of section edit data var $headers = array(); var $footnotes = array(); @@ -39,6 +40,34 @@ class Doku_Renderer_xhtml extends Doku_Renderer { var $_counter = array(); // used as global counter, introduced for table classes var $_codeblock = 0; // counts the code and file blocks, used to provide download links + /** + * Register a new edit section range + * + * @param $type string The section type identifier + * @param $title string The section title + * @param $start int The byte position for the edit start + * @return string A marker class for the starting HTML element + * @author Adrian Lang <lang@cosmocode.de> + */ + protected function startSectionEdit($start, $type, $title) { + static $lastsecid = 0; + $this->sectionedits[] = array(++$lastsecid, $start, $type, $title); + return 'sectionedit' . $lastsecid; + } + + /** + * Finish an edit section range + * + * @param $pos int The byte position for the edit end + * @author Adrian Lang <lang@cosmocode.de> + */ + protected function finishSectionEdit($end) { + list($id, $start, $type, $title) = array_pop($this->sectionedits); + $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' "' . + str_replace('"', '', $title) . "\" [$start-" . + ($end === 0 ? '' : $end) . "] -->"; + } + function getFormat(){ return 'xhtml'; } @@ -51,6 +80,17 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } function document_end() { + // Finish open section edits. + while (count($this->sectionedits) > 0) { + if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { + // If there is only one section, do not write a section edit + // marker. + array_pop($this->sectionedits); + } else { + $this->finishSectionEdit(0); + } + } + if ( count ($this->footnotes) > 0 ) { $this->doc .= '<div class="footnotes">'.DOKU_LF; @@ -106,6 +146,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } function header($text, $level, $pos) { + global $conf; + if(!$text) return; //skip empty headlines $hid = $this->_headerToLink($text,true); @@ -122,30 +164,24 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } $this->lastlevel = $level; + if ($level <= $conf['maxseclevel'] && + count($this->sectionedits) > 0 && + $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') { + $this->finishSectionEdit($pos); + } + // write the header - $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; + $this->doc .= DOKU_LF.'<h'.$level; + if ($level <= $conf['maxseclevel']) { + $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"'; + } + $this->doc .= '><a name="'.$hid.'" id="'.$hid.'">'; $this->doc .= $this->_xmlEntities($text); $this->doc .= "</a></h$level>".DOKU_LF; } - /** - * Section edit marker is replaced by an edit button when - * the page is editable. Replacement done in 'inc/html.php#html_secedit' - * - * @author Andreas Gohr <andi@splitbrain.org> - * @author Ben Coburn <btcoburn@silicodon.net> - */ - function section_edit($start, $end, $level, $name) { - global $conf; - - if ($start!=-1 && $level<=$conf['maxseclevel']) { - $name = str_replace('"', '', $name); - $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; - } - } - function section_open($level) { - $this->doc .= "<div class=\"level$level\">".DOKU_LF; + $this->doc .= "<div class='level$level'>".DOKU_LF; } function section_close() { @@ -845,15 +881,16 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } // $numrows not yet implemented - function table_open($maxcols = NULL, $numrows = NULL){ + function table_open($maxcols = NULL, $numrows = NULL, $pos){ + global $lang; // initialize the row counter used for classes $this->_counter['row_counter'] = 0; - $this->doc .= '<table class="inline">'.DOKU_LF; + $this->doc .= '<table class="inline ' . $this->startSectionEdit($pos, 'table', $lang['table_edit_title']) . '">'.DOKU_LF; } - function table_close($begin, $end){ + function table_close($pos){ $this->doc .= '</table>'.DOKU_LF; - $this->doc .= '<!-- TABLE ['. $begin .'-'.$end.'] -->'; + $this->finishSectionEdit($pos); } function tablerow_open(){ |