Browse Source

Release 1.0.0

v1.1.9
Pandao 10 years ago
parent
commit
9ab18be32d
  1. 27
      CHANGE.md
  2. 108
      Gulpfile.js
  3. 4
      README.md
  4. 8
      dist/css/editormd.css
  5. 4
      dist/css/editormd.css.map
  6. 4
      dist/css/editormd.css.min.map
  7. 4
      dist/css/editormd.min.css
  8. 8
      dist/css/editormd.preview.css
  9. 4
      dist/css/editormd.preview.css.map
  10. 4
      dist/css/editormd.preview.css.min.map
  11. 4
      dist/css/editormd.preview.min.css
  12. 2
      examples/html-preview-markdown-to-html.html
  13. 25
      examples/index.html
  14. 49
      examples/katex.html
  15. 47
      examples/mathjax.html
  16. 13
      examples/simple.html
  17. 2
      examples/test.md
  18. 61
      examples/use-requirejs.html
  19. 20
      examples/use-seajs.html
  20. 2
      lib/codemirror/addons.min.js
  21. 0
      lib/codemirror/codemirror.min.css
  22. 0
      lib/codemirror/codemirror.min.js
  23. 8
      lib/codemirror/modes.min.js
  24. 362
      src/js/editormd.js
  25. 8
      src/scss/editormd.preview.scss
  26. 75
      tests/codemirror-test.html

27
CHANGE.md

@ -1,5 +1,28 @@
####更新日志
#####v1.0.0
#####v1.0.0 beta
基本功能完成;
基本功能完成;
#####v1.0.0 releases
主要更新:
- 新建分支 `mathjax-version`,但不打算继续对此分支进行开发;
- 移除MathJax,改用Katex,解析和预览响应速度大幅度提高;
- 移除 `mathjax` 配置项;
- 移除 `mathjaxURL` 属性;
- 移除 `setMathJaxConfig()` 方法;
- 移除 `loadMathJax()` 方法;
- 移除MathJax的所有示例;
- 新增 `tex` 配置项,表示是否开启支持科学公式TeX;
- 新增 `katexURL` 属性;
- 新增 `loadKaTex` 方法;
- 新增KaTeX的示例;
- `setCodeEditor()`方法更名为`setCodeMirror()`;
- 合并CodeMirror使用到的多个JS模块文件,大幅减少HTTP请求,加快下载速度;
- 新增合并后的两个模块文件:`./lib/codemirror/modes.min.js`、`./lib/codemirror/addons.min.js`;
- `Gulpfile.js` 新增合并CodeMirror模块文件的任务方法`codemirror-mode`和`codemirror-addon`;
- 另外在使用Require.js时,因为CodeMirror的严格模块依赖,不使用上述合并的模块文件;
- 更新 `README.md` 等相关文档和示例;
- 解决Sea.js环境下Raphael.js无法运行的问题,即必须先加载Raphael.js,后加载Sea.js;

108
Gulpfile.js

@ -88,6 +88,114 @@ gulp.task('js', function() {
.pipe(notify({ message: 'js task complete' }));
});
var codeMirror = {
path : {
src : {
mode : "lib/codemirror/mode",
addon : "lib/codemirror/addon"
},
dist : "lib/codemirror"
},
modes : [
"css",
"sass",
"shell",
"sql",
"clike",
"php",
"xml",
"markdown",
"javascript",
"htmlmixed",
"gfm",
"http",
"go",
"dart",
"coffeescript",
"nginx",
"python",
"perl",
"lua",
"r",
"ruby",
"rst",
"smartymixed",
"vb",
"vbscript",
"velocity",
"xquery",
"yaml",
"erlang",
"jade",
],
addons : [
"edit/trailingspace",
"dialog/dialog",
"search/searchcursor",
"search/search",
"scroll/annotatescrollbar",
"search/matchesonscrollbar",
"display/placeholder",
"edit/closetag",
"fold/xml-fold",
"mode/overlay",
"selection/active-line",
"edit/closebrackets",
"display/fullscreen",
"search/searchcursor",
"search/match-highlighter"
]
};
gulp.task('codemirror-mode', function() {
var modes = [
codeMirror.path.src.mode + "/meta.js"
];
for(var i in codeMirror.modes) {
var mode = codeMirror.modes[i];
modes.push(codeMirror.path.src.mode + "/" + mode + "/" + mode + ".js");
}
//console.log("modes =>", modes);
return gulp.src(modes)
.pipe(concat('modes.min.js'))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(uglify())
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + "\\");
return name[1].replace('\\', '');
}}))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(notify({ message: 'codemirror-mode task complete' }));
});
gulp.task('codemirror-addon', function() {
var addons = [];
for(var i in codeMirror.addons) {
var addon = codeMirror.addons[i];
addons.push(codeMirror.path.src.addon + "/" + addon + ".js");
}
return gulp.src(addons)
.pipe(concat('addons.min.js'))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(uglify())
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + "\\");
return name[1].replace('\\', '');
}}))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(notify({ message: 'codemirror-addon task complete' }));
});
gulp.task("jsdoc", function(){
return gulp.src(["./src/editormd.js", "README.md"])
.pipe(jsdoc.parser())

4
README.md

@ -10,9 +10,9 @@ A simple online markdown editor.
- 支持Markdown标准和Github风格;
- 支持实时预览和多语言语法高亮;
- 支持ToC(Table of Contents);
- 支持[ToC(Table of Contents)](https://pandao.github.io/editor.md/examples/toc.html)
- 兼容主流的浏览器(IE8+),且支持iPad等平板设备;
- 支持Latex科学公式(基于MathJax);
- 支持TeX科学公式(基于[KaTeX](https://pandao.github.io/editor.md/examples/katex.html));
- 支持流程图 `flowchart` 和时序图 `sequenceDiagram`;
- 支持AMD/CMD模块化加载(支持 [Require.js](https://pandao.github.io/editor.md/examples/use-requirejs.html) & [Sea.js](https://pandao.github.io/editor.md/examples/use-seajs.html));

8
dist/css/editormd.css

@ -6,7 +6,7 @@
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-02-07
* @updateTime 2015-02-09
*/
/*!
@ -3364,6 +3364,12 @@
.editormd-preview-container .markdown-body pre code, .editormd-html-preview .markdown-body pre code {
padding: 0;
}
.editormd-preview-container p.editormd-tex, .editormd-html-preview p.editormd-tex {
text-align: center;
}
.editormd-preview-container span.editormd-tex, .editormd-html-preview span.editormd-tex {
margin: 0 5px;
}
.editormd-preview-container .sequence-diagram, .editormd-preview-container .flowchart, .editormd-html-preview .sequence-diagram, .editormd-html-preview .flowchart {
text-align: center;
}

4
dist/css/editormd.css.map

File diff suppressed because one or more lines are too long

4
dist/css/editormd.css.min.map

File diff suppressed because one or more lines are too long

4
dist/css/editormd.min.css

File diff suppressed because one or more lines are too long

8
dist/css/editormd.preview.css

@ -6,7 +6,7 @@
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-02-07
* @updateTime 2015-02-09
*/
/*! github-markdown-css | The MIT License (MIT) | Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | https://github.com/sindresorhus/github-markdown-css */
@ -715,6 +715,12 @@
.editormd-preview-container .markdown-body pre code, .editormd-html-preview .markdown-body pre code {
padding: 0;
}
.editormd-preview-container p.editormd-tex, .editormd-html-preview p.editormd-tex {
text-align: center;
}
.editormd-preview-container span.editormd-tex, .editormd-html-preview span.editormd-tex {
margin: 0 5px;
}
.editormd-preview-container .sequence-diagram, .editormd-preview-container .flowchart, .editormd-html-preview .sequence-diagram, .editormd-html-preview .flowchart {
text-align: center;
}

4
dist/css/editormd.preview.css.map

File diff suppressed because one or more lines are too long

4
dist/css/editormd.preview.css.min.map

File diff suppressed because one or more lines are too long

4
dist/css/editormd.preview.min.css

File diff suppressed because one or more lines are too long

2
examples/html-preview-markdown-to-html.html

@ -36,7 +36,7 @@
$.get("test.md", function(markdown) {
editormd.markdownToHTML("test-editormd", {
markdown : markdown, // 不设置时,从<script type="text/markdown">markdown
mathjax : true, // 默认不解析
tex : true, // 默认不解析
flowChart: true, // 默认不解析
sequenceDiagram : true, // 默认不解析
});

25
examples/index.html

@ -20,40 +20,37 @@
</header>
<ul>
<li>
<a href="./simple.html">simple.html</a>
<a href="./simple.html">Full example</a>
</li>
<li>
<a href="./use-requirejs.html">use-requirejs.html</a>
<a href="./use-requirejs.html">Use Require.js example</a>
</li>
<li>
<a href="./use-seajs.html">use-seajs.html</a>
<a href="./use-seajs.html">Use Seajs example</a>
</li>
<li>
<a href="./toc.html">toc.html</a>
<a href="./toc.html">ToC (Table of Contents) example</a>
</li>
<li>
<a href="./onload.html">onload.html</a>
<a href="./katex.html">TeX (based on KaTeX) </a>
</li>
<li>
<a href="./onchange.html">onchange.html</a>
<a href="./onload.html">onload event handle example</a>
</li>
<li>
<a href="./onfullscreen.html">onfullscreen.html</a>
<a href="./onchange.html">onchange event handle example</a>
</li>
<li>
<a href="./onfullscreen.html">onfullscreenExit.html</a>
<a href="./onfullscreen.html">onfullscreen / onfullscreenExit event handle example</a>
</li>
<li>
<a href="./mathjax.html">mathjax.html</a>
<a href="./flowchart.html">flowChart example</a>
</li>
<li>
<a href="./flowchart.html">flowchart.html</a>
<a href="./sequence-diagram.html">Sequence Diagram example</a>
</li>
<li>
<a href="./sequence-diagram.html">sequence-diagram.html</a>
</li>
<li>
<a href="./html-preview-markdown-to-html.html">html-preview-markdown-to-html.html</a>
<a href="./html-preview-markdown-to-html.html">Markdown to HTML for preview</a>
</li>
</ul>
</div>

49
examples/katex.html

@ -9,55 +9,42 @@
<div id="layout">
<header>
<h1>Tex科学公式</h1>
<p>基于KaTeX.js:<a href="http://khan.github.io/KaTeX/" target="_blank">http://khan.github.io/KaTeX/</a></p>
<p>基于KaTeX.js:<a href="http://khan.github.io/KaTeX/" target="_blank">http://khan.github.io/KaTeX/</a></p>
<p>注:默认使用cloudflare的CDN,有时加载速度会比较慢,可自定义加载地址。</p>
</header>
<div class="editormd" id="test-editormd">
<script type="text/markdown">####
$$E=mc^2$$
行内的公式$$E=mc^2$$行内的公式,行内的$$E=mc^2$$公式。
$$\(\sqrt{3x-1}+(1+x)^2\)$$
$$\sin(\alpha)^{\theta}=\sum_{i=0}^{n}(x^i + \cos(f))$$</script>
</div>
</div>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.js"></script>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../dist/css/editormd.css" />
<script src="../src/js/editormd.js"></script>
<script type="text/javascript">
$(function() {
//自定义MathJax加载URL,适用于国内
//editormd.mathjaxURL = "http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
$(function() {
/*
默认使用cloudflare的CDN,有时加载速度会比较慢
自定义KaTex的URL或者直接修改源码
//适用于全球/国外
//editormd.mathjaxURL = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
var testEditor
editormd.katexURL = {
js : ".....",
css : "......"
};
*/
$.get("./test.md", function(md){
testEditor = editormd("test-editormd", {
width: "90%",
height: 640,
path : '../lib/',
markdown : md,
//mathjax : true,
onload : function() {
this.editor.find(".mathjax-code").each(function(){
//console.log($(this)[0]);
$(this).html($(this).html().replace(/\$\$/g, ""));
katex.render($(this).html(), $(this)[0]);
});
},
onchange : function() {
this.editor.find(".mathjax-code").each(function(){
//console.log($(this)[0]);
$(this).html($(this).html().replace(/\$\$/g, ""));
katex.render($(this).html(), $(this)[0]);
});
}
});
var testEditor = editormd("test-editormd", {
width: "90%",
height: 640,
path : '../lib/',
tex : true
});
});
</script>

47
examples/mathjax.html

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>Mathjax - Editor.md examples</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="layout">
<header>
<h1>支持Latex(MathJax)科学公式</h1>
<p>基于MathJax.js:<a href="http://www.mathjax.org/" target="_blank">http://www.mathjax.org/</a></p>
<p>注1:默认不开启,影响实时预览的响应速度;</p>
<p>注2:可以自定义MathJax加载URL,国内可以采用这个CDN,http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML</p>
</header>
<div class="editormd" id="test-editormd">
<script type="text/markdown">####
$$E=mc^2$$
$$\(\sqrt{3x-1}+(1+x)^2\)$$
$$\sin(\alpha)^{\theta}=\sum_{i=0}^{n}(x^i + \cos(f))$$</script>
</div>
</div>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../dist/css/editormd.css" />
<script src="../src/js/editormd.js"></script>
<script type="text/javascript">
$(function() {
//自定义MathJax加载URL,适用于国内
editormd.mathjaxURL = "http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
//适用于全球/国外
//editormd.mathjaxURL = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
var testEditor = editormd("test-editormd", {
width: "90%",
height: 480,
path : '../lib/',
mathjax : true
});
});
</script>
</body>
</html>

13
examples/simple.html

@ -9,7 +9,7 @@
<div id="layout">
<header>
<h1>完整示例</h1>
<p>开启Latex(MathJax)、流程图和序列图支持;</p>
<p>开启TeX(基于KaTeX)、流程图和时序/序列图支持;</p>
</header>
<div class="btns">
<button id="show-btn">显示编辑器</button>
@ -27,7 +27,6 @@
<script type="text/markdown">###Hello world!</script>
</div>
</div>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../dist/css/editormd.css" />
<script src="../src/js/editormd.js"></script>
@ -41,11 +40,11 @@
height: 720,
path : '../lib/',
markdown : md,
//toolbar : false, //关闭工具栏
mathjax : true,
previewCodeHighlight : true,
flowChart : true,
sequenceDiagram : true,
//toolbar : false, //关闭工具栏
//previewCodeHighlight : false, // 关闭预览HTML的代码块高亮,默认开启
tex : true, // 开启科学公式TeX语言支持,默认关闭
flowChart : true, // 开启流程图支持,默认关闭
sequenceDiagram : true, // 开启时序/序列图支持,默认关闭
onload : function() {
console.log('onload', this);
//this.fullscreen();

2
examples/test.md

@ -133,6 +133,8 @@ Content Cell | Content Cell
$$E=mc^2$$
行内的公式$$E=mc^2$$行内的公式,行内的$$E=mc^2$$公式。
$$\(\sqrt{3x-1}+(1+x)^2\)$$
$$\sin(\alpha)^{\theta}=\sum_{i=0}^{n}(x^i + \cos(f))$$

61
examples/use-requirejs.html

@ -4,7 +4,8 @@
<meta charset="utf-8" />
<title>Use require.js - Editor.md examples</title>
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="../lib/codemirror/lib/codemirror.min.css" />
<link rel="stylesheet" href="../lib/codemirror/codemirror.min.css" />
<link rel="stylesheet" href="../dist/css/editormd.min.css" />
</head>
<body>
<div id="layout">
@ -27,8 +28,7 @@
<script type="text/markdown">###Hello world!</script>
</div>
</div>
<link rel="stylesheet" href="../dist/css/editormd.min.css" />
<script src="js/require.min.js"></script>
<script src="js/require.min.js"></script>
<script type="text/javascript">
requirejs.config({
@ -37,41 +37,44 @@
jquery : "jquery.min",
marked : "marked.min",
prettify : "prettify.min",
raphael : "raphael.min",
editormd : "../src/js/editormd"
},
waitSeconds: 30
});
require(["jquery", "marked", "prettify", "editormd", "raphael.min", "underscore.min", "flowchart.min", "jquery.flowchart.min", "sequence-diagram.min"], function($, marked, prettify, editormd) {
require(["jquery", "marked", "prettify", "editormd", "raphael", "underscore.min", "flowchart.min", "jquery.flowchart.min", "sequence-diagram.min"], function($, marked, prettify, editormd) {
var testEditor;
require(editormd.requireModules(), function(CodeMirror) {
//console.log(CodeMirror, marked);
// editormd.katexURL.js + ".js"
require([editormd.katexURL.js + ".js"], function(katex) {
require(editormd.requireModules(), function(CodeMirror) {
console.log(CodeMirror, marked, katex);
editormd.requirejsInit(CodeMirror, marked, prettyPrint);
editormd.requirejsInit(CodeMirror, marked, katex, prettyPrint);
$.get('test.md', function(md) {
testEditor = editormd("test-editormd", {
width: "90%",
height: 640,
path : '../lib/',
markdown : md,
mathjax : true,
previewCodeHighlight : true,
inRequirejs : true,
flowChart : true,
//codeMirror : CodeMirror,
sequenceDiagram : true,
onload : function() {
console.log('onload', this);
//this.fullscreen();
//this.unwatch();
//this.watch().fullscreen();
$.get('test.md', function(md) {
testEditor = editormd("test-editormd", {
width: "90%",
height: 640,
path : '../lib/',
markdown : md,
tex : true,
previewCodeHighlight : true,
inRequirejs : true,
flowChart : true,
sequenceDiagram : true,
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);
}
//this.setMarkdown("#PHP");
//this.width("100%");
//this.height(480);
//this.resize("100%", 640);
}
});
});
});
});

20
examples/use-seajs.html

@ -19,7 +19,9 @@
<div id="layout">
<header>
<h1>Use sea.js</h1>
<p>说明:由于Editor.md是依赖jQuery的,所以在使用Sea.js加载Editor.md时,要在jQuery.js文件尾部加上 <code>if(typeof define === "function") { define(function () { return $.noConflict(); }); }</code>,使jQuery支持Sea.js</p>
<p>说明:</p>
<p>1、由于Editor.md是依赖jQuery的,所以在使用Sea.js加载Editor.md时,要在jQuery.js文件尾部加上 <code>if(typeof define === "function") { define(function () { return $.noConflict(); }); }</code>,使jQuery支持Sea.js;</p>
<p>2、flowChart(流程图)和sequenceDiagram(时序图)基于Raphael.js,由于疑似Sea.js与Raphael.js有冲突,所以必须先加载Raphael.js再加载Sea.js,Editor.md才能在Sea.js下正常进行;</p>
</header>
<div class="btns">
<button id="show-btn">显示编辑器</button>
@ -37,20 +39,21 @@
<script type="text/markdown">###Hello world!</script>
</div>
</div>
<script src="../lib/raphael.min.js"></script>
<script src="js/sea.js"></script>
<link rel="stylesheet" href="../dist/css/editormd.css" />
<script type="text/javascript">
<script type="text/javascript">
seajs.config({
base : "../lib",
alias : {
"jquery" : "jquery.min",
"editormd" : "../src/js/editormd"
jquery : "jquery.min",
editormd : "../src/js/editormd"
}
});
var testEditor;
seajs.use(["jquery", "editormd"], function($, editormd) {
seajs.use(["jquery", "editormd"], function($, editormd) {
$.get("./test.md", function(md){
testEditor = editormd("test-editormd", {
@ -58,10 +61,11 @@
height: 640,
path : '../lib/',
markdown : md,
mathjax : true,
//toolbar : false, //关闭工具栏
tex : true, // 开启科学公式TeX语言支持,默认关闭
//previewCodeHighlight : false, // 关闭预览窗口的代码高亮,默认开启
//flowChart : true, // 未解决的Bug:因为Sea.js下Raphael无法加载
//sequenceDiagram : true, // 同上
flowChart : true, // 疑似Sea.js与Raphael.js有冲突,必须先加载Raphael.js,Editor.md才能在Sea.js下正常进行;
sequenceDiagram : true, // 同上
onload : function() {
console.log('onload', this);
//this.fullscreen();

2
lib/codemirror/addons.min.js

File diff suppressed because one or more lines are too long

0
lib/codemirror/lib/codemirror.min.css → lib/codemirror/codemirror.min.css

0
lib/codemirror/lib/codemirror.min.js → lib/codemirror/codemirror.min.js

8
lib/codemirror/modes.min.js

File diff suppressed because one or more lines are too long

362
src/js/editormd.js

@ -59,8 +59,8 @@
toc : true,
tocStartLevel : 2,
fontSize : "13px",
tex : false,
flowChart : false, // flowChart.js only support IE9+
mathjax : false,
sequenceDiagram : false, // sequenceDiagram.js only support IE9+
previewCodeHighlight : true,
inRequirejs : false,
@ -133,60 +133,14 @@
fullscreen : "全屏(按ESC还原)",
info : "关于" + editormd.title
}
},
codemirror : {
modes : [
"css",
"sass",
"shell",
"sql",
"clike",
"php",
"xml",
"markdown",
"javascript",
"htmlmixed",
"gfm",
"http",
"go",
"dart",
"coffeescript",
"nginx",
"python",
"perl",
"lua",
//"r",
"ruby",
"rst",
"smartymixed",
//"vb",
//"vbscript",
//"velocity",
//"xquery",
"yaml"
],
addons : [
"edit/trailingspace",
"dialog/dialog",
"search/searchcursor",
"search/search",
"scroll/annotatescrollbar",
"search/matchesonscrollbar",
"display/placeholder",
"edit/closetag",
"fold/xml-fold",
"mode/overlay",
"selection/active-line",
"edit/closebrackets",
"display/fullscreen",
"search/searchcursor",
"search/match-highlighter"
]
}
};
editormd.classNames = {
tex : editormd.classPrefix + "tex"
};
editormd.$katex = null;
editormd.$marked = null;
editormd.$CodeMirror = null;
editormd.$prettyPrint = null;
@ -265,7 +219,7 @@
}
else
{
_this.setCodeEditor();
_this.setCodeMirror();
_this.setToolbar();
_this.toolbarHandler();
_this.setMarked().loadedDisplay();
@ -282,8 +236,6 @@
loadQueues : function() {
var _this = this;
var settings = this.settings;
var cmModeIndex = 0, cmModeTotal = settings.codemirror.modes.length;
var cmAddonIndex = 0, cmAddonTotal = settings.codemirror.addons.length;
var loadPath = settings.path;
var loadFlowChartOrSequenceDiagram = function() {
@ -328,28 +280,23 @@
}
};
var loadCodeMirrorAddons = function() {
var addonName = settings.codemirror.addons[cmAddonIndex];
editormd.loadScript(loadPath + "codemirror/addon/" + addonName, function() {
if(cmAddonIndex < cmAddonTotal - 1)
{
cmAddonIndex ++;
loadCodeMirrorAddons();
}
else
{
_this.setCodeEditor();
_this.setToolbar();
editormd.loadCSS(loadPath + "codemirror/codemirror.min");
editormd.loadScript(loadPath + "codemirror/codemirror.min", function() {
editormd.$CodeMirror = CodeMirror;
editormd.loadScript(loadPath + "codemirror/modes.min", function() {
editormd.loadScript(loadPath + "codemirror/addons.min", function() {
_this.setCodeMirror();
_this.setToolbar();
_this.toolbarHandler();
editormd.loadScript(loadPath + "marked.min", function() {
editormd.$marked = marked;
//_this.marked = marked;
if (settings.previewCodeHighlight)
{
editormd.loadScript(loadPath + "prettify.min", function() {
@ -361,33 +308,11 @@
loadFlowChartOrSequenceDiagram();
}
});
}
});
};
var loadCodeMirrorModes = function(){
var modeName = settings.codemirror.modes[cmModeIndex];
editormd.loadScript(loadPath + "codemirror/mode/" + modeName + "/" + modeName, function() {
if(cmModeIndex < cmModeTotal - 1)
{
cmModeIndex ++;
loadCodeMirrorModes();
}
else
{
loadCodeMirrorAddons();
}
});
});
};
//editormd.loadCSS(loadPath + "font-awesome.min");
editormd.loadCSS(loadPath + "codemirror/lib/codemirror.min");
editormd.loadScript(loadPath + "codemirror/lib/codemirror.min", function() {
editormd.$CodeMirror = CodeMirror;
loadCodeMirrorModes();
});
return this;
@ -398,7 +323,7 @@
* @returns {editormd} 返回editormd的实例对象
*/
setCodeEditor : function() {
setCodeMirror : function() {
var settings = this.settings;
var codeMirrorConfig = {
@ -811,12 +736,24 @@
if (settings.sequenceDiagram) {
previewContainer.find(".sequence-diagram").sequenceDiagram({theme: "simple"});
}
if (settings.mathjax)
{
editormd.setMathJaxConfig(function() {
editormd.loadMathJax();
var katexHandle = function() {
previewContainer.find("." + editormd.classNames.tex).each(function(){
var tex = $(this);
editormd.$katex.render(tex.html(), tex[0]);
});
};
if (settings.tex)
{
if (!settings.inRequirejs) {
editormd.loadKaTex(function(){
editormd.$katex = katex;
katexHandle();
});
} else {
katexHandle();
}
}
editor.data({
@ -910,21 +847,9 @@
if (settings.sequenceDiagram) {
previewContainer.find(".sequence-diagram").sequenceDiagram({theme: "simple"});
}
if (settings.mathjax)
{
MathJax.Hub.Queue(function () {
previewContainer.find(".mathjax-code").each(function() {
var mathjaxDoc = $(this).html().replace(/\$\$(.*)\$\$/, function(s1, s2) { return s2; });
var jaxScript = "<script type=\"math/tex; mode=display\">" + mathjaxDoc + "</script>";
$(this).html($(jaxScript));
//MathJax.Hub.Queue(["Typeset", MathJax.Hub, "mathjax-code"]);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, $(this)[0]]);
});
});
if (settings.tex) {
katexHandle();
}
$.proxy(settings.onchange, _this)();
@ -1356,8 +1281,6 @@
markedRenderer.heading = function(text, level, raw) {
var escapedText = text.toLowerCase().replace(/[^\w]+/g, "-");
//console.log("escapedText", text, escapedText, level, raw);
var toc = {
text : text,
level : level,
@ -1366,27 +1289,35 @@
markdownToC.push(toc);
return "<h" + level + " id=\""+this.options.headerPrefix+raw.toLowerCase().replace(/[^\w]+/g,"-")+"\"><a href=\"#" + text + "\" name=\"" + text + "\" class=\"anchor\"></a><span class=\"header-link\"></span>" + text + "</h" + level + ">";
};
var mathJaxList = [];
return "<h" + level + " id=\"" + this.options.headerPrefix + raw.toLowerCase().replace(/[^\w]+/g,"-")+"\">" +
"<a href=\"#" + text + "\" name=\"" + text + "\" class=\"anchor\"></a>" +
"<span class=\"header-link\"></span>" + text + "</h" + level + ">";
};
markedRenderer.paragraph = function(text) {
var isMathJax = /\$\$(.*)\$\$/.test(text);
var mathjaxClassName = (isMathJax) ? " class=\"mathjax-code\"" : "";
var isToC = /^\[TOC\]$/.test(text);
if (isMathJax) {
mathJaxList.push(text);
var isTeXInline = /\$\$(.*)\$\$/g.test(text);
var isTeXLine = /^\$\$(.*)\$\$$/.test(text);
var isTeXAddClass = (isTeXLine) ? " class=\"" + editormd.classNames.tex + "\"" : "";
var isToC = /^\[TOC\]$/.test(text);
if (!isTeXLine && isTeXInline)
{
text = text.replace(/(\$\$([^\$]*)\$\$)+/g, function($1, $2) {
return "<span class=\"" + editormd.classNames.tex + "\">" + $2.replace(/\$/g, "") + "</span>";
});
}
else
{
text = (isTeXLine) ? text.replace(/\$/g, "") : text;
}
return (isToC) ? "<div class=\"markdown-toc\"><ul class=\"markdown-toc-list\">" + text + "</ul></div>" : "<p" + mathjaxClassName + ">" + text + "</p>\n";
return (isToC) ? "<div class=\"markdown-toc\"><ul class=\"markdown-toc-list\">" + text + "</ul></div>"
: "<p" + isTeXAddClass + ">" + text + "</p>\n";
};
markedRenderer.code = function (code, lang, escaped) {
if (lang === "seq")
if (lang === "seq" || lang === "sequence")
{
return "<div class=\"sequence-diagram\">" + code + "</div>";
}
@ -1459,10 +1390,11 @@
toc : true,
tocStartLevel : 2,
markdown : "",
mathjax : false,
previewCodeHighlight : true,
inRequirejs : false,
tex : false,
flowChart : false,
sequenceDiagram : false
sequenceDiagram : false,
previewCodeHighlight : true
};
editormd.$marked = marked;
@ -1506,24 +1438,92 @@
div.find(".sequence-diagram").sequenceDiagram({theme: "simple"});
}
if (settings.mathjax)
if (settings.tex)
{
editormd.setMathJaxConfig(function() {
editormd.loadMathJax();
});
var katexHandle = function() {
div.find("." + editormd.classNames.tex).each(function(){
var tex = $(this);
editormd.$katex.render(tex.html(), tex[0]);
});
};
if (!settings.inRequirejs) {
editormd.loadKaTex(function(){
editormd.$katex = katex;
katexHandle();
});
} else {
katexHandle();
}
}
};
// for Requires.js
// 与Gulpfile.js对应
editormd.codeMirrorModules = {
modes : [
"css",
"sass",
"shell",
"sql",
"clike",
"php",
"xml",
"markdown",
"javascript",
"htmlmixed",
"gfm",
"http",
"go",
"dart",
"coffeescript",
"nginx",
"python",
"perl",
"lua",
"r",
"ruby",
"rst",
"smartymixed",
"vb",
"vbscript",
"velocity",
"xquery",
"yaml",
"erlang",
"jade",
],
addons : [
"edit/trailingspace",
"dialog/dialog",
"search/searchcursor",
"search/search",
"scroll/annotatescrollbar",
"search/matchesonscrollbar",
"display/placeholder",
"edit/closetag",
"fold/xml-fold",
"mode/overlay",
"selection/active-line",
"edit/closebrackets",
"display/fullscreen",
"search/searchcursor",
"search/match-highlighter"
]
};
/**
* 用于支持Require.js加载的方法
* 用于支持Require.js加载的方法注入
* @param {Function} CodeMirror CodeMirror对象
* @param {Function} marked marked对象
* @param {Function} prettyPrint prettyPrint函数
*/
editormd.requirejsInit = function(CodeMirror, marked, prettyPrint) {
editormd.requirejsInit = function(CodeMirror, marked, katex, prettyPrint) {
editormd.$CodeMirror = CodeMirror;
editormd.$marked = marked;
editormd.$katex = katex;
editormd.$prettyPrint = prettyPrint;
};
@ -1538,19 +1538,25 @@
var settings = editormd.defaults;
var modules = [];
modules.push(loadPath + "codemirror/lib/codemirror.min");
modules.push(loadPath + "codemirror/codemirror.min");
for (var i = 0, len = settings.codemirror.modes.length; i < len; i++)
var codeMirrorModules = editormd.codeMirrorModules;
for (var i = 0, len = codeMirrorModules.modes.length; i < len; i++)
{
var modeName = settings.codemirror.modes[i];
var modeName = codeMirrorModules.modes[i];
modules.push(loadPath + "codemirror/mode/" + modeName + "/" + modeName);
}
for (var i = 0, len = settings.codemirror.addons.length; i < len; i++)
for (var i = 0, len = codeMirrorModules.addons.length; i < len; i++)
{
var addonName = settings.codemirror.addons[i];
var addonName = codeMirrorModules.addons[i];
modules.push(loadPath + "codemirror/addon/" + addonName);
}
editormd.loadCSS(editormd.katexURL.css);
//modules.push(editormd.katexURL.js + ".js");
return modules;
};
@ -1624,61 +1630,21 @@
}
};
/**
* MathJax配置信息
* @param {Function} [callback=function()] 加载成功后执行的回调函数
*/
editormd.setMathJaxConfig = function (callback) {
callback = callback || function() {};
var script = document.createElement("script");
script.className = "mathjax-config";
script.type = "text/x-mathjax-config";
script.text = 'MathJax.Hub.Config({' +
'extensions: ["tex2jax.js"],'+
'jax: ["input/TeX","output/HTML-CSS"],'+
'tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}'+
'});';
document.getElementsByTagName("head")[0].appendChild(script);
callback();
// 使用国外的CDN,加载速度有时会很慢,或者自定义URL
editormd.katexURL = {
css : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min",
js : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min",
};
// 注:国内可以采用这个CDN,http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML
editormd.mathjaxURL = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
/**
* 加载MathJax文件
* 加载KaTex文件
* @param {Function} [callback=function()] 加载成功后执行的回调函数
*/
editormd.loadMathJax = function (callback) {
callback = callback || function() {};
var script = document.createElement("script");
script.type = "text/javascript";
script.className = "mathjax-script";
script.onload = script.onreadystatechange = function() {
if (script.readyState)
{
if (script.readyState === "loaded" || script.readyState === "complete")
{
script.onreadystatechange = null;
callback();
}
}
else
{
callback();
}
};
script.src = editormd.mathjaxURL;
document.getElementsByTagName("head")[0].appendChild(script);
editormd.loadKaTex = function (callback) {
editormd.loadCSS(editormd.katexURL.css, function(){
editormd.loadScript(editormd.katexURL.js, callback || function(){});
});
};
/**

8
src/scss/editormd.preview.scss

@ -58,6 +58,14 @@
.markdown-toc-list {
}
}
p#{$prefix}tex {
text-align: center;
}
span#{$prefix}tex {
margin: 0 5px;
}
.sequence-diagram, .flowchart {
text-align: center;

75
tests/codemirror-test.html

@ -0,0 +1,75 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<title>CodeMirror Test</title>
<meta charset="UTF-8">
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" href="../examples/css/style.css" />
</head>
<body>
<div style="text-align: left;">
<textarea id="test" style="height: 700px;">###Hello world!</textarea>
</div>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../lib/codemirror/codemirror.min.css" />
<script src="../lib/codemirror/codemirror.min.js"></script>
<script src="../lib/codemirror/modes.min.js"></script>
<script src="../lib/codemirror/addons.min.js"></script>
<script type="text/javascript">
$(function() {
var codeMirrorConfig = {
mode: "gfm",
theme: "default",
tabSize: 4,
dragDrop: false,
autofocus: true,
indentUnit : 4,
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
indentWithTabs: true,
styleActiveLine: true,
styleSelectedText: true,
autoCloseBrackets: true,
showTrailingSpace: true,
highlightSelectionMatches: {
showToken: /\w/
}
};
$.get("../examples/test.md", function(md){
$("#test").html(md);
var codeMirrorEditor = CodeMirror.fromTextArea($("#test")[0], codeMirrorConfig);
var codeMirror = $(".CodeMirror");
});
/* var testEditor;
$.get("./test.md", function(md){
testEditor = editormd("test-editormd", {
width: "90%",
height: 640,
path : '../lib/',
markdown : md,
//mathjax : true,
onload : function() {
this.editor.find(".mathjax-code").each(function(){
//console.log($(this)[0]);
$(this).html($(this).html().replace(/\$\$/g, ""));
katex.render($(this).html(), $(this)[0]);
});
},
onchange : function() {
this.editor.find(".mathjax-code").each(function(){
//console.log($(this)[0]);
$(this).html($(this).html().replace(/\$\$/g, ""));
katex.render($(this).html(), $(this)[0]);
});
}
});
});*/
});
</script>
</body>
</html>
Loading…
Cancel
Save