• 在线阅览md文件


    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>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174

    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118

    调用方式:https://ip:port/index.html?url=./monitor/index.md

  • 相关阅读:
    计算机毕业设计(附源码)python在线共享笔记系统
    JS中面向对象的程序设计
    chromium windows编译32位正式版
    Java进阶知识点总结
    Netty原理与基础
    多项式快速幂
    如何不加锁地将数据并发写入Apache Hudi?
    【C++】【Opencv】cv::warpAffine()仿射变换函数详解,实现平移、缩放和旋转等功能
    vue里面使用pdfjs-dist+fabric实现pdf电子签章!!!
    【高级算法设计与分析】实验2:单向与双向A*搜索算法
  • 原文地址:https://blog.csdn.net/f_h_h/article/details/133934268