1
0
mirror of https://github.com/til-schneider/slim-wiki.git synced 2025-08-12 03:24:02 +02:00

Staying in edit mode when user clicks on local links

This commit is contained in:
til-schneider
2015-12-22 22:50:08 +01:00
parent df95ea7f8e
commit fc285d8ad4
3 changed files with 18 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ class EditorService {
gzwrite ($fp, $markdownText); gzwrite ($fp, $markdownText);
gzclose($fp); gzclose($fp);
return $this->context->getRenderService()->renderMarkdown($markdownText); return $this->context->getRenderService()->renderMarkdown($markdownText, true);
} }
} }

View File

@@ -97,7 +97,7 @@ class Main {
$data['articleFilename'] = $articleFilename; $data['articleFilename'] = $articleFilename;
$articleMarkdown = file_get_contents($this->context->getArticleBaseDir() . $articleFilename); $articleMarkdown = file_get_contents($this->context->getArticleBaseDir() . $articleFilename);
$data['articleMarkdown'] = $articleMarkdown; $data['articleMarkdown'] = $articleMarkdown;
$data['articleHtml'] = $this->context->getRenderService()->renderMarkdown($articleMarkdown); $data['articleHtml'] = $this->context->getRenderService()->renderMarkdown($articleMarkdown, $isEditMode);
$this->renderPage($data); $this->renderPage($data);
} }

View File

@@ -2,9 +2,23 @@
class RenderService { class RenderService {
public function renderMarkdown($markdownText) { public function renderMarkdown($markdownText, $isEditMode) {
require_once __DIR__ . '/../lib/parsedown/Parsedown.php'; require_once __DIR__ . '/../lib/parsedown/Parsedown.php';
return Parsedown::instance()->text($markdownText); $html = Parsedown::instance()->text($markdownText);
if ($isEditMode) {
// Append `?edit` to local links (in order to stay in edit mode)
$html = preg_replace_callback('|(<a href="([^"]+))"|',
function($match) {
$url = $match[2];
$isLocalLink = ! strpos($url, '//');
if ($isLocalLink) {
return $match[1] . '?edit"';
} else {
return $match[0];
}
}, $html);
}
return $html;
} }
} }