当前位置:网站首页>解决Editor.md上传图片获取不到图片地址问题
解决Editor.md上传图片获取不到图片地址问题
2022-07-03 09:01:00 【科技那些事儿】
Editor.md图片上传获取不到图片地址,Editor.md图片上传iframe存在跨域情况,几经调试都不好用,最后采取替代方案,还不存在跨域情况。
最近项目中要支持markdown 编辑器,现在基本做技术的没有不知道Markdown 的,因为实在是太强大了,只需要了解很简单的几个操作,即可编辑非常优美的文章,包括TeX科学公式(基于KaTeX)、流程图 Flowchart 和 时序图 ,不在让你浪费时间在格式的调整。
背景
是在PC端使用,直接引入JQuery和Markdown.md插件进行使用
editor.md目录介绍
这边需要说明一下 editor.md目录,本文介绍的版本为v1.5.0,在首页下载完成,解压editor.md-master.zip文件,可以看到如下图的目录结构:

图中红色框内是我们要引用到项目的文件和目录。
- css目录中可选择editormd.min.css放在对应的项目css目录中;
- js可选择editormd.min.js放置在对应项目的js目录中,需要注意的是同时需要引入jQuery,这里使用jquery.min.js;
- examples文件夹中是一部分核心功能的demo,在使用的过程中用到对应的组件或功能可打开参考;
- fonts是需要用到字体,可一并引入项目;
- images是一些加载类的图片;
- lib是editor.md依赖的第三方js资源,比如流程图的js资源;
- plugins主要是编辑器上面的操作功能插件,比如图片上传等,可选择使用的进行加载;
导入到web 项目中的目录如下:

页面中需要引入的文件,其他插件根据需要再增加
<!-- 页面中添加css -->
<link rel="stylesheet" href="./css/style.css" />
<link rel="stylesheet" href="./css/editormd.css" />
<!-- 页面中添加div -->
<div id="editormd">
<textarea style="display:none;">### Hello Editor.md !</textarea>
</div>
<!-- 页面中添加js -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/[email protected]"></script>
<script type="text/javascript" src="js/editormd.min.js"></script>
<script type="text/javascript" src="js/[email protected]"></script>
<script>
var testEditor = editormd("editormd", {
width: "90%",
height: 'calc(100vh - 85px)',
path : './lib/',
// theme : "dark",
// previewTheme : "dark",
// editorTheme : "pastel-on-dark",
// markdown : content?content:' ',
markdown : content,
codeFold : true,
//syncScrolling : false,
saveHTMLToTextarea : true, // 保存 HTML 到 Textarea
searchReplace : true,
//watch : false, // 关闭实时预览
htmlDecode : "style,script,iframe|on*", // 开启 HTML 标签解析,为了安全性,默认不开启
//toolbar : false, //关闭工具栏
//previewCodeHighlight : false, // 关闭预览 HTML 的代码块高亮,默认开启
emoji : true,
taskList : true,
tocm : true, // Using [TOCM]
tex : true, // 开启科学公式TeX语言支持,默认关闭
flowChart : true, // 开启流程图支持,默认关闭
sequenceDiagram : true, // 开启时序/序列图支持,默认关闭,
//dialogLockScreen : false, // 设置弹出层对话框不锁屏,全局通用,默认为true
//dialogShowMask : false, // 设置弹出层对话框显示透明遮罩层,全局通用,默认为true
//dialogDraggable : false, // 设置弹出层对话框不可拖动,全局通用,默认为true
//dialogMaskOpacity : 0.4, // 设置透明遮罩层的透明度,全局通用,默认值为0.1
//dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色,全局通用,默认为#fff
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "https://api.xxxx.com/api/v1/editorMdImgUpload",
onload : function() {
/*上传图片成功后可以做一些自己的处理*/
console.log('onload', this);
//this.fullscreen();
//this.unwatch();
//this.watch().fullscreen();
//this.setMarkdown("#PHP");
//this.width("100%");
//this.height(480);
//this.resize("100%", 640);
}
});
</script>
复制代码id为editormd,后面的js代码中需要用到。而且源码内部也是通过这个作为前缀的。
通过form表单提交时后台可通过content-editormd-markdown-doc获取到对应的markdown文档内容。比如Java中可通过request.getParameter(“content-editormd-markdown-doc”) 注意:此处需要注意的是,无论需要html格式的内容还是markdown格式的内容,都只需要写一个textarea。此处有一个很大的坑。不少其他教程中说需要两个textarea,那么会导致后一个textarea后台获得的数据是一个数组,而不是单纯的HTML内容。
编辑器中的编辑配置: path路径需要指定到项目中对应的lib的路径。如果设置不对markdown 无法渲染出来。
saveHTMLToTextarea设置为true表示,转化为html格式的内容也同样提交到后台。
好,到这边你就可以看到页面效果了。如下:

边栏推荐
- 【Kotlin疑惑】在Kotlin类中重载一个算术运算符,并把该运算符声明为扩展函数会发生什么?
- LeetCode每日一题(2305. Fair Distribution of Cookies)
- Navicat, MySQL export Er graph, er graph
- [point cloud processing paper crazy reading classic version 14] - dynamic graph CNN for learning on point clouds
- [point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
- Flask+supervisor installation realizes background process resident
- About the configuration of vs2008+rade CATIA v5r22
- [advanced feature learning on point clouds using multi resolution features and learning]
- [point cloud processing paper crazy reading classic version 11] - mining point cloud local structures by kernel correlation and graph pooling
- Digital statistics DP acwing 338 Counting problem
猜你喜欢

Redis learning (I)

Vscode编辑器右键没有Open In Default Browser选项

【点云处理之论文狂读经典版13】—— Adaptive Graph Convolutional Neural Networks

Instant messaging IM is the countercurrent of the progress of the times? See what jnpf says

Excel is not as good as jnpf form for 3 minutes in an hour. Leaders must praise it when making reports like this!

Flask+supervisor installation realizes background process resident

The "booster" of traditional office mode, Building OA office system, was so simple!
![[point cloud processing paper crazy reading frontier version 8] - pointview gcn: 3D shape classification with multi view point clouds](/img/ee/3286e76797a75c0f999c728fd2b555.png)
[point cloud processing paper crazy reading frontier version 8] - pointview gcn: 3D shape classification with multi view point clouds

LeetCode 871. Minimum refueling times

Windows安装Redis详细步骤
随机推荐
LeetCode每日一题(1300. Sum of Mutated Array Closest to Target)
【点云处理之论文狂读经典版13】—— Adaptive Graph Convolutional Neural Networks
The idea of compiling VBA Encyclopedia
CSDN markdown editor help document
用Redis实现分布式锁
Utilisation de hudi dans idea
PowerDesigner does not display table fields, only displays table names and references, which can be modified synchronously
[point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
[point cloud processing paper crazy reading cutting-edge version 12] - adaptive graph revolution for point cloud analysis
Severity code description the project file line prohibits the display of status error c2440 "initialization": unable to convert from "const char [31]" to "char *"
Crawler career from scratch (V): detailed explanation of re regular expression
LeetCode每日一题(2115. Find All Possible Recipes from Given Supplies)
【Kotlin学习】运算符重载及其他约定——重载算术运算符、比较运算符、集合与区间的约定
ERROR: certificate common name “www.mysql.com” doesn’t match requested host name “137.254.60.11”.
State compression DP acwing 291 Mondrian's dream
With low code prospect, jnpf is flexible and easy to use, and uses intelligence to define a new office mode
Win10 quick screenshot
307. Range Sum Query - Mutable
Vs2019 configuration opencv3 detailed graphic tutorial and implementation of test code
LeetCode每日一题(1856. Maximum Subarray Min-Product)