add: markdown preview

This commit is contained in:
quenousimporte 2024-02-19 12:20:20 +01:00
parent 2ce4cbeef6
commit f8b2ee3942
2 changed files with 1729 additions and 7 deletions

View File

@ -41,6 +41,9 @@
exit; exit;
} }
require 'libs/Parsedown.php';
$homelink = '<a accesskey="h" href="' . $root . '">home</a>&nbsp;';
$action = ''; $action = '';
if (isset($_POST['action'])) $action = $_POST['action']; if (isset($_POST['action'])) $action = $_POST['action'];
else if (isset($_GET['action'])) $action = $_GET['action']; else if (isset($_GET['action'])) $action = $_GET['action'];
@ -70,7 +73,15 @@
rename($dir . '/' . $title, $dir . '/' . $title . '.del'); rename($dir . '/' . $title, $dir . '/' . $title . '.del');
} }
if ($action == 'open') if ($action == 'preview')
{
$title = $_POST['title'];
$content = $_POST['content'];
$Parsedown = new Parsedown();
$Parsedown->setBreaksEnabled(true);
echo $Parsedown->text('# ' . $title . "\r\n" . $content);
}
else if ($action == 'open')
{ {
$now = date("Y-m-d H.i.s", time()); $now = date("Y-m-d H.i.s", time());
if (!$param) if (!$param)
@ -94,11 +105,11 @@
$length = strlen($content); $length = strlen($content);
echo '<form action="index.php" method="POST"> echo '<form action="index.php" method="POST">
<div> <div>' . $homelink .
<a accesskey="h" href="' . $root . '">home</a> '<select name="action">
<select name="action">
<option value="save">save</option> <option value="save">save</option>
<option value="delete">delete</option> <option value="delete">delete</option>
<option value="preview">preview</option>
</select> </select>
<input class="title" name="title" value="' . $param . '"> <input class="title" name="title" value="' . $param . '">
<input type="submit" name="go" value="go" accesskey="s"> <input type="submit" name="go" value="go" accesskey="s">
@ -139,9 +150,8 @@
} }
else else
{ {
echo '<form action="index.php" method="GET"> echo '<form action="index.php" method="GET">' .$homelink .
<a accesskey="h" href="' . $root . '">home</a> '<select name="action">
<select name="action">
<option ' . ($action == 'open' ? 'selected' : '') . ' value="open">open</option> <option ' . ($action == 'open' ? 'selected' : '') . ' value="open">open</option>
<option ' . ($action == 'filter' ? 'selected' : '') . ' value="filter">filter</option> <option ' . ($action == 'filter' ? 'selected' : '') . ' value="filter">filter</option>
<option ' . ($action == 'search' ? 'selected' : '') . ' value="search">search</option> <option ' . ($action == 'search' ? 'selected' : '') . ' value="search">search</option>

1712
libs/Parsedown.php Normal file

File diff suppressed because it is too large Load Diff