1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Add a pair of special variables to aid debugging.

This commit is contained in:
Starbeamrainbowlabs 2016-03-20 17:05:16 +00:00
parent 42b66729b7
commit 1c6ace3492
3 changed files with 69 additions and 7 deletions

View file

@ -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 = "<table>
<tr><th>Key</th><th>Value</th></tr>\n";
foreach($params as $key => $value)
{
$variableValue .= "\t<tr><td>" . $this->escapeText($key) . "</td><td>" . $this->escapeText($value) . "</td></tr>\n";
}
$variableValue .= "</table>";
}
break;
case "#":
$variableValue = "<ol start=\"0\">\n";
$variableValue .= "\t<li>$env->page</li>\n";
foreach($this->paramStack as $curStackEntry)
{
$variableValue .= "\t<li>" . $curStackEntry["pagename"] . "</li>\n";
}
$variableValue .= "</ol>\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;

View file

@ -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
}
]

View file

@ -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 = "<table>
<tr><th>Key</th><th>Value</th></tr>\n";
foreach($params as $key => $value)
{
$variableValue .= "\t<tr><td>" . $this->escapeText($key) . "</td><td>" . $this->escapeText($value) . "</td></tr>\n";
}
$variableValue .= "</table>";
}
break;
case "#":
$variableValue = "<ol start=\"0\">\n";
$variableValue .= "\t<li>$env->page</li>\n";
foreach($this->paramStack as $curStackEntry)
{
$variableValue .= "\t<li>" . $curStackEntry["pagename"] . "</li>\n";
}
$variableValue .= "</ol>\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;