markdown 自己搞一个浏览工具

时间:2023-03-09 08:48:31
markdown 自己搞一个浏览工具

注意! 下不能有空行 上也不能有空行 问题未解决

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery.min.js"></script>
<script src="markdown.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<style> code {
margin:0;
padding:1em;
background:#F9F9F9;
border:1px dashed #2F6FAB;
display:block;
white-space:pre;
font-family:"Courier New", Courier, monospace;
color:#666;
line-height:1.5;
overflow:auto;
}
</style>
</head>
<body>
<?php
session_start();
if (isset($_GET['mdpsd'])) {
if ($_GET['mdpsd'] != "xienaizhong") {
} else {
$_SESSION['loginmd'] = "1";
}
header("Location:/doc");
}
if ($_SESSION['loginmd'] != "1") {
exit("<form method='get'><input name='mdpsd'><input type='submit' value='提交'></form>");
} ?> <textarea id="text-input" oninput="this.editor.update()"
rows="6" cols="60" style="display: none;"><?php include $_GET['f'] . ""; ?></textarea>
<div id="preview"></div> <script>
function Editor(input, preview) {
this.update = function () {
preview.innerHTML = markdown.toHTML(input.value);
};
input.editor = this;
this.update();
}
var $ = function (id) {
return document.getElementById(id);
};
new Editor($("text-input"), $("preview")); </script> <hr>
<?php
$dir = __DIR__;
$file = scandir($dir);
$index = 1;
foreach ($file as $x) {
if (strpos($x, ".md") >= 1) {
echo "<a href='/doc?f=" . $x . "'>" . $x . "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
if ($index % 4 == 0) {
echo "<br>";
}
$index = $index +1;
}
}
?> </body>
</html>