Fiddle with parsedown versions, remove ParsedownExtreme, and add our own checkbox implementation

This commit is contained in:
Starbeamrainbowlabs 2020-05-23 02:06:59 +01:00
parent a0f6e89643
commit 04bb67f505
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 58 additions and 7 deletions

View File

@ -6,6 +6,16 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
### Added
- [Module Api] Add new `search::invindex_term_getpageids`, and `search::invindex_term_getoffsets`, and `search::index_sort_freq` methods
- Added new syntax features to PeppermintParsedown, inspired by ParsedownExtreme (which we couldn't get to work, and it wasn't working before as far as I can tell)
- Checkboxes: `[ ]` and `[x]` after a bullet point or at the start of a line
- TODO: Update the help text in parser-parsedown
- TODO: Look through the ParsedownExtreme / ParsedownExtended README and pick out the extra syntax we like and implement it
### Changed
- Fiddled with Parsedown & ParsedownExtra versions
- Removed ParsedownExtreme, as it wasn't doing anything useful anyway
- Don't worry, we've absorbed all the useful features (see above)
## v0.21

View File

@ -8,12 +8,15 @@ register_module([
/********** Parsedown versions **********
* Parsedown Core: 1.8.0-beta-7 *
* Parsedown Extra: 0.8.0-beta-1 *
* Parsedown Extreme: 0.1.6 *
* Parsedown Extreme: 0.1.6 *removed* *
****************************************/
"Parsedown.php" => "https://raw.githubusercontent.com/erusev/parsedown/3825db53a2be5d9ce54436a9cc557c6bdce1808a/Parsedown.php",
"ParsedownExtra.php" => "https://raw.githubusercontent.com/erusev/parsedown-extra/352d03d941fc801724e82e49424ff409175261fd/ParsedownExtra.php",
"ParsedownExtreme.php" => "https://raw.githubusercontent.com/BenjaminHoegh/parsedown-extreme/adae4136534ad1e4159fe04c74c4683681855b84/ParsedownExtreme.php"
// TODO: Add Parsedown Extreme support
"Parsedown.php" => "https://raw.githubusercontent.com/erusev/parsedown/1610e4747c88a53676f94f752b447f4eff03c28d/Parsedown.php",
// "ParsedownExtra.php" => "https://raw.githubusercontent.com/erusev/parsedown-extra/91ac3ff98f0cea243bdccc688df43810f044dcef/ParsedownExtra.php",
// "Parsedown.php" => "https://raw.githubusercontent.com/erusev/parsedown/3825db53a2be5d9ce54436a9cc557c6bdce1808a/Parsedown.php",
"ParsedownExtra.php" => "https://raw.githubusercontent.com/erusev/parsedown-extra/352d03d941fc801724e82e49424ff409175261fd/ParsedownExtra.php"
// Parsedown Extreme is causing PHP 7.4+ errors, and isn't rendering correctly with the security features we have turned on.
// "ParsedownExtended.php" => "https://raw.githubusercontent.com/BenjaminHoegh/ParsedownExtended/8e1224e61a199cb513c47398353a27f6ba822da6/ParsedownExtended.php"
// "ParsedownExtreme.php" => "https://raw.githubusercontent.com/BenjaminHoegh/parsedown-extreme/adae4136534ad1e4159fe04c74c4683681855b84/ParsedownExtreme.php"
],
"id" => "parser-parsedown",
"code" => function() {
@ -428,7 +431,7 @@ Insert text here
require_once("$paths->extra_data_directory/parser-parsedown/Parsedown.php");
require_once("$paths->extra_data_directory/parser-parsedown/ParsedownExtra.php");
require_once("$paths->extra_data_directory/parser-parsedown/ParsedownExtreme.php");
// require_once("$paths->extra_data_directory/parser-parsedown/ParsedownExtended.php");
/**
* Attempts to 'auto-correct' a page name by trying different capitalisation
@ -468,7 +471,7 @@ function parsedown_pagename_resolve($pagename) {
/**
* The Peppermint-flavoured Parsedown parser.
*/
class PeppermintParsedown extends ParsedownExtreme
class PeppermintParsedown extends ParsedownExtra
{
/**
* The base directory with which internal links will be resolved.
@ -491,6 +494,8 @@ class PeppermintParsedown extends ParsedownExtreme
// Prioritise our internal link parsing over the regular link parsing
array_unshift($this->InlineTypes["["], "InternalLink");
// Prioritise the checkbox handling - this is fine 'cause it doesn't step on InternalLink's toes
array_unshift($this->InlineTypes["["], "Checkbox");
// Prioritise our image parser over the regular image parser
array_unshift($this->InlineTypes["!"], "ExtendedImage");
@ -703,6 +708,42 @@ class PeppermintParsedown extends ParsedownExtreme
];
}
/*
* ██████ ██ ██ ███████ ██████ ██ ██ ██████ ██████ ██ ██
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ███████ █████ ██ █████ ██████ ██ ██ ███
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██████ ██ ██ ███████ ██████ ██ ██ ██████ ██████ ██ ██
*/
protected function inlineCheckbox($fragment) {
// We're not interested if it's not at the beginning of a line
if(strpos($fragment["context"], $fragment["text"]) !== 0)
return;
// If it doesn't match, then we're not interested
if(preg_match('/\[([ x])\]/u', $fragment["text"], $matches) !== 1)
return;
$checkbox_content = $matches[1];
$result = [
"extent" => 3,
"element" => [
"name" => "input",
"attributes" => [
"type" => "checkbox",
"disabled" => "disabled"
]
]
];
if($checkbox_content === "x")
$result["element"]["attributes"]["checked"] = "checked";
return $result;
}
/*
* ██ ███ ██ ████████ ███████ ██████ ███ ██ █████ ██
* ██ ████ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██