HTML5教程

wiki 引入markdown编辑器 html

本文主要是介绍wiki 引入markdown编辑器 html,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
{% extends 'layout/manage.html' %}
{% load static %}

{% block css %}
    <link rel="stylesheet" href="{% static 'plugins/editor_md/css/editormd.preview.min.css' %}">
    <style>
       .panel-default {
            margin-top: 10px;
        }

        .panel-default .panel-heading {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
        }

        .panel-body {
            padding: 0;
        }

        .title-list {
            border-right: 1px solid #dddddd;
            min-height: 500px;
        }

        .title-list ul {
            padding-left: 15px;
        }

        .title-list ul a {
            display: block;
            padding: 5px 0;
        }

        .content {
            border-left: 1px solid #dddddd;
            min-height: 600px;
            margin-left: -1px;
        }

    </style>
{% endblock %}

{% block content %}
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div><i class="fa fa-book" aria-hidden="true"></i>wiki知识库</div>
                <div class="function">
                        <a type="button" class="btn btn-success btn-xs"
                           href="{% url 'wiki_add' pro_id=request.dashuju.pro.id %}">
                            <i class="fa fa-plus-circle" aria-hidden="true"></i> 新建
                        </a>
                        {% if wiki_obj %}
                            <a type="button" class="btn btn-primary btn-xs"
                               href="{% url 'wiki_edit' pro_id=request.dashuju.pro.id  wiki_id=wiki_obj.id %}">
                                <i class="fa fa-edit" aria-hidden="true"></i> 编辑
                            </a>
                            <a type="button" class="btn btn-danger btn-xs"
                               href="{% url 'wiki_delete' pro_id=request.dashuju.pro.id wiki_id=wiki_obj.id %} ">
                                <i class="fa fa-trash" aria-hidden="true"></i> 删除
                            </a>
                        {% endif %}
                </div>
            </div>

            <div class="panel-body">
                <div class="col-sm-3 title-list">
                    <ul id = "catalog">
{#                        <li>#}
{#                            <a href="">目录1</a>#}
{#                            <ul>#}
{#                                <li>子目录</li>#}
{#                                <li>子目录</li>#}
{#                            </ul>#}
{#                        </li>#}
{#                        <li>#}
{#                            <a href="">目录2</a>#}
{#                        </li>#}
                    </ul>

                </div>
                <div class="col-sm-9 content">
                    {% if wiki_obj %}
                        <div id="previewMarkdown">
                            <textarea>{{ wiki_obj.content }}</textarea>
                        </div>

                     {% else %}
                    <div style="text-align: center;margin-top: 60px">
                        <h4>《{{request.dashuju.pro.name }}》 WIKI文档库</h4>
                        <a href="{% url 'wiki_add'  pro_id=request.dashuju.pro.id %}"><i class="fa fa-angellist"></i> 点击这里记录第一篇文档</a>
                    </div>
                  {% endif %}

                </div>

            </div>
        </div>
    </div>



{% endblock %}


{% block js %}
    <script src="{% static 'plugins/editor_md/editormd.min.js' %}"></script>
    <script src="{% static 'plugins/editor_md/lib/marked.min.js' %}"></script>
    <script src="{% static 'plugins/editor-md/lib/prettify.min.js' %}"></script>
    <script src="{% static 'plugins/editor-md/lib/raphael.min.js' %}"></script>
    <script src="{% static 'plugins/editor-md/lib/underscore.min.js' %}"></script>
    <script src="{% static 'plugins/editor-md/lib/sequence-diagram.min.js' %}"></script>
    <script src="{% static 'plugins/editor-md/lib/flowchart.min.js' %}"></script>
    <script src="{% static 'plugins/editor-md/lib/jquery.flowchart.min.js' %}"></script>

     <script>
        var WIKI_XIANGXI_URL="{% url 'wiki' pro_id=request.dashuju.pro.id %}";    //url 要加上“”号,结尾是;

        $(function () {
            initCatalog();
            initPreivewMarkdown();
        });

        function initPreivewMarkdown() {
            editormd.markdownToHTML("previewMarkdown", {
                htmlDecode: "style,script,iframe"
            });
        }

        function initCatalog() {
            $.ajax({
                url: "{% url 'wiki_catalog' pro_id=request.dashuju.pro.id %}",
                type:"GET",
                dataType:"JSON",
                success:function (res) {
                    //console.log(res);
                    if(res.status){
                        $.each(res.data, function (index,item) {
                            var href=WIKI_XIANGXI_URL+"?wiki_id="+item.id;
                            var li=  $("<li>").attr('id','id_'+item.id).append($('<a>').text(item.title).attr('href',href)).append($('<ul>'));
                            if(!item.parent_id){
                                $("#catalog").append(li);
                            }else{
                                $('#id_'+item.parent_id).children('ul').append(li);
                            }
                        })
                    }else {
                        alert("初始化目录失败");
                    }
                }
            })
        }

    </script>
{% endblock %}

这篇关于wiki 引入markdown编辑器 html的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!