Skip to content

Commit

Permalink
update at 2019/02/22
Browse files Browse the repository at this point in the history
update at 2019/02/22
  • Loading branch information
NoisyWinds committed Feb 22, 2019
1 parent 01fb7bd commit f845224
Show file tree
Hide file tree
Showing 16 changed files with 442 additions and 126 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@
</p>
A markdown text editor compatible almost all markdown syntax, like Mathematical formula、flowchart、upload images...

### Get smartmd
## Screenshots
editor demo: [Demo](https://xiaoqingxin.site/editor/write)
js render page [Demo](https://xiaoqingxin.site/editor/js-show)
php render page [Demo](https://xiaoqingxin.site/editor/php-show)

![](./docs/screenshot.png)
---
![](./docs/screenshot_02.gif)
---
![](./docs/screenshot_03.gif)

## Get smartmd
```node
npm install smartmd
```
Expand All @@ -20,14 +31,14 @@ npm install smartmd
<script src="dist/smartmd.min.js"></script>
</head>
```
### Quickstart
## Quickstart
```javascript
var editor = new Smartmd({
el: "#editor",
height: "400px"
});
```
### Build Setup
## Build Setup
```node
# install reference
npm install smartmd
Expand All @@ -39,15 +50,15 @@ npm run dev
npm run build
```

### Features
## Features
- Markdown syntax parse by Markdown-It and it's plugins
- LaTeX mathematical expressions using KaTeX
- Diagrams and flowcharts using Mermaid
- Live preview
- Emoji
- Images upload (need server)

### Issue
## Issue
welcome repo bug reports, feature requests or optimization method.

### Reference:
Expand Down
44 changes: 27 additions & 17 deletions dist/smartmd.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -36178,10 +36178,11 @@ function mermaidChart(code) {
}

function MermaidPlugin(markdownIt) {
if (mermaid) {
if (window.mermaid) {
markdownIt.mermaid = mermaid;
var temp = markdownIt.renderer.rules.fence.bind(markdownIt.renderer.rules);

markdownIt.renderer.rules.fence = function (tokens, idx) {
markdownIt.renderer.rules.fence = function (tokens, idx, options, env, slf) {
var token = tokens[idx];
var code = token.content.trim();

Expand All @@ -36190,11 +36191,15 @@ function MermaidPlugin(markdownIt) {
}

var firstLine = code.split(/\n/)[0].trim();
if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) return mermaidChart(code);
return tokens;

if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) {
return mermaidChart(code);
}

return temp(tokens, idx, options, env, slf);
};
} else {
console.warn('Smartmd: mermaid is used but not import');
throw new ReferenceError('Smartmd: mermaid is used but not import');
}
}

Expand Down Expand Up @@ -36433,7 +36438,7 @@ function MarkdownItKatex (md, options) {
md.renderer.rules.math_inline = inlineRenderer;
md.renderer.rules.math_block = blockRenderer;
} else {
console.warn("Smartmd: katex is used but not import");
throw new ReferenceError("Smartmd: katex is used but not import");
}
}

Expand Down Expand Up @@ -36462,7 +36467,7 @@ function MarkdownIt$1 (editor) {
return "<pre class=\"hljs\"><code>".concat(window.hljs.highlightAuto(str).value, "</code></pre>");
};
} else {
console.warn("Smartmd: highlight used but not import");
throw new ReferenceError("Smartmd: highlight used but not import");
}
}

Expand Down Expand Up @@ -36778,6 +36783,8 @@ function checkImage(file) {
return true;
}
function uploadImages (file) {
var _this = this;

var options = this.options;
var cm = this.codemirror;
var url = options.uploads.url; // image validator
Expand All @@ -36794,25 +36801,30 @@ function uploadImages (file) {
var xhr = new XMLHttpRequest();
xhr.open('post', url);

xhr.onreadystatechange = function (response) {
if (this.readyState === 4) {
bookmark.clear(); // write to parse your response data
xhr.onreadystatechange = function () {
bookmark.clear();

if (xhr.readyState === 4) {
// write to parse your xhr.responseText data
try {
var data = JSON.parse(response);
var data = JSON.parse(xhr.responseText);

if (xhr.status === 200) {
cm.setSelection(from);
cm.replaceSelection("![](".concat(data.path, ")"));

_this.alert(data.message);
} else {
var error = options.uploads.serverError.replace('{msg}', data.msg);
this.alert(error, 'error');

_this.alert(error, 'error');
}
} catch (e) {
console.warn('Smartmd: Json data cannot be parse check your request return');
console.log(xhr.responseText);
throw new SyntaxError('Smartmd: Json data cannot be parse check your request return');
}
}
}.bind(this);
};

xhr.upload.onprogress = function (ev) {
if (ev.lengthComputable) {
Expand Down Expand Up @@ -37278,11 +37290,9 @@ function () {

if (opt.el) {
opt.el = getElement(opt.el);
console.log(opt.el);
} else {
// no element found
console.error("Smartmd: Error. No element was found.");
return;
throw new ReferenceError("Smartmd: Error. No element was found.");
}

new Observer$1(opt);
Expand Down
44 changes: 27 additions & 17 deletions dist/smartmd.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36163,10 +36163,11 @@ function mermaidChart(code) {
}

function MermaidPlugin(markdownIt) {
if (mermaid) {
if (window.mermaid) {
markdownIt.mermaid = mermaid;
var temp = markdownIt.renderer.rules.fence.bind(markdownIt.renderer.rules);

markdownIt.renderer.rules.fence = function (tokens, idx) {
markdownIt.renderer.rules.fence = function (tokens, idx, options, env, slf) {
var token = tokens[idx];
var code = token.content.trim();

Expand All @@ -36175,11 +36176,15 @@ function MermaidPlugin(markdownIt) {
}

var firstLine = code.split(/\n/)[0].trim();
if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) return mermaidChart(code);
return tokens;

if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) {
return mermaidChart(code);
}

return temp(tokens, idx, options, env, slf);
};
} else {
console.warn('Smartmd: mermaid is used but not import');
throw new ReferenceError('Smartmd: mermaid is used but not import');
}
}

Expand Down Expand Up @@ -36418,7 +36423,7 @@ function MarkdownItKatex (md, options) {
md.renderer.rules.math_inline = inlineRenderer;
md.renderer.rules.math_block = blockRenderer;
} else {
console.warn("Smartmd: katex is used but not import");
throw new ReferenceError("Smartmd: katex is used but not import");
}
}

Expand Down Expand Up @@ -36447,7 +36452,7 @@ function MarkdownIt$1 (editor) {
return "<pre class=\"hljs\"><code>".concat(window.hljs.highlightAuto(str).value, "</code></pre>");
};
} else {
console.warn("Smartmd: highlight used but not import");
throw new ReferenceError("Smartmd: highlight used but not import");
}
}

Expand Down Expand Up @@ -36763,6 +36768,8 @@ function checkImage(file) {
return true;
}
function uploadImages (file) {
var _this = this;

var options = this.options;
var cm = this.codemirror;
var url = options.uploads.url; // image validator
Expand All @@ -36779,25 +36786,30 @@ function uploadImages (file) {
var xhr = new XMLHttpRequest();
xhr.open('post', url);

xhr.onreadystatechange = function (response) {
if (this.readyState === 4) {
bookmark.clear(); // write to parse your response data
xhr.onreadystatechange = function () {
bookmark.clear();

if (xhr.readyState === 4) {
// write to parse your xhr.responseText data
try {
var data = JSON.parse(response);
var data = JSON.parse(xhr.responseText);

if (xhr.status === 200) {
cm.setSelection(from);
cm.replaceSelection("![](".concat(data.path, ")"));

_this.alert(data.message);
} else {
var error = options.uploads.serverError.replace('{msg}', data.msg);
this.alert(error, 'error');

_this.alert(error, 'error');
}
} catch (e) {
console.warn('Smartmd: Json data cannot be parse check your request return');
console.log(xhr.responseText);
throw new SyntaxError('Smartmd: Json data cannot be parse check your request return');
}
}
}.bind(this);
};

xhr.upload.onprogress = function (ev) {
if (ev.lengthComputable) {
Expand Down Expand Up @@ -37263,11 +37275,9 @@ function () {

if (opt.el) {
opt.el = getElement(opt.el);
console.log(opt.el);
} else {
// no element found
console.error("Smartmd: Error. No element was found.");
return;
throw new ReferenceError("Smartmd: Error. No element was found.");
}

new Observer$1(opt);
Expand Down
44 changes: 27 additions & 17 deletions dist/smartmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -36182,10 +36182,11 @@
}

function MermaidPlugin(markdownIt) {
if (mermaid) {
if (window.mermaid) {
markdownIt.mermaid = mermaid;
var temp = markdownIt.renderer.rules.fence.bind(markdownIt.renderer.rules);

markdownIt.renderer.rules.fence = function (tokens, idx) {
markdownIt.renderer.rules.fence = function (tokens, idx, options, env, slf) {
var token = tokens[idx];
var code = token.content.trim();

Expand All @@ -36194,11 +36195,15 @@
}

var firstLine = code.split(/\n/)[0].trim();
if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) return mermaidChart(code);
return tokens;

if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) {
return mermaidChart(code);
}

return temp(tokens, idx, options, env, slf);
};
} else {
console.warn('Smartmd: mermaid is used but not import');
throw new ReferenceError('Smartmd: mermaid is used but not import');
}
}

Expand Down Expand Up @@ -36437,7 +36442,7 @@
md.renderer.rules.math_inline = inlineRenderer;
md.renderer.rules.math_block = blockRenderer;
} else {
console.warn("Smartmd: katex is used but not import");
throw new ReferenceError("Smartmd: katex is used but not import");
}
}

Expand Down Expand Up @@ -36466,7 +36471,7 @@
return "<pre class=\"hljs\"><code>".concat(window.hljs.highlightAuto(str).value, "</code></pre>");
};
} else {
console.warn("Smartmd: highlight used but not import");
throw new ReferenceError("Smartmd: highlight used but not import");
}
}

Expand Down Expand Up @@ -36782,6 +36787,8 @@
return true;
}
function uploadImages (file) {
var _this = this;

var options = this.options;
var cm = this.codemirror;
var url = options.uploads.url; // image validator
Expand All @@ -36798,25 +36805,30 @@
var xhr = new XMLHttpRequest();
xhr.open('post', url);

xhr.onreadystatechange = function (response) {
if (this.readyState === 4) {
bookmark.clear(); // write to parse your response data
xhr.onreadystatechange = function () {
bookmark.clear();

if (xhr.readyState === 4) {
// write to parse your xhr.responseText data
try {
var data = JSON.parse(response);
var data = JSON.parse(xhr.responseText);

if (xhr.status === 200) {
cm.setSelection(from);
cm.replaceSelection("![](".concat(data.path, ")"));

_this.alert(data.message);
} else {
var error = options.uploads.serverError.replace('{msg}', data.msg);
this.alert(error, 'error');

_this.alert(error, 'error');
}
} catch (e) {
console.warn('Smartmd: Json data cannot be parse check your request return');
console.log(xhr.responseText);
throw new SyntaxError('Smartmd: Json data cannot be parse check your request return');
}
}
}.bind(this);
};

xhr.upload.onprogress = function (ev) {
if (ev.lengthComputable) {
Expand Down Expand Up @@ -37282,11 +37294,9 @@

if (opt.el) {
opt.el = getElement(opt.el);
console.log(opt.el);
} else {
// no element found
console.error("Smartmd: Error. No element was found.");
return;
throw new ReferenceError("Smartmd: Error. No element was found.");
}

new Observer$1(opt);
Expand Down
2 changes: 1 addition & 1 deletion dist/smartmd.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit f845224

Please sign in to comment.