From 46c146516a7c766009420f7cc75b4b2e3032a8d4 Mon Sep 17 00:00:00 2001 From: LarsDW223 Date: Sat, 3 Jun 2017 15:44:04 +0200 Subject: [PATCH] Added syntax tag option 'showCount'. If set, the number of occurrences of a word will be shown. Closes #30. --- syntax.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/syntax.php b/syntax.php index 5855c6e..cc5b2ed 100644 --- a/syntax.php +++ b/syntax.php @@ -15,6 +15,7 @@ require_once(DOKU_PLUGIN.'syntax.php'); class syntax_plugin_cloud extends DokuWiki_Syntax_Plugin { + protected $knownFlags = array('showCount'); function getType() { return 'substition'; } function getPType() { return 'block'; } @@ -37,19 +38,31 @@ function handle($match, $state, $pos, Doku_Handler $handler) { list($num, $ns) = explode('>', $match, 2); list($junk, $num) = explode(':', $num, 2); + $flags = null; + if (preg_match ('/\[.*\]/', $junk, $flags) === 1) { + $flags = trim ($flags [0], '[]'); + $found = explode(',', $flags); + $flags = array(); + foreach ($found as $flag) { + if (in_array($flag, $this->knownFlags)) { + // Actually we just set flags as present + // Later we might add values to flags like key=value pairs + $flags [$flag] = true; + } + } + } if (!is_numeric($num)) $num = 50; if(!is_null($ns)) $namespaces = explode('|', $ns); else $namespaces = null; - return array($type, $num, $namespaces); + return array($type, $num, $namespaces, $flags); } function render($mode, Doku_Renderer $renderer, $data) { global $conf; - list($type, $num, $namespaces) = $data; - + list($type, $num, $namespaces, $flags) = $data; if ($mode == 'xhtml') { if ($type == 'tag') { // we need the tag helper plugin @@ -122,6 +135,9 @@ function render($mode, Doku_Renderer $renderer, $data) { } } + if ($flags ['showCount'] === true) { + $name .= '('.$size.')'; + } $renderer->doc .= DOKU_TAB . '' . hsc($name) . '' . DOKU_LF; }