mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Add experimental [display text](./Page Name.md) style internal links
This is transparently handled by a wrapper around inlineLink, which conditionally bails by returning the parent if parsing fails. It then ~~ab~~uses inlineInternalLink to provide proper internal link support. Fixes #190.
This commit is contained in:
parent
ffe1d37d4b
commit
26f5838ce0
3 changed files with 43 additions and 2 deletions
|
@ -42,8 +42,9 @@ _No changes were made since the last release_
|
|||
|
||||
### Added
|
||||
- Added dark theme via `prefers-color-scheme` to configuration guide (see the stable channel guide [here](https://starbeamrainbowlabs.com/labs/peppermint/peppermint-config-info.php) - will only be updated when v0.22 is released)
|
||||
- Added link thingy you can click next to each setting to jump right to it
|
||||
- Added link thingy you can click next to each setting to jump right to it
|
||||
- [docs] Documented the structure of `pageindex.json` and `recentchanges.json`
|
||||
- Experimental support for transparent handling of `[display text](./Page Name.md)` style internal links (disabled by default: enable the `parser_mangle_external_links` setting and delete the `._cache` directory to enable)
|
||||
|
||||
### Fixed
|
||||
- Obfuscate the admin email address at the bottom of every page - we missed it in v0.22-beta1 (but got every other one though :P) (#205)
|
||||
|
|
|
@ -449,6 +449,7 @@ require_once("$paths->extra_data_directory/parser-parsedown/ParsedownExtra.php")
|
|||
/**
|
||||
* Attempts to 'auto-correct' a page name by trying different capitalisation
|
||||
* combinations.
|
||||
*
|
||||
* @param string $pagename The page name to auto-correct.
|
||||
* @return string The auto-corrected page name.
|
||||
*/
|
||||
|
@ -1063,6 +1064,44 @@ class PeppermintParsedown extends ParsedownExtra
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
███ █████ ███ ██ ██ ██████ ███ ███ ██████ ██
|
||||
██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██
|
||||
██ ███████ ██ ██ ██ ██████ ██ ████ ██ ██ ██ ██
|
||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
███ ██ ██ ███ ██ ██ ██ ██████ ██ ██ ██ ██████ ██
|
||||
*/
|
||||
// This wraps the native [display text](url) syntax
|
||||
protected function inlineLink($fragment) {
|
||||
global $settings;
|
||||
|
||||
// If this feature is disabled, defer to the parent implementation unconditionally
|
||||
if(!$settings->parser_mangle_external_links)
|
||||
return parent::inlineLink($fragment);
|
||||
|
||||
// Extract the URL from the internal link. If it fails defer to the parent function
|
||||
// 1 = display text, 2 = url
|
||||
if(preg_match("/^\[([^[\]]+?)\]\(\s*([^()]+)\s*\)/", $fragment["text"], $matches) !== 1)
|
||||
return parent::inlineLink($fragment);
|
||||
|
||||
// Check the URL. If it doesn't match our *exact* format, then it doesn't happen.
|
||||
if(!is_string($matches[2]) || preg_match("/^\.\/(.+)\.md$/", $matches[2], $matches_url) !== 1)
|
||||
return parent::inlineLink($fragment);
|
||||
|
||||
// The page name is made safe when Pepperminty Wiki does initial consistency checks (if it's unsafe it results in a 301 redirect)
|
||||
$page_name = parsedown_pagename_resolve($matches_url[1]);
|
||||
|
||||
$internal_link_text = "[[${page_name}]]";
|
||||
if(!empty($matches[1])) // If the display text isn't empty, then respect it
|
||||
$internal_link_text = "[[${page_name}¦{$matches[1]}]]";
|
||||
|
||||
$result = $this->inlineInternalLink([
|
||||
"text" => $internal_link_text
|
||||
]);
|
||||
$result["extent"] = strlen($fragment["text"]); // Parsedown isn't mb_ friendly
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* ███████ ██ ██ ████████ ███████ ███ ██ ██████ ███████ ██████
|
||||
* ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
"parser_ext_time_limit": { "type": "number", "description": "The number of seconds external renderers are allowed to run for. Has no effect if external renderers are turned off. Also currently has no effect on Windows.", "default": 5 },
|
||||
"parser_ext_allow_anon": { "type": "checkbox", "description": "<p>Whether to allow anonymous users to render new diagrams with the external renderer. When disabled, anonymous users will still be allowed to recall pre-rendered items from the cache, but will be unable to generate brand-new diagrams.</p><p>Note that if you allow anonymous edits this setting won't fully protect you: anonymous users could edit a page and insert a malicious diagram, and then laer a logged in user could unwittingly invoke the external renderer on the anonymous user's behalf.", "default": false },
|
||||
"parser_toc_heading_level": { "type": "number", "description": "The level of heading to create when generating a table of contents. Corresponds directly with the HTML h1-h6 tags. A value of 0 disables the heading.", "default": 2 },
|
||||
"parser_mangle_external_links": { "type": "checkbox", "description": "Whether <code>[display text](./Page Name.md)</code> style links are transparently handled as internal links. Useful to increase compatibility to other systems that use this style of link such as <a href='https://js.wiki/'>Wiki.js</a>.", "default": false },
|
||||
"interwiki_index_location": { "type": "text", "description": "The location to find the interwiki wiki definition file, which contains a list of wikis along with their names, prefixes, and root urls. May be a URL, or simply a file path - as it's passed to file_get_contents(). If left blank, interwiki link parsing is disabled.", "default": null },
|
||||
"clean_raw_html": { "type": "checkbox", "description": "Whether page sources should be cleaned of HTML before rendering. It is STRONGLY recommended that you keep this option turned on.", "default": true },
|
||||
"all_untrusted": { "type": "checkbox", "description": "Whether to treat both page sources and comment text as untrusted input. Untrusted input has additional restrictions to protect against XSS attacks etc. Turn on if your wiki allows anonymous edits.", "default": false},
|
||||
|
@ -199,7 +200,7 @@
|
|||
]
|
||||
]},
|
||||
"comment_enabled": { "type": "checkbox", "description": "Whether commenting is enabled or not. If disabled, nobody will be able to post new comments, but existing comments will still be shown (if the <code>feature-comments</code> module is installed, of course - otherwise this setting will have no effect).", "default": true },
|
||||
"comment_hide_all": { "type": "checkbox ", "description": "Whether to hide all comments, as if the commenting feature never existed. If you want to enable this setting, consider using the downloader (link in the docs) to exclude the <code>feature-comments</code> module instead.", "default": false },
|
||||
"comment_hide_all": { "type": "checkbox", "description": "Whether to hide all comments, as if the commenting feature never existed. If you want to enable this setting, consider using the downloader (link in the docs) to exclude the <code>feature-comments</code> module instead.", "default": false },
|
||||
"anoncomments": { "type": "checkbox", "description": "Whether to allow anonymous user to make comments. Note that anonymous users are not able to delete their own comments (since they are not logged in, there's no way to know if they were the original poster or not)", "default": false },
|
||||
"comment_max_length": { "type": "number", "description": "The maximum allowed length, in characters, for comments", "default": 5000 },
|
||||
"comment_min_length": { "type": "number", "description": "The minimum allowed length, in characters, for comments", "default": 10 },
|
||||
|
|
Loading…
Reference in a new issue