Skip to content
This repository was archived by the owner on May 12, 2023. It is now read-only.

Commit 1213b08

Browse files
authored
feat: executePlugin() now supports proxy option allowing the caller to receive output from plugin execution (#76)
1 parent 2f6b2e9 commit 1213b08

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

editormd.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* Editor.md
33
*
44
* @file editormd.js
5-
* @version v1.7.12
5+
* @version v1.7.13
66
* @description Open source online markdown editor.
77
* @license MIT License
88
* @author Pandao
99
* {@link https://github.com/pandao/editor.md}
10-
* @updateTime 2022-09-16
10+
* @updateTime 2023-04-25
1111
*/
1212

1313
;(function(factory) {
@@ -59,7 +59,7 @@
5959
};
6060

6161
editormd.title = editormd.$name = "Editor.md";
62-
editormd.version = "1.7.12";
62+
editormd.version = "1.7.13";
6363
editormd.homePage = "https://pandao.github.io/editor.md/";
6464
editormd.classPrefix = "editormd-";
6565

@@ -2655,7 +2655,7 @@
26552655
* @returns {editormd} 返回editormd的实例对象
26562656
*/
26572657

2658-
executePlugin : function(name, path, customPlugin = false, optionalParams= {}) {
2658+
executePlugin : function(name, path, customPlugin = false, optionalParams= {"proxy": false}) {
26592659
var _this = this;
26602660
var cm = this.cm;
26612661
var settings = this.settings;
@@ -2671,20 +2671,34 @@
26712671
return this;
26722672
}
26732673

2674-
this[name](cm);
2675-
2676-
return this;
2674+
if (optionalParams["proxy"]) {
2675+
return this[name](cm);
2676+
} else {
2677+
this[name](cm);
2678+
return this;
2679+
}
26772680
}
26782681

26792682
if ($.inArray(path, editormd.loadFiles.plugin) < 0)
26802683
{
2681-
editormd.loadPlugin(path, function() {
2682-
editormd.loadPlugins[name] = _this[name];
2683-
_this[name](cm, optionalParams);
2684-
}, "head", (customPlugin ? _this.author_ide_version : editormd.version) );
2684+
if (optionalParams["proxy"]){
2685+
return new Promise((res)=>{
2686+
editormd.loadPlugin(path, function() {
2687+
editormd.loadPlugins[name] = _this[name];
2688+
res(_this[name](cm, optionalParams))
2689+
}, "head", (customPlugin ? _this.author_ide_version : editormd.version) );
2690+
});
2691+
}
2692+
else{
2693+
editormd.loadPlugin(path, function() {
2694+
editormd.loadPlugins[name] = _this[name];
2695+
_this[name](cm, optionalParams);
2696+
}, "head", (customPlugin ? _this.author_ide_version : editormd.version) );
2697+
}
26852698
}
26862699
else
26872700
{
2701+
if (optionalParams["proxy"]) return $.proxy(editormd.loadPlugins[name], this)(cm, optionalParams);
26882702
$.proxy(editormd.loadPlugins[name], this)(cm, optionalParams);
26892703
}
26902704

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ibm-skills-network/editor.md",
3-
"version": "1.7.12",
3+
"version": "1.7.13",
44
"description": "Open source online markdown editor.",
55
"directories": {
66
"doc": "docs",

src/editormd.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
};
4848

4949
editormd.title = editormd.$name = "Editor.md";
50-
editormd.version = "1.7.12";
50+
editormd.version = "1.7.13";
5151
editormd.homePage = "https://pandao.github.io/editor.md/";
5252
editormd.classPrefix = "editormd-";
5353

@@ -2643,7 +2643,7 @@
26432643
* @returns {editormd} 返回editormd的实例对象
26442644
*/
26452645

2646-
executePlugin : function(name, path, customPlugin = false, optionalParams= {}) {
2646+
executePlugin : function(name, path, customPlugin = false, optionalParams= {"proxy": false}) {
26472647
var _this = this;
26482648
var cm = this.cm;
26492649
var settings = this.settings;
@@ -2659,20 +2659,34 @@
26592659
return this;
26602660
}
26612661

2662-
this[name](cm);
2663-
2664-
return this;
2662+
if (optionalParams["proxy"]) {
2663+
return this[name](cm);
2664+
} else {
2665+
this[name](cm);
2666+
return this;
2667+
}
26652668
}
26662669

26672670
if ($.inArray(path, editormd.loadFiles.plugin) < 0)
26682671
{
2669-
editormd.loadPlugin(path, function() {
2670-
editormd.loadPlugins[name] = _this[name];
2671-
_this[name](cm, optionalParams);
2672-
}, "head", (customPlugin ? _this.author_ide_version : editormd.version) );
2672+
if (optionalParams["proxy"]){
2673+
return new Promise((res)=>{
2674+
editormd.loadPlugin(path, function() {
2675+
editormd.loadPlugins[name] = _this[name];
2676+
res(_this[name](cm, optionalParams))
2677+
}, "head", (customPlugin ? _this.author_ide_version : editormd.version) );
2678+
});
2679+
}
2680+
else{
2681+
editormd.loadPlugin(path, function() {
2682+
editormd.loadPlugins[name] = _this[name];
2683+
_this[name](cm, optionalParams);
2684+
}, "head", (customPlugin ? _this.author_ide_version : editormd.version) );
2685+
}
26732686
}
26742687
else
26752688
{
2689+
if (optionalParams["proxy"]) return $.proxy(editormd.loadPlugins[name], this)(cm, optionalParams);
26762690
$.proxy(editormd.loadPlugins[name], this)(cm, optionalParams);
26772691
}
26782692

0 commit comments

Comments
 (0)