Flask轻博客系统实战开发(10) 一 集成Editor.md支持markdown在线编辑

欢迎关注原创视频教程

Python微信订餐小程序课程视频

https://edu.csdn.net/course/detail/36074

Python实战量化交易理财系统

https://edu.csdn.net/course/detail/35475
首先支持在线编辑markdown编辑,作为技术人通常使用markdown写文档还是比较顺手的,因为格式统一,不需要花很多的时间在排版上,我选用了国内editor.md作为本博客的编辑器,下面就对editor.md的集成做下简单介绍

文章编辑界面

{% extends 'admin/common/base.html' %}
{% block css %}
{
  { super() }}
<link rel="stylesheet" href="{
    {url_for('.static',filename='editor_md/editormd.min.css')}}">
<link rel="stylesheet" href="{
    {url_for('.static',filename='css/write.css')}}">
{% endblock %}
{% block js %}
{
  { super() }}
<script src="{
    {url_for('.static',filename='editor_md/editormd.min.js')}}"></script>
<script>

    var imagehosting_for = "thumbnail-img";
    //图床
    function imagehosting(flag) {
     
        imagehosting_for = flag;
        layer.open({
     
            type: 2,
            title: '图片管理',
            shade: 0.8,
            maxmin: true,
            shadeClose: true,
            area: ['80%', '90%'],
            content: '{
     {url_for("admin.image_hosting")}}' //这里content是一个URL,如果你不想让iframe出现滚动条,你还可以content: ['http://sentsin.com', 'no']
        });
    }

    function imagehosting_callback(obj) {
     
        //缩略图
        if(imagehosting_for === 'thumbnail-img') {
     
            $('#thumbnail-img').attr('src', obj.img_url);
            $('#thumbnail').val(obj.img_url);
        }
        //编辑器 editor.md
        if(imagehosting_for === 'editor-img') {
     
            console.log(myEditor)
            myEditor.settings.imagehosting_callback(obj)
        }

    }

    var myEditor;
    $(function () {
     
        myEditor = editormd("write-editor", {
     
            // width: '100%',
            height: '450px',
            syncScrolling: "single",
            path: "{
     {url_for('.static',filename='editor_md/lib/')}}",
            emoji: true,//emoji表情,默认关闭
            watch: true, // 关闭实时预览
            taskList: true,
            tocm: true, // Using [TOCM]
            tex: true,// 开启科学公式TeX语言支持,默认关闭
            //flowChart: true,//开启流程图支持,默认关闭
            //sequenceDiagram: true,//开启时序/序列图支持,默认关闭,
            //启动本地图片上传功能
            imageUpload: true,
            // imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
            // imageUploadURL: "{
     {url_for('.upload')}}",
            toolbarIcons: function () {
     
                // Or return editormd.toolbarModes[name]; // full, simple, mini
                // Using "||" set icons align right.
                // ["undo", "redo", "|", "bold", "del", "italic", "quote", "|", "h1", "h2", "h3", "h4",
                //     "h5", "h6", "|", "list-ul", "list-ol", "hr", "|", "link", "reference-link", "image",
                //     "code", "code-block", "table", "datetime", "html-entities", "goto-line", "search", "||",
                //     "fullscreen", "watch", "preview", "info", "|", "publish"]
                return ["bold", "del", "italic", "quote", "|", "h2", "h3", "h4",
                    "|", "list-ul", "list-ol", "hr", "|", "link", "reference-link", "image",
                    "code", "code-block", "table", "|", "watch", "fullscreen"]
            },
            imagehosting: function () {
     
                imagehosting('editor-img');
            },
            imagehosting_callback:function(obj) {
     

            }
        });

        function save(state) {
     
            $.ajax({
     
                url: '{
     {url_for("admin.write")}}',
                type: "post"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虚坏叔叔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值