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

Link images to their sources, properly handling short image urls. Fixes #111.

This commit is contained in:
Starbeamrainbowlabs 2016-10-11 19:44:01 +01:00
parent 53f4f2227d
commit 9caadadc66
3 changed files with 42 additions and 12 deletions

View file

@ -4941,7 +4941,7 @@ register_module([
register_module([
"name" => "Parsedown",
"version" => "0.9.6",
"version" => "0.9.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 some weight to your installation, and also *requires* write access to the disk on first load.",
"id" => "parser-parsedown",
@ -5352,6 +5352,7 @@ class PeppermintParsedown extends ParsedownExtra
$floatDirection = false;
$imageSize = false;
$imageCaption = false;
$shortImageUrl = false;
if($this->isFloatValue($param1))
{
@ -5395,8 +5396,8 @@ class PeppermintParsedown extends ParsedownExtra
if(isset($pageindex->$imageUrl) and $pageindex->$imageUrl->uploadedfile)
{
//echo("Found pageindex entry: "); var_dump($pageindex->$imageUrl->uploadedfile);
// We have a short url! Expand it.
$shortImageUrl = $imageUrl;
$imageUrl = "index.php?action=preview&size=" . max($imageSize["x"], $imageSize["y"]) ."&page=" . rawurlencode($imageUrl);
}
@ -5459,6 +5460,20 @@ class PeppermintParsedown extends ParsedownExtra
break;
}
// ~ Image linker ~
$imageHref = $shortImageUrl !== false ? "?page=" . rawurlencode($shortImageUrl) : $imageUrl;
$result["element"] = [
"name" => "a",
"attributes" => [
"href" => $imageHref
],
"text" => [$result["element"]],
"handler" => "elements"
];
// ~
if($imageCaption)
{
$rawStyle = $result["element"]["attributes"]["style"];
@ -5466,6 +5481,9 @@ class PeppermintParsedown extends ParsedownExtra
$mediaStyle = preg_replace('/\s*float.*;/', "", $rawStyle);
$result["element"] = [
"name" => "figure",
"attributes" => [
"style" => $containerStyle
],
"text" => [
$result["element"],
[
@ -5473,9 +5491,6 @@ class PeppermintParsedown extends ParsedownExtra
"text" => $altText
],
],
"attributes" => [
"style" => $containerStyle
],
"handler" => "elements"
];
$result["element"]["text"][0]["attributes"]["style"] = $mediaStyle;

View file

@ -199,11 +199,11 @@
},
{
"name": "Parsedown",
"version": "0.9.6",
"version": "0.9.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 some weight to your installation, and also *requires* write access to the disk on first load.",
"id": "parser-parsedown",
"lastupdate": 1476814064,
"lastupdate": 1476814092,
"optional": false
}
]

View file

@ -1,7 +1,7 @@
<?php
register_module([
"name" => "Parsedown",
"version" => "0.9.6",
"version" => "0.9.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 some weight to your installation, and also *requires* write access to the disk on first load.",
"id" => "parser-parsedown",
@ -412,6 +412,7 @@ class PeppermintParsedown extends ParsedownExtra
$floatDirection = false;
$imageSize = false;
$imageCaption = false;
$shortImageUrl = false;
if($this->isFloatValue($param1))
{
@ -455,8 +456,8 @@ class PeppermintParsedown extends ParsedownExtra
if(isset($pageindex->$imageUrl) and $pageindex->$imageUrl->uploadedfile)
{
//echo("Found pageindex entry: "); var_dump($pageindex->$imageUrl->uploadedfile);
// We have a short url! Expand it.
$shortImageUrl = $imageUrl;
$imageUrl = "index.php?action=preview&size=" . max($imageSize["x"], $imageSize["y"]) ."&page=" . rawurlencode($imageUrl);
}
@ -519,6 +520,20 @@ class PeppermintParsedown extends ParsedownExtra
break;
}
// ~ Image linker ~
$imageHref = $shortImageUrl !== false ? "?page=" . rawurlencode($shortImageUrl) : $imageUrl;
$result["element"] = [
"name" => "a",
"attributes" => [
"href" => $imageHref
],
"text" => [$result["element"]],
"handler" => "elements"
];
// ~
if($imageCaption)
{
$rawStyle = $result["element"]["attributes"]["style"];
@ -526,6 +541,9 @@ class PeppermintParsedown extends ParsedownExtra
$mediaStyle = preg_replace('/\s*float.*;/', "", $rawStyle);
$result["element"] = [
"name" => "figure",
"attributes" => [
"style" => $containerStyle
],
"text" => [
$result["element"],
[
@ -533,9 +551,6 @@ class PeppermintParsedown extends ParsedownExtra
"text" => $altText
],
],
"attributes" => [
"style" => $containerStyle
],
"handler" => "elements"
];
$result["element"]["text"][0]["attributes"]["style"] = $mediaStyle;