mirror of
https://github.com/til-schneider/slim-wiki.git
synced 2025-08-12 11:34:11 +02:00
Staying in edit mode when user clicks on local links
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user