summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorAdrian Lang <mail@adrianlang.de>2011-04-22 22:35:43 +0200
committerAdrian Lang <mail@adrianlang.de>2011-04-22 22:35:43 +0200
commit8ccf9c9785ec2b626bad30a88a21f02886845418 (patch)
tree0ecd6103880e3350bd37ba11ae3872805ede1755 /inc/parser
parente2092379b1c3200832cb569781ec647db5aeef0f (diff)
parent23d27376b2a2f6a1ccf0777c48435717494d85b1 (diff)
downloadrpg-8ccf9c9785ec2b626bad30a88a21f02886845418.tar.gz
rpg-8ccf9c9785ec2b626bad30a88a21f02886845418.tar.bz2
Merge branch 'master' into stable
Conflicts: data/deleted.files doku.php lib/exe/xmlrpc.php
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/handler.php255
-rw-r--r--inc/parser/lexer.php2
-rw-r--r--inc/parser/metadata.php7
-rw-r--r--inc/parser/parser.php11
-rw-r--r--inc/parser/renderer.php2
-rw-r--r--inc/parser/xhtml.php15
-rw-r--r--inc/parser/xhtmlsummary.php2
7 files changed, 108 insertions, 186 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index a96e6b9db..22a50d1b7 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -720,6 +720,7 @@ class Doku_Handler_CallWriter {
// function is required, but since this call writer is first/highest in
// the chain it is not required to do anything
function finalise() {
+ unset($this->Handler);
}
}
@@ -764,6 +765,7 @@ class Doku_Handler_Nest {
$this->process();
$this->CallWriter->finalise();
+ unset($this->CallWriter);
}
function process() {
@@ -817,6 +819,7 @@ class Doku_Handler_List {
$this->process();
$this->CallWriter->finalise();
+ unset($this->CallWriter);
}
//------------------------------------------------------------------------
@@ -1014,6 +1017,7 @@ class Doku_Handler_Preformatted {
$this->process();
$this->CallWriter->finalise();
+ unset($this->CallWriter);
}
function process() {
@@ -1070,6 +1074,7 @@ class Doku_Handler_Quote {
$this->process();
$this->CallWriter->finalise();
+ unset($this->CallWriter);
}
function process() {
@@ -1165,6 +1170,7 @@ class Doku_Handler_Table {
$this->process();
$this->CallWriter->finalise();
+ unset($this->CallWriter);
}
//------------------------------------------------------------------------
@@ -1427,14 +1433,8 @@ class Doku_Handler_Table {
* @author Harry Fuecks <hfuecks@gmail.com>
*/
class Doku_Handler_Block {
-
var $calls = array();
-
- var $blockStack = array();
-
- var $inParagraph = false;
- var $atStart = true;
- var $skipEolKey = -1;
+ var $skipEol = false;
// Blocks these should not be inside paragraphs
var $blockOpen = array(
@@ -1442,9 +1442,9 @@ class Doku_Handler_Block {
'listu_open','listo_open','listitem_open','listcontent_open',
'table_open','tablerow_open','tablecell_open','tableheader_open',
'quote_open',
- 'section_open', // Needed to prevent p_open between header and section_open
'code','file','hr','preformatted','rss',
'htmlblock','phpblock',
+ 'footnote_open',
);
var $blockClose = array(
@@ -1452,18 +1452,18 @@ class Doku_Handler_Block {
'listu_close','listo_close','listitem_close','listcontent_close',
'table_close','tablerow_close','tablecell_close','tableheader_close',
'quote_close',
- 'section_close', // Needed to prevent p_close after section_close
'code','file','hr','preformatted','rss',
'htmlblock','phpblock',
+ 'footnote_close',
);
// Stacks can contain paragraphs
var $stackOpen = array(
- 'footnote_open','section_open',
+ 'section_open',
);
var $stackClose = array(
- 'footnote_close','section_close',
+ 'section_close',
);
@@ -1489,6 +1489,13 @@ class Doku_Handler_Block {
}
}
+ function openParagraph($pos){
+ if ($this->inParagraph) return;
+ $this->calls[] = array('p_open',array(), $pos);
+ $this->inParagraph = true;
+ $this->skipEol = true;
+ }
+
/**
* Close a paragraph if needed
*
@@ -1496,7 +1503,8 @@ class Doku_Handler_Block {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- function closeParagraph($pos){
+ function closeParagraph($pos){
+ if (!$this->inParagraph) return;
// look back if there was any content - we don't want empty paragraphs
$content = '';
for($i=count($this->calls)-1; $i>=0; $i--){
@@ -1513,11 +1521,29 @@ class Doku_Handler_Block {
if(trim($content)==''){
//remove the whole paragraph
array_splice($this->calls,$i);
- }else{
+ }else{
+ // remove ending linebreaks in the paragraph
+ $i=count($this->calls)-1;
+ if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL);
$this->calls[] = array('p_close',array(), $pos);
}
- $this->inParagraph = false;
+ $this->inParagraph = false;
+ $this->skipEol = true;
+ }
+
+ function addCall($call) {
+ $key = count($this->calls);
+ if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
+ $this->calls[$key-1][1][0] .= $call[1][0];
+ } else {
+ $this->calls[] = $call;
+ }
+ }
+
+ // simple version of addCall, without checking cdata
+ function storeCall($call) {
+ $this->calls[] = $call;
}
/**
@@ -1525,186 +1551,71 @@ class Doku_Handler_Block {
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
- * @todo This thing is really messy and should be rewritten
*/
function process($calls) {
+ // open first paragraph
+ $this->openParagraph(0);
foreach ( $calls as $key => $call ) {
$cname = $call[0];
- if($cname == 'plugin') {
+ if ($cname == 'plugin') {
$cname='plugin_'.$call[1][0];
-
$plugin = true;
$plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));
$plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));
} else {
$plugin = false;
}
-
- // Process blocks which are stack like... (contain linefeeds)
+ /* stack */
+ if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) {
+ $this->closeParagraph($call[2]);
+ $this->storeCall($call);
+ $this->openParagraph($call[2]);
+ continue;
+ }
if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) {
-
- // Hack - footnotes shouldn't immediately contain a p_open
- if ($this->addToStack($cname != 'footnote_open')) {
- $this->closeParagraph($call[2]);
- }
- $this->calls[] = $call;
-
+ $this->closeParagraph($call[2]);
+ $this->storeCall($call);
+ $this->openParagraph($call[2]);
continue;
}
-
- if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) {
-
- if ( $this->inParagraph ) {
- $this->closeParagraph($call[2]);
- }
- $this->calls[] = $call;
- if ($this->removeFromStack()) {
- $this->calls[] = array('p_open',array(), $call[2]);
- }
+ /* block */
+ // If it's a substition it opens and closes at the same call.
+ // To make sure next paragraph is correctly started, let close go first.
+ if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
+ $this->closeParagraph($call[2]);
+ $this->storeCall($call);
+ $this->openParagraph($call[2]);
continue;
}
-
- if ( !$this->atStart ) {
-
- if ( $cname == 'eol' ) {
-
- // Check this isn't an eol instruction to skip...
- if ( $this->skipEolKey != $key ) {
- // Look to see if the next instruction is an EOL
- if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
-
- if ( $this->inParagraph ) {
- //$this->calls[] = array('p_close',array(), $call[2]);
- $this->closeParagraph($call[2]);
- }
-
- $this->calls[] = array('p_open',array(), $call[2]);
- $this->inParagraph = true;
-
-
- // Mark the next instruction for skipping
- $this->skipEolKey = $key+1;
-
- }else{
- //if this is just a single eol make a space from it
- $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
- }
- }
-
-
- } else {
-
- $storeCall = true;
- if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) {
+ if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) {
+ $this->closeParagraph($call[2]);
+ $this->storeCall($call);
+ continue;
+ }
+ /* eol */
+ if ( $cname == 'eol' ) {
+ // Check this isn't an eol instruction to skip...
+ if ( !$this->skipEol ) {
+ // Next is EOL => double eol => mark as paragraph
+ if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
$this->closeParagraph($call[2]);
- $this->calls[] = $call;
- $storeCall = false;
- }
-
- if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
- if ( $this->inParagraph ) {
- $this->closeParagraph($call[2]);
- }
- if ( $storeCall ) {
- $this->calls[] = $call;
- $storeCall = false;
- }
-
- // This really sucks and suggests this whole class sucks but...
- if ( isset($calls[$key+1])) {
- $cname_plusone = $calls[$key+1][0];
- if ($cname_plusone == 'plugin') {
- $cname_plusone = 'plugin'.$calls[$key+1][1][0];
-
- // plugin test, true if plugin has a state which precludes it requiring blockOpen or blockClose
- $plugin_plusone = true;
- $plugin_test = ($call[$key+1][1][2] == DOKU_LEXER_MATCHED) || ($call[$key+1][1][2] == DOKU_LEXER_MATCHED);
- } else {
- $plugin_plusone = false;
- }
- if ((!in_array($cname_plusone, $this->blockOpen) && !in_array($cname_plusone, $this->blockClose)) ||
- ($plugin_plusone && $plugin_test)
- ) {
-
- $this->calls[] = array('p_open',array(), $call[2]);
- $this->inParagraph = true;
- }
- }
- }
-
- if ( $storeCall ) {
- $this->addCall($call);
- }
-
- }
-
-
- } else {
-
- // Unless there's already a block at the start, start a paragraph
- if ( !in_array($cname,$this->blockOpen) ) {
- $this->calls[] = array('p_open',array(), $call[2]);
- if ( $call[0] != 'eol' ) {
- $this->calls[] = $call;
+ $this->openParagraph($call[2]);
+ } else {
+ //if this is just a single eol make a space from it
+ $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
}
- $this->atStart = false;
- $this->inParagraph = true;
- } else {
- $this->addCall($call);
- $this->atStart = false;
}
-
- }
-
- }
-
- if ( $this->inParagraph ) {
- if ( $cname == 'p_open' ) {
- // Ditch the last call
- array_pop($this->calls);
- } else if ( !in_array($cname, $this->blockClose) ) {
- //$this->calls[] = array('p_close',array(), $call[2]);
- $this->closeParagraph($call[2]);
- } else {
- $last_call = array_pop($this->calls);
- //$this->calls[] = array('p_close',array(), $call[2]);
- $this->closeParagraph($call[2]);
- $this->calls[] = $last_call;
+ continue;
}
+ /* normal */
+ $this->addCall($call);
+ $this->skipEol = false;
}
-
+ // close last paragraph
+ $call = end($this->calls);
+ $this->closeParagraph($call[2]);
return $this->calls;
}
-
- /**
- *
- * @return bool true when a p_close() is required
- */
- function addToStack($newStart = true) {
- $ret = $this->inParagraph;
- $this->blockStack[] = array($this->atStart, $this->inParagraph);
- $this->atStart = $newStart;
- $this->inParagraph = false;
-
- return $ret;
- }
-
- function removeFromStack() {
- $state = array_pop($this->blockStack);
- $this->atStart = $state[0];
- $this->inParagraph = $state[1];
-
- return $this->inParagraph;
- }
-
- function addCall($call) {
- $key = count($this->calls);
- if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
- $this->calls[$key-1][1][0] .= $call[1][0];
- } else {
- $this->calls[] = $call;
- }
- }
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :
diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php
index 211945d8f..b5bcb9612 100644
--- a/inc/parser/lexer.php
+++ b/inc/parser/lexer.php
@@ -597,4 +597,4 @@ function Doku_Lexer_Escape($str) {
return preg_replace($chars, $escaped, $str);
}
-//Setup VIM: ex: et ts=4 sw=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 sw=4 :
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php
index f635ea1d5..fc2c8cbc5 100644
--- a/inc/parser/metadata.php
+++ b/inc/parser/metadata.php
@@ -45,6 +45,9 @@ class Doku_Renderer_metadata extends Doku_Renderer {
if(!$this->persistent['date']['created']){
$this->persistent['date']['created'] = filectime(wikiFN($ID));
}
+ if(!isset($this->persistent['user'])){
+ $this->persistent['user'] = '';
+ }
if(!isset($this->persistent['creator'])){
$this->persistent['creator'] = '';
}
@@ -461,7 +464,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
} else if (is_string($title)){
return $title;
} else if (is_array($title)){
- return '['.$title['title'].']';
+ if($title['title']) return '['.$title['title'].']';
}
}
@@ -479,4 +482,4 @@ class Doku_Renderer_metadata extends Doku_Renderer {
}
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 20f0e6ca3..68d4e4569 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -90,7 +90,6 @@ class Doku_Parser {
if ( $mode == 'base' ) {
continue;
}
-
$this->modes[$mode]->preConnect();
foreach ( array_keys($this->modes) as $cm ) {
@@ -218,11 +217,11 @@ class Doku_Parser_Mode_footnote extends Doku_Parser_Mode {
//-------------------------------------------------------------------
class Doku_Parser_Mode_header extends Doku_Parser_Mode {
- function preConnect() {
+ function connectTo($mode) {
//we're not picky about the closing ones, two are enough
$this->Lexer->addSpecialPattern(
'[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)',
- 'base',
+ $mode,
'header'
);
}
@@ -829,7 +828,7 @@ class Doku_Parser_Mode_internallink extends Doku_Parser_Mode {
function connectTo($mode) {
// Word boundaries?
- $this->Lexer->addSpecialPattern("\[\[.+?\]\]",$mode,'internallink');
+ $this->Lexer->addSpecialPattern("\[\[(?:(?:[^[\]]*?\[.*?\])|.*?)\]\]",$mode,'internallink');
}
function getSort() {
@@ -871,7 +870,7 @@ class Doku_Parser_Mode_externallink extends Doku_Parser_Mode {
if(count($this->patterns)) return;
$ltrs = '\w';
- $gunk = '/\#~:.?+=&%@!\-';
+ $gunk = '/\#~:.?+=&%@!\-\[\]';
$punc = '.:?\-;,';
$host = $ltrs.$punc;
$any = $ltrs.$gunk.$punc;
@@ -957,4 +956,4 @@ class Doku_Parser_Mode_emaillink extends Doku_Parser_Mode {
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index a178b2457..7002fd0cb 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -319,4 +319,4 @@ class Doku_Renderer extends DokuWiki_Plugin {
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 37900b2c3..ab295dd01 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -574,11 +574,20 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$params = $parts[1];
}
+ // For empty $id we need to know the current $ID
+ // We need this check because _simpleTitle needs
+ // correct $id and resolve_pageid() use cleanID($id)
+ // (some things could be lost)
+ if ($id === '') {
+ $id = $ID;
+ }
+
// default name is based on $id as given
$default = $this->_simpleTitle($id);
// now first resolve and clean up the $id
resolve_pageid(getNS($ID),$id,$exists);
+
$name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
if ( !$isImage ) {
if ( $exists ) {
@@ -734,9 +743,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$name = $this->_getLinkTitle($name, '', $isImage);
if ( !$isImage ) {
- $link['class']='mail JSnocheck';
+ $link['class']='mail';
} else {
- $link['class']='media JSnocheck';
+ $link['class']='media';
}
$address = $this->_xmlEntities($address);
@@ -1205,4 +1214,4 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :
diff --git a/inc/parser/xhtmlsummary.php b/inc/parser/xhtmlsummary.php
index b187fef01..95f86cbef 100644
--- a/inc/parser/xhtmlsummary.php
+++ b/inc/parser/xhtmlsummary.php
@@ -87,4 +87,4 @@ class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
}
-//Setup VIM: ex: et ts=2 enc=utf-8 :
+//Setup VIM: ex: et ts=2 :