1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-21 16:13:00 +00:00

parsedown: fix templating under circumstances

This commit is contained in:
Starbeamrainbowlabs 2023-01-26 20:51:07 +00:00
parent c6fb3cdd6e
commit 0e675f4c6f
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 15 additions and 4 deletions

View file

@ -5,6 +5,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
## v0.24-beta2 ## v0.24-beta2
- **Added:** `filter` GET parameter to the `list` action, which filters the list of pages to contain only those containing the specified substring. - **Added:** `filter` GET parameter to the `list` action, which filters the list of pages to contain only those containing the specified substring.
- **Fixed:** [Rest API] Documented `redirect` and `redirected_from` GET params to the `view` action. - **Fixed:** [Rest API] Documented `redirect` and `redirected_from` GET params to the `view` action.
- **Fixed:** Fixed bug where templating variables were not populated under some circumstances.
- **Fixed:** Typo on credits page - **Fixed:** Typo on credits page
## v0.24-beta1 ## v0.24-beta1

View file

@ -5,7 +5,7 @@
register_module([ register_module([
"name" => "Parsedown", "name" => "Parsedown",
"version" => "0.12.2", "version" => "0.12.3",
"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" => [
@ -589,7 +589,7 @@ class PeppermintParsedown extends ParsedownExtra
if(!empty($this->paramStack)) if(!empty($this->paramStack))
{ {
$stackEntry = array_slice($this->paramStack, -1)[0]; $stackEntry = array_slice($this->paramStack, -1)[0];
$params = !empty($stackEntry) ? $stackEntry["params"] : false; $params = !empty($stackEntry) ? $stackEntry["params"] : null;
} }
$variableKey = trim($matches[1]); $variableKey = trim($matches[1]);
@ -732,7 +732,7 @@ class PeppermintParsedown extends ParsedownExtra
// Extract the name of the template page // Extract the name of the template page
$templatePagename = array_shift($parts); $templatePagename = array_shift($parts);
// If the page that we are supposed to use as the tempalte doesn't // If the page that we are supposed to use as the template doesn't
// exist, then there's no point in continuing. // exist, then there's no point in continuing.
if(empty($pageindex->$templatePagename)) if(empty($pageindex->$templatePagename))
return false; return false;
@ -770,13 +770,23 @@ class PeppermintParsedown extends ParsedownExtra
$parsedTemplateSource = $this->linesElements(explode("\n", $parsedTemplateSource = $this->linesElements(explode("\n",
trim(str_replace(["\r\n", "\r"], "\n", file_get_contents($templateFilePath)), "\n") trim(str_replace(["\r\n", "\r"], "\n", file_get_contents($templateFilePath)), "\n")
)); ));
// Render it out. Important to preserve scope.
$parsedTemplateSource = $this->elements($parsedTemplateSource);
// HACK: Find/replace to ensure variables are inserted inside HTML. Note this does NOTE support special variables inside HTML - only simple ones.
// This would cause issues if we later allow variables to be unset.
foreach($params as $param_key => $param_value) {
$parsedTemplateSource = str_replace("{{{".$param_key."}}}", $param_value, $parsedTemplateSource);
}
// Remove the parsed parameters from the stack // Remove the parsed parameters from the stack
array_pop($this->paramStack); array_pop($this->paramStack);
return [ return [
"name" => "div", "name" => "div",
"elements" => $parsedTemplateSource, "element" => [
"rawHtml" => $parsedTemplateSource,
],
"attributes" => [ "attributes" => [
"class" => "template" "class" => "template"
] ]