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

parser-parsedown: fix templating

This commit is contained in:
Starbeamrainbowlabs 2020-08-08 01:54:10 +01:00
parent ddb7cd9c18
commit 3b799cbcba
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 19 additions and 16 deletions

View file

@ -57,6 +57,7 @@ Make sure you have PHP 7.3+ when you update past this point! It isn't the end of
- Removed annoying scrollbars when editing long pages - Removed annoying scrollbars when editing long pages
- Fixed an obscure warning when previewing PDFs (#202) - Fixed an obscure warning when previewing PDFs (#202)
- Ensure that the parent page exists when moving a page to be a child of a non-existent parent (#201) - Ensure that the parent page exists when moving a page to be a child of a non-existent parent (#201)
- Fixed templating (#203)
## v0.21.1-hotfix1 ## v0.21.1-hotfix1

View file

@ -1,7 +1,7 @@
<?php <?php
register_module([ register_module([
"name" => "Parsedown", "name" => "Parsedown",
"version" => "0.11", "version" => "0.11.1",
"author" => "Emanuil Rusev & Starbeamrainbowlabs", "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 some weight to your installation.", "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 some weight to your installation.",
"extra_data" => [ "extra_data" => [
@ -420,7 +420,7 @@ Insert text here
"; ";
foreach($settings->parser_ext_renderers as $code => $renderer) { foreach($settings->parser_ext_renderers as $code => $renderer) {
$row = array_map("htmlentities", [ $row = array_map(function($value) { return htmlentities($value, ENT_COMPAT|ENT_HTML5); }, [
$renderer->name, $renderer->name,
$code, $code,
$renderer->description, $renderer->description,
@ -589,27 +589,24 @@ class PeppermintParsedown extends ParsedownExtra
$variableKey = trim($matches[1]); $variableKey = trim($matches[1]);
$variableValue = false; $variableValue = false;
switch ($variableKey) switch ($variableKey) {
{
case "@": // Lists all variables and their values case "@": // Lists all variables and their values
if(!empty($params)) { if(!empty($params)) {
$variableValue = "<table> $variableValue = "<table>
<tr><th>Key</th><th>Value</th></tr>\n"; <tr><th>Key</th><th>Value</th></tr>\n";
foreach($params as $key => $value) foreach($params as $key => $value) {
{
$variableValue .= "\t<tr><td>" . $this->escapeText($key) . "</td><td>" . $this->escapeText($value) . "</td></tr>\n"; $variableValue .= "\t<tr><td>" . $this->escapeText($key) . "</td><td>" . $this->escapeText($value) . "</td></tr>\n";
} }
$variableValue .= "</table>"; $variableValue .= "</table>";
} }
else { else {
$variableValue = "<em>(no parameters have been specified)</em>"; $variableValue = "<em>(no variables are currently defined)</em>";
} }
break; break;
case "#": // Shows a stack trace case "#": // Shows a stack trace
$variableValue = "<ol start=\"0\">\n"; $variableValue = "<ol start=\"0\">\n";
$variableValue .= "\t<li>$env->page</li>\n"; $variableValue .= "\t<li>$env->page</li>\n";
foreach($this->paramStack as $curStackEntry) foreach($this->paramStack as $curStackEntry) {
{
$variableValue .= "\t<li>" . $curStackEntry["pagename"] . "</li>\n"; $variableValue .= "\t<li>" . $curStackEntry["pagename"] . "</li>\n";
} }
$variableValue .= "</ol>\n"; $variableValue .= "</ol>\n";
@ -656,10 +653,10 @@ class PeppermintParsedown extends ParsedownExtra
switch($previewType) switch($previewType)
{ {
case "video": case "video":
$previewHtml .= "<video src='$previewUrl' controls preload='metadata'>$pagename</video>\n"; $previewHtml .= "<video src='$previewUrl' controls preload='metadata'>".$this->escapeText($pagename)."</video>\n";
break; break;
case "audio": case "audio":
$previewHtml .= "<audio src='$previewUrl' controls preload='metadata'>$pagename</audio>\n"; $previewHtml .= "<audio src='$previewUrl' controls preload='metadata'>".$this->escapeText($pagename)."</audio>\n";
break; break;
case "pdf": case "pdf":
$previewHtml .= "<object type='application/pdf' data='$previewUrl' style='width: {$previewStyle}px;'></object>"; $previewHtml .= "<object type='application/pdf' data='$previewUrl' style='width: {$previewStyle}px;'></object>";
@ -682,16 +679,21 @@ class PeppermintParsedown extends ParsedownExtra
break; break;
} }
if(isset($params[$variableKey])) if(isset($params[$variableKey]))
{ $variableValue = $this->escapeText($params[$variableKey]);
$variableValue = $params[$variableKey];
$variableValue = $this->escapeText($variableValue);
}
if($variableValue !== false) if($variableValue !== false)
{ {
return [ return [
"extent" => strlen($matches[0]), "extent" => strlen($matches[0]),
"markup" => $variableValue "element" => [
"name" => "span",
"attributes" => [
"class" => "template-var-value"
],
// rawHtml is fine here 'cause we escape above
// Note also that we *must* return some sort of element here: we can't just return rawHtml directly. It needs to be a property of an element.
"rawHtml" => $variableValue
]
]; ];
} }
} }