DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title id="title">Markdown Playertitle>
<link href="//cdn.bootcss.com/skeleton/2.0.4/skeleton.css" rel="stylesheet">
<script src="//cdn.bootcss.com/jquery/3.0.0-alpha1/jquery.js">script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1">
<script src="./server/marked.min.js">script>
<link rel="stylesheet" href="./server/github-markdown-light.min.css">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/index.css">
<script>
$.ajaxSetup({async: false});
script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/idea.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js">script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/go.min.js">script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css"
integrity="sha512-uf06llspW44/LZpHzHT6qBOIVODjWtv4MxCricRxkzvopAlSWnTf6hpZTFxuuZcuNE9CBQhqE0Seu1CoRk84nQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"
integrity="sha512-sSWQXoxIkE0G4/xqLngx5C53oOZCgFRxWE79CvMX2X0IKx14W3j9Dpz/2MpRh58xb2W/h+Y4WAHJQA0qMMuxJg=="
crossorigin="anonymous"
referrerpolicy="no-referrer">script>
head>
<body>
<div id="div_editor" class="markdown-body" contenteditable="true">div>
<br/> <br/> <br/>
<textarea id="textarea">
# Hello World
*Write* `your` **Markdown** here.
textarea>
<button id='save'>savebutton>
<div id="directory">
目录
<div id="content">
<ul>
<li class="li-h1" title="主题1"><a href="#222">主题1a>li>
<li class="li-h2" title="主题2"><a href="#222">主题2a>li>
<li class="li-h3" title="主题3"><a href="#222">主题3a>li>
<li class="li-h4" title="主题4"><a href="#222">主题4a>li>
<li class="li-h5" title="主题5"><a href="#222">主题5a>li>
ul>
div>
div>
<script>
textarea.innerHTML = marked.parse(textarea.value);
var editor
script>
<script>
editor = CodeMirror.fromTextArea(document.getElementById("textarea"), {//定义CodeMirror代码编辑器
lineNumbers: true, // 显示行号
indentUnit: 4, // 缩进单位为4
styleActiveLine: true, // 当前行背景高亮
matchBrackets: true, // 括号匹配
mode: 'java/javascript/html/go', // HMTL混合模式
lineWrapping: true, // 自动换行
theme: 'dracula', // 编辑器主题
});
editor.on('change', function (cm) {
div_editor.innerHTML = marked.parse(cm.getValue());
hljs.highlightAll();
init();
});
$('#div_editor').on('input', function () {
var value = $(this).html();
console.log('输入框的值变为:', value.length);
});
$("#save").click(function () {
console.log(editor.getValue())
});
function init() {
$("#div_editor a").click(function () {
window.open($(this).attr("href"))
});
let html = "";
let index = 0;
for (let h of $("#div_editor h1,h2,h3,h4,h5")) {
let id = index++;
h.id = id;
html += '- +
h.localName + '" title="' + h.innerText + '">+id+'">' + h.innerText + '';
}
$("#directory ul").html(html);
}
script>
<script>
function load(url) {
var s = $.get(url, function (text) {
div_editor.innerHTML = marked.parse(text);
editor.setValue(text);
init();
});
s.fail(function (a) {
console.log(a.status)
var error = '' + a.status + ''
body.innerHTML = error;
})
}
var url = getUrlParam(document.URL, "url");
url ? url : "index.md";
title.text = url;
load(url ? url : "index.md");
function getUrlParam(sUrl, sKey) {
sUrl = sUrl.toString();
let allUrl = sUrl.split("?")[1].split("#")[0];
if (sKey) {//指定参数名
var strs = allUrl.split("&")
var paramsArr = new Array()
for (var i = 0, len = strs.length; i < len; i++) {
var temp = strs[i].split("=")
if (temp[0] === sKey) {
paramsArr.push(temp[1])
}
}
if (paramsArr.length === 0) { //找不到指定参数
return ""
} else if (paramsArr.length === 1) { //只匹配到一个唯一key
return paramsArr[0]
} else { //多个同名参数key
return paramsArr
}
} else { //不指定参数名
if (allUrl === undefined || allUrl === "") { //路径无参
return {}
}
var strs = allUrl.split("&")
var objArr = new Object()
for (var i = 0, len = strs.length; i < len; i++) { //遍历所有参数值
var temp = strs[i].split("=")
if (!(temp[0] in objArr)) {
objArr[temp[0]] = []
}
objArr[temp[0]].push(temp[1])
}
return objArr
}
}
script>
div>
body>
html>
css/index.css
@media (max-width: 767px) {
body {
padding: 15px;
}
}
body {
box-sizing: border-box;
min-width: 200px;
max-width: 80%;
margin: 0 auto;
padding: 30px;
}
#directory {
padding: 10px 2px 10px 10px;
position: fixed;
top: 15%;
right: 4px;
width: 20%;
min-width: 150px;
max-width: 250px;
font-size: 20px;
max-height: 70%;
z-index: 100;
background: rgba(222, 222, 222, 0.8);
border-radius: 10px 0px 0px 10px;
font-weight: bold;
overflow-y: auto;
}
#directory li a {
text-wrap: nowrap;
cursor: pointer;
color: #0a0e14;
text-decoration: none;
display: -webkit-box;
text-overflow: ellipsis;
overflow: hidden;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
#directory li a::before {
content: '';
unicode-bidi: isolate;
font-variant-numeric: tabular-nums;
text-transform: none;
text-indent: 0px !important;
text-align: start !important;
text-align-last: start !important;
position: absolute;
top: 12px;
left: 5px;
width: 5px;
height: 5px;
border-radius: 50%;
border: 0.1px #555 solid;
}
#directory li.li-h1 a::before {
left: 2px
}
#directory li.li-h2 a::before {
left: 1.1em
}
#directory li.li-h3 a::before {
left: 2.2em
}
#directory li.li-h4 a::before {
top: 10px;
left: 3.3em;
}
#directory li.li-h5 a::before {
top: 10px;
left: 4em
}
#directory ul {
margin-bottom: 1.5rem;
}
#directory li {
margin: 0;
padding: 3px 0px;
position: relative;
font-size: 18px;
list-style: none;
}
#directory .li-h1 {
text-indent: 1em;
font-weight: 600;
font-size: 16px;
}
#directory .li-h2 {
text-indent: 2em;
font-weight: 600;
font-size: 16px;
}
#directory .li-h3 {
text-indent: 3em;
font-weight: 500;
font-size: 15px;
}
#directory .li-h4 {
text-indent: 4em;
font-weight: 400;
font-size: 14px;
}
#directory .li-h5 {
text-indent: 5em;
font-weight: 300;
font-size: 13px;
}
调用方式:https://ip:port/index.html?url=./monitor/index.md