From c2e4a04778087638a9863dd48232db48e619e352 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Tue, 18 Aug 2020 13:49:16 +0100
Subject: [PATCH] Fix #209

---
 Changelog.md                 |  3 +++
 docs/99-Making-A-Release.md  |  2 +-
 modules/page-edit.php        |  4 ++--
 modules/parser-parsedown.php | 18 ++++++++++++++----
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 70a529b..9b07ecc 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -12,6 +12,9 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
 ### Fixed
  - Hide the admin email address at the bottom of every page - we missed it in v0.22-beta1 (but got every other one though :P)
 
+### Changed
+ - Disable parser cache by default to avoid issues because said cache isn't invalidated when it should be (and doing so would take more of a performance hit than leaving it on)
+
 
 ## v0.22-beta1
 Make sure you have PHP 7.3+ when you update past this point! It isn't the end of the world if you don't, but it will make you more secure if you do.
diff --git a/docs/99-Making-A-Release.md b/docs/99-Making-A-Release.md
index 3f0d4d8..94465f0 100644
--- a/docs/99-Making-A-Release.md
+++ b/docs/99-Making-A-Release.md
@@ -43,7 +43,7 @@ You can update to this release simply by grabbing an updated copy of `index.php`
 
 For more information on the last 2 methods, please see [the documentation](https://starbeamrainbowlabs.com/labs/peppermint/__nightdocs/05-Getting-A-Copy.html) for more information.
 
-For those who want to contribute financially as a thank you, I've recently [setup a Liberapay](https://liberapay.com/sbrl) to accept donations. It's certainly not required, but would definitely help me out :-)
+For those who want to contribute financially as a thank you, I've recently [setup a Liberapay](https://liberapay.com/sbrl) to accept donations. It's certainly not required, but would definitely help me out :-) If you want to contribute but Liberapay isn't for you, please let me know (e.g. open an issue, see [my website for more contact options](https://starbeamrainbowlabs.com/))
 
 ## Since VERSION_NUMBER_HERE
 FULL_CHANGELOG_HERE
diff --git a/modules/page-edit.php b/modules/page-edit.php
index c217740..92436ba 100644
--- a/modules/page-edit.php
+++ b/modules/page-edit.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "Page editor",
-	"version" => "0.17.8",
+	"version" => "0.17.9",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
 	"id" => "page-edit",
@@ -236,7 +236,7 @@ window.addEventListener("load", function(event) {
 		});
 		
 		/**
-		 * @api {post} ?action=preview-edit&page={pageName}[&newpage=yes]	Get a preview of the page
+		 * @api {post} ?action=preview-edit&page={pageName}[&newpage=yes]	Get a preview of an edit to a page
 		 * @apiDescription	Gets a preview of the current edit state of a given page
 		 * @apiName 		PreviewPage
 		 * @apiGroup		Editing
diff --git a/modules/parser-parsedown.php b/modules/parser-parsedown.php
index c69e6af..6e4aa0c 100644
--- a/modules/parser-parsedown.php
+++ b/modules/parser-parsedown.php
@@ -760,14 +760,18 @@ class PeppermintParsedown extends ParsedownExtra
 		
 		$templateFilePath = $env->storage_prefix . $pageindex->$templatePagename->filename;
 		
-		$parsedTemplateSource = $this->text(file_get_contents($templateFilePath));
+		// We use linesElements here to avoid resetting $this->DefinitionData (which is done in ->textElements)
+		// Consequently, we have to do what textElements does directly
+		$parsedTemplateSource = $this->linesElements(explode("\n",
+			trim(str_replace(["\r\n", "\r"], "\n", file_get_contents($templateFilePath)), "\n")
+		));
 		
 		// Remove the parsed parameters from the stack
 		array_pop($this->paramStack);
 		
 		return [
 			"name" => "div",
-			"rawHtml" => $parsedTemplateSource,
+			"elements" => $parsedTemplateSource,
 			"attributes" => [
 				"class" => "template"
 			]
@@ -1257,8 +1261,14 @@ class PeppermintParsedown extends ParsedownExtra
 						$result["element"],
 						[
 							"name" => "figcaption",
-							// rawHtml is fine here 'cause we're using the output of $this->text(), which is safe
-							"rawHtml" => $this->text($altText),
+							// We use lineElements here because of issue #209 - in short it makes it appear as part of the same document to avoid breaking footnotes
+							// Specifically ->text() calls ->textElements(), which resets $this->DefinitionData, which is used to hold information about footnotes
+							// lineElements = inline text, and linesElements = multiline text
+							"handler" => [
+								"function" => "lineElements",
+								"argument" => $altText,
+								"destination" => "elements"
+							]
 						],
 					],
 					"handler" => "elements"
