javaweb项目集成editor.md编辑器—markdown编辑器

javaweb项目集成editor.md编辑器—markdown编辑器最近写一个博客系统,需要集成编辑器,所以我就打算集成一个markdown编辑器用来编辑文章。在网上搜,好像editor.md这个国产开源的markdown编辑器比较好。不过想吐槽是网上的教程真的。。。哈哈哈,开始我们的教程:1.首先在editor.md官网(http://pandao.github.io/editor.md/)下载这一个编辑器。这是下载好后的文件目录2.将目录下的css目

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

最近写一个博客系统,需要集成编辑器,所以我就打算集成一个markdown编辑器用来编辑文章。在网上搜,好像editor.md这个国产开源的markdown编辑器比较好。不过想吐槽是网上的教程真的。。。哈哈哈,开始我们的教程:
1.首先在editor.md官网(http://pandao.github.io/editor.md/)下载这一个编辑器。
这是下载好后的文件目录

这里写图片描述
2.将目录下的css目录,images目录,lib目录,plugins目录,src目录以及example目录中的css目录,js目录和整合一下
这里写图片描述
3.将提取后的文件放在你项目的静态文件夹中,我用的idea,我放在web目录下的static文件夹中,
写一个html如下

<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="utf-8" />
        <title>Simple example - Editor.md examples</title>
        <link rel="stylesheet" href="/static/Admin/editor/css/style.css" />
        <link rel="stylesheet" href="/static/Admin/editor/css/editormd.css" />
        <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="/static/Public/css/bootstrap_button.css">\
        <style> #submit_button{ display:block; margin-left: 42%; margin-top: 2em; margin-bottom: 2em; } .input{ display: block; margin-left: 20%; } </style>
    </head>
    <body>
        <div id="layout">
            <div id="my-editormd" >
                 <textarea id="my-editormd-markdown-doc" name="my-editormd-markdown-doc" style="display:none;"></textarea>
                <!-- 注意:name属性的值-->
                <textarea id="my-editormd-html-code" name="my-editormd-html-code" style="display:none;"></textarea>
            </div>
            <button class="button button-block button-rounded button-action button-large" id="submit_button">确认提交</button>

        </div>

        <script src="/static/Public/jquery.js"></script>
        <script src="/static/Admin/editor/js/editormd.js"></script>
        <script type="text/javascript"> <!--为了让editor.md编辑器完整的显示出来--> var testEditor; $(function() { 
     testEditor = editormd("my-editormd", { width : "90%", height : 640, syncScrolling : "single", path : "/static/Admin/editor/lib/", saveHTMLToTextarea : true }); }); <!--然后用ajax将编辑器中的md格式的数据提交到后台,存储在数据库中,有的人可能存储的是html格式的,也行,这个看你自己的选择了,不过存储.md格式还是要好一点--> $("#submit_button").click(function () { $.ajax({ type: "post", url: "", data: { content:$("#my-editormd-html-code").val(), }, contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType: "json", success: function (data) { }, error:function () { } }); }); </script>
    </body>
</html>

4.第三步是为了把数据存储到数据库中,这一步那就是将数据库存储的数据在前端显示。
同样的写个jsp文件如下

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh">
<head>
    <meta charset="utf-8" />
    <title>HTML Preview(markdown to html) - Editor.md examples</title>
    <link rel="stylesheet" href="/static/Admin/editor/css/style.css" />
    <link rel="stylesheet" href="/static/Admin/editor/css/editormd.preview.css" />
    <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
    <style> .editormd-html-preview { width: 90%; margin: 0 auto; padding-top: 9em; } </style>
</head>
<body>
<div id="layout">
    <div id="test-editormd-view">
        <textarea style="display:none;" name="test-editormd-markdown-doc"></textarea>
    </div>
    <div id="test-editormd-view2">
                <%--存放md数据--%>
                <textarea id="append-test" style="display:none;">
                    ${articleContent}
                </textarea>
    </div>
</div>
<script src="/static/Public/jquery.js"></script>
<script src="/static/Admin/editor/lib/marked.min.js"></script>
<script src="/static/Admin/editor/lib/prettify.min.js"></script>
<script src="/static/Admin/editor/lib/raphael.min.js"></script>
<script src="/static/Admin/editor/lib/underscore.min.js"></script>
<script src="/static/Admin/editor/lib/sequence-diagram.min.js"></script>
<script src="/static/Admin/editor/lib/flowchart.min.js"></script>
<script src="/static/Admin/editor/lib/jquery.flowchart.min.js"></script>
<script src="/static/Admin/editor/js/editormd.js"></script>
<script type="text/javascript"> $(function() { 
     var testEditormdView, testEditormdView2; $.get("test.md", function(markdown) { 
     testEditormdView = editormd.markdownToHTML("test-editormd-view", { markdown : markdown ,//+ "\r\n" + $("#append-test").text(), htmlDecode : "style,script,iframe", // you can filter tags decode tocm : true, // Using [TOCM] // markdownSourceCode : true, // 是否保留 Markdown 源码,即是否删除保存源码的 Textarea 标签 emoji : true, taskList : true, tex : true, // 默认不解析 flowChart : true, // 默认不解析 sequenceDiagram : true, // 默认不解析 }); // 获取Markdown源码 //console.log(testEditormdView.getMarkdown()); //alert(testEditormdView.getMarkdown()); }); testEditormdView2 = editormd.markdownToHTML("test-editormd-view2", { htmlDecode : "style,script,iframe", // you can filter tags decode emoji : true, taskList : true, tex : true, // 默认不解析 flowChart : true, // 默认不解析 sequenceDiagram : true, // 默认不解析 }); }); </script>
</body>
</html>

上面几步都是我从我的项目里抽出来的代码,真实可用。
5.关于编辑器拓展功能的实现我就不多说了,这方面度娘上的文章很多了。

以上只是用源代码说明一下,怎样在Javaweb项目中集成editor.md编辑器,知识很浅,只是希望有些童鞋能少走些弯路。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/192674.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • mysql通配符转义_转义MySQL通配符

    mysql通配符转义_转义MySQL通配符小编典典_而%不是通配符在MySQL一般,而且不应该被转义,将它们放入普通的字符串字面量的目的。mysql_real_escape_string是正确的,足以满足此目的。addcslashes不应该使用。_并且%仅在LIKE-matching上下文中是特殊的。当您想为LIKE语句中的文字使用准备字符串时,要100%匹配百分之一百,而不仅仅是以100开头的任何字符串,都需要担心两种转义。首先是喜欢转…

    2022年6月16日
    44
  • 【Unity3D插件】Unity3D各类教程汇总「建议收藏」

    推荐阅读CSDN主页GitHub开源地址Unity3D插件分享简书地址我的个人博客QQ群:1040082875一、工具篇工欲善其事,必先利其器学习Unity3D不从工具篇说起怎么能行?学习Unity3D最重要的两个工具:Unity3D和VisualStudio(VisualStudioCode也行)1-1、Unity3D安装Unity安装个人免费版步骤详解(通过UnityHub安装unity,是比较流行的安装方式)https://blog.csdn.net/fi.

    2022年4月14日
    55
  • Windows系统重装Linux系统

    Windows系统重装Linux系统PC机以前是Windows系统现在重装Linux系统材料:8G以上U盘(eveything版本很大,如果U盘容量不足请选择DVD版本ISO)UltralSOLinux系统(Centos7_64_eveything.iso)tips:准…

    2022年6月28日
    54
  • Java内存管理-探索Java中字符串String(十二)

    做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!文章目录一、初识String类二、字符串的不可变性三、字符串常量池和 intern 方法四、面试题1、 String s1 = new String(“hello”);这句话创建了几个字符串对象?2、有时候在面试的时候会遇到这样的问题:**都说String是不可变的,为什么我可以这样做呢,String a = “1”…

    2022年2月28日
    37
  • qtcpsocket用法_qtcpsocket发送16进制数据

    qtcpsocket用法_qtcpsocket发送16进制数据在QTcpSocket中的tcp通信,发送数据,接收数据都是QTcpSocket套接字的功能,包括server端,QTcpServer的功能仅仅是作为一个服务器的存在;客户端:classClient:publicQWidget{Q_OBJECTpublic:explicitClient(QWidget*parent=0);~Cl…

    2025年10月17日
    2
  • 当黑客说:我入侵了你的电脑,并拍下你看XXOO的画面时,你该怎么办?[通俗易懂]

    当黑客说:我入侵了你的电脑,并拍下你看XXOO的画面时,你该怎么办?[通俗易懂]以后浏览某些网站时,一定要记得把你的前置摄像头遮住,否则,你可能会被敲诈~底下这封邮件,可能会让那些没遮住摄像头的朋友们心慌慌~(不喜欢看英文的童鞋请移步图下,编辑为你贴…

    2022年7月17日
    10

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号