Allow linking in internal links to subheadings.
This commit is contained in:
parent
1abc963efd
commit
16076a8d8f
|
@ -5040,7 +5040,7 @@ class PeppermintParsedown extends ParsedownExtra
|
||||||
|
|
||||||
protected function inlineInternalLink($fragment)
|
protected function inlineInternalLink($fragment)
|
||||||
{
|
{
|
||||||
global $pageindex;
|
global $pageindex, $env;
|
||||||
|
|
||||||
if(preg_match('/^\[\[([^\]]*)\]\]/', $fragment["text"], $matches))
|
if(preg_match('/^\[\[([^\]]*)\]\]/', $fragment["text"], $matches))
|
||||||
{
|
{
|
||||||
|
@ -5053,6 +5053,18 @@ class PeppermintParsedown extends ParsedownExtra
|
||||||
$display = trim($parts[1]); // The text to display
|
$display = trim($parts[1]); // The text to display
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hashCode = "";
|
||||||
|
if(strpos($linkPage, "#") !== false)
|
||||||
|
{
|
||||||
|
// We want to link to a subsection of a page
|
||||||
|
$hashCode = substr($linkPage, strpos($linkPage, "#") + 1);
|
||||||
|
$linkPage = substr($linkPage, 0, strpos($linkPage, "#"));
|
||||||
|
|
||||||
|
// If $linkPage is empty then we want to link to the current page
|
||||||
|
if(strlen($linkPage) === 0)
|
||||||
|
$linkPage = $env->page;
|
||||||
|
}
|
||||||
|
|
||||||
// If the page doesn't exist, check varying different
|
// If the page doesn't exist, check varying different
|
||||||
// capitalisations to see if it exists under some variant.
|
// capitalisations to see if it exists under some variant.
|
||||||
if(empty($pageindex->$linkPage))
|
if(empty($pageindex->$linkPage))
|
||||||
|
@ -5070,6 +5082,9 @@ class PeppermintParsedown extends ParsedownExtra
|
||||||
$this->internalLinkBase
|
$this->internalLinkBase
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(strlen($hashCode) > 0)
|
||||||
|
$linkUrl .= "#$hashCode";
|
||||||
|
|
||||||
$result = [
|
$result = [
|
||||||
"extent" => strlen($matches[0]),
|
"extent" => strlen($matches[0]),
|
||||||
"element" => [
|
"element" => [
|
|
@ -203,7 +203,7 @@
|
||||||
"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, and also *requires* write access to the disk on first load.",
|
"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",
|
"id": "parser-parsedown",
|
||||||
"lastupdate": 1471599779,
|
"lastupdate": 1471631572,
|
||||||
"optional": false
|
"optional": false
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -82,7 +82,7 @@ register_module([
|
||||||
$pageindex->$new_name->$key = $value;
|
$pageindex->$new_name->$key = $value;
|
||||||
}
|
}
|
||||||
unset($pageindex->$page);
|
unset($pageindex->$page);
|
||||||
$pageindex->$new_name->filename = $new_name;
|
$pageindex->$new_name->filename = "$new_name.md";
|
||||||
|
|
||||||
// If this page has an associated file, then we should move that too
|
// If this page has an associated file, then we should move that too
|
||||||
if(!empty($pageindex->$new_name->uploadedfile))
|
if(!empty($pageindex->$new_name->uploadedfile))
|
|
@ -295,7 +295,7 @@ class PeppermintParsedown extends ParsedownExtra
|
||||||
|
|
||||||
protected function inlineInternalLink($fragment)
|
protected function inlineInternalLink($fragment)
|
||||||
{
|
{
|
||||||
global $pageindex;
|
global $pageindex, $env;
|
||||||
|
|
||||||
if(preg_match('/^\[\[([^\]]*)\]\]/', $fragment["text"], $matches))
|
if(preg_match('/^\[\[([^\]]*)\]\]/', $fragment["text"], $matches))
|
||||||
{
|
{
|
||||||
|
@ -308,6 +308,18 @@ class PeppermintParsedown extends ParsedownExtra
|
||||||
$display = trim($parts[1]); // The text to display
|
$display = trim($parts[1]); // The text to display
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hashCode = "";
|
||||||
|
if(strpos($linkPage, "#") !== false)
|
||||||
|
{
|
||||||
|
// We want to link to a subsection of a page
|
||||||
|
$hashCode = substr($linkPage, strpos($linkPage, "#") + 1);
|
||||||
|
$linkPage = substr($linkPage, 0, strpos($linkPage, "#"));
|
||||||
|
|
||||||
|
// If $linkPage is empty then we want to link to the current page
|
||||||
|
if(strlen($linkPage) === 0)
|
||||||
|
$linkPage = $env->page;
|
||||||
|
}
|
||||||
|
|
||||||
// If the page doesn't exist, check varying different
|
// If the page doesn't exist, check varying different
|
||||||
// capitalisations to see if it exists under some variant.
|
// capitalisations to see if it exists under some variant.
|
||||||
if(empty($pageindex->$linkPage))
|
if(empty($pageindex->$linkPage))
|
||||||
|
@ -325,6 +337,9 @@ class PeppermintParsedown extends ParsedownExtra
|
||||||
$this->internalLinkBase
|
$this->internalLinkBase
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(strlen($hashCode) > 0)
|
||||||
|
$linkUrl .= "#$hashCode";
|
||||||
|
|
||||||
$result = [
|
$result = [
|
||||||
"extent" => strlen($matches[0]),
|
"extent" => strlen($matches[0]),
|
||||||
"element" => [
|
"element" => [
|
Loading…
Reference in New Issue