summaryrefslogtreecommitdiff
path: root/inc/parser/xhtml.php
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-02-04 14:50:10 +0100
committerAdrian Lang <lang@cosmocode.de>2010-02-04 15:37:17 +0100
commit90df9a4d69a2e467433b419b94fe799d11590539 (patch)
treebe212d380d1aafd710370d5c12df0e71b6fdfbac /inc/parser/xhtml.php
parent1807fcf5084f3bda9cef9580a624b9afed38b559 (diff)
downloadrpg-90df9a4d69a2e467433b419b94fe799d11590539.tar.gz
rpg-90df9a4d69a2e467433b419b94fe799d11590539.tar.bz2
Rewrite section edit handling according to #1860
Diffstat (limited to 'inc/parser/xhtml.php')
-rw-r--r--inc/parser/xhtml.php81
1 files changed, 59 insertions, 22 deletions
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(){