diff --git a/helper.php b/helper.php index 9dca93b..7d71645 100644 --- a/helper.php +++ b/helper.php @@ -67,6 +67,7 @@ function getMethods() { * Overrides standard values for showfooter and firstseconly settings */ function get_flags($setflags) { + // load defaults $flags = $this->defaults; foreach ($setflags as $flag) { @@ -222,6 +223,10 @@ function get_flags($setflags) { case 'exclude': $flags['exclude'] = $value; break; + case 'parameters': + case 'params': + $flags['parameters'] = $this->_parse_parameter_string($value); + break; } } // the include_content URL parameter overrides flags @@ -230,6 +235,38 @@ function get_flags($setflags) { return $flags; } + /** + * Parse parameter flag value into array, to create 'dictionary' of replace values. + */ + function _parse_parameter_string($value) { + + $param_array = array(); + + $count = 0; + $value = preg_split('/(?_escape_value($value); + } else { + // There's no '=' character: This is unnamed parameter. + $count += 1; + $param_array[strval($count)] = $this->_escape_value($param); + } + } + + return $param_array; + } + + /** + * Escapes '\|', '\&', '\=', '\}' in parameter value. + */ + function _escape_value($value) { + return preg_replace('/\\\\([|&=}])/', '\1', $value); + } + + /** * Returns the converted instructions of a give page/section * @@ -315,7 +352,10 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $this->adapt_links($ins, $page, $included_pages); - for($i=0; $i<$num; $i++) { + for ($i=0; $i<$num; $i++) { + if (!isset($ins[$i][0])) { + continue; + } switch($ins[$i][0]) { case 'document_start': case 'document_end': @@ -370,6 +410,47 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc if (!$flags['inline'] && $flags['indent']) $ins[$i][1][1][4] += $lvl; break; + case 'include_placeholder': + if (!isset($flags['parameters'])) + break; + + if (array_key_exists($ins[$i][1][1][0], $flags['parameters'])) { + + // Call dokuwiki parser to get instructions of included text. + $included_ins = p_get_instructions($flags['parameters'][$ins[$i][1][1][0]]); + + // Get starting and ending position + for ($start=0; $start $conf['target']['wiki'], 'class' => $class . ' permalink', 'more' => 'rel="bookmark"', + 'pre' => '', + 'suf' => '' ); $xhtml[] = $renderer->_formatLink($link); } diff --git a/syntax/include.php b/syntax/include.php index 44b803a..d587de9 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -75,7 +75,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { $check = false; if (isset($sect)) $sect = sectionID($sect, $check); $level = NULL; - return array($mode, $page, $sect, explode('&', $flags), $level, $pos); + return array($mode, $page, $sect, explode('(?Lexer->addSpecialPattern("{{{.+?}}}", $mode, 'plugin_include_placeholder'); + } + + /** + * Handle syntax matches + * + * @param string $match The current match + * @param int $state The match state + * @param int $pos The position of the match + * @param Doku_Handler $handler The hanlder object + * @return array The instructions of the plugin + */ + function handle($match, $state, $pos, Doku_handler $handler) { + $name = substr($match, 3, -3); // strip markup + return array($name, $pos); + } + + /** + * Skip rendering of template field. + */ + function render($format, Doku_Renderer $renderer, $data) { + return true; + } + +} \ No newline at end of file