From 1c6ace34927db522b8ed9b52b1cfad1161f0c457 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 20 Mar 2016 17:05:16 +0000 Subject: [PATCH] Add a pair of special variables to aid debugging. --- build/index.php | 37 +++++++++++++++++++++++++++++++++--- module_index.json | 2 +- modules/parser-parsedown.php | 37 +++++++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/build/index.php b/build/index.php index d902bef..c776e7d 100644 --- a/build/index.php +++ b/build/index.php @@ -3803,15 +3803,43 @@ class PeppermintParsedown extends ParsedownExtra protected function inlineTemplate($fragment) { + global $env; + // Variable parsing if(preg_match("/\{\{\{([^}]+)\}\}\}/", $fragment["text"], $matches)) { + $stackEntry = array_slice($this->paramStack, -1)[0]; + $params = !empty($stackEntry) ? $stackEntry["params"] : false; + $variableKey = trim($matches[1]); $variableValue = false; - if(isset(array_slice($this->paramStack, -1)[0][$variableKey])) + switch ($variableKey) { - $variableValue = array_slice($this->paramStack, -1)[0][$variableKey]; + case "@": + if(!empty($params)) + { + $variableValue = " + \n"; + foreach($params as $key => $value) + { + $variableValue .= "\t\n"; + } + $variableValue .= "
KeyValue
" . $this->escapeText($key) . "" . $this->escapeText($value) . "
"; + } + break; + case "#": + $variableValue = "
    \n"; + $variableValue .= "\t
  1. $env->page
  2. \n"; + foreach($this->paramStack as $curStackEntry) + { + $variableValue .= "\t
  3. " . $curStackEntry["pagename"] . "
  4. \n"; + } + $variableValue .= "
\n"; + } + if(isset($params[$variableKey])) + { + $variableValue = $params[$variableKey]; $variableValue = $this->escapeText($variableValue); } @@ -3874,7 +3902,10 @@ class PeppermintParsedown extends ParsedownExtra } } // Add the parsed parameters to the parameter stack - $this->paramStack[] = $params; + $this->paramStack[] = [ + "pagename" => $templatePagename, + "params" => $params + ]; $templateFilePath = $paths->storage_prefix . $pageindex->$templatePagename->filename; diff --git a/module_index.json b/module_index.json index feb4351..e51d12f 100644 --- a/module_index.json +++ b/module_index.json @@ -194,7 +194,7 @@ "author": "Emanuil Rusev & Starbeamrainbowlabs", "description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds a some weight to your installation, and also *requires* write access to the disk on first load.", "id": "parser-parsedown", - "lastupdate": 1458492103, + "lastupdate": 1458493193, "optional": false } ] \ No newline at end of file diff --git a/modules/parser-parsedown.php b/modules/parser-parsedown.php index 579749d..0bbb5f4 100644 --- a/modules/parser-parsedown.php +++ b/modules/parser-parsedown.php @@ -81,15 +81,43 @@ class PeppermintParsedown extends ParsedownExtra protected function inlineTemplate($fragment) { + global $env; + // Variable parsing if(preg_match("/\{\{\{([^}]+)\}\}\}/", $fragment["text"], $matches)) { + $stackEntry = array_slice($this->paramStack, -1)[0]; + $params = !empty($stackEntry) ? $stackEntry["params"] : false; + $variableKey = trim($matches[1]); $variableValue = false; - if(isset(array_slice($this->paramStack, -1)[0][$variableKey])) + switch ($variableKey) { - $variableValue = array_slice($this->paramStack, -1)[0][$variableKey]; + case "@": + if(!empty($params)) + { + $variableValue = " + \n"; + foreach($params as $key => $value) + { + $variableValue .= "\t\n"; + } + $variableValue .= "
KeyValue
" . $this->escapeText($key) . "" . $this->escapeText($value) . "
"; + } + break; + case "#": + $variableValue = "
    \n"; + $variableValue .= "\t
  1. $env->page
  2. \n"; + foreach($this->paramStack as $curStackEntry) + { + $variableValue .= "\t
  3. " . $curStackEntry["pagename"] . "
  4. \n"; + } + $variableValue .= "
\n"; + } + if(isset($params[$variableKey])) + { + $variableValue = $params[$variableKey]; $variableValue = $this->escapeText($variableValue); } @@ -152,7 +180,10 @@ class PeppermintParsedown extends ParsedownExtra } } // Add the parsed parameters to the parameter stack - $this->paramStack[] = $params; + $this->paramStack[] = [ + "pagename" => $templatePagename, + "params" => $params + ]; $templateFilePath = $paths->storage_prefix . $pageindex->$templatePagename->filename;