Skip to content

Commit

Permalink
Add option to enable use of the medium-editor editableInput event Ion…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pete Chappell committed Mar 5, 2019
1 parent e356013 commit 9c3346d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Creates a new instance of `MeMarkdown`.

- **Object** `options`: An object containing the following fields:
- `events` (Array): An array with the events when the markdown code will be generated (default: `["input", "change"]`).
- `subscribeToMeEditableInput` (Boolean): If this is true we will respond to the medium editor's custom "editableInput" event
- `callback` (Function): The callback function. If the second argument is a function, then it has greater priority.
- `toTurndownOptions` (Object): Options to pass to the markdown converter code.
- `ignoreBuiltinConverters` (Boolean): If `true`, the default converters passed to `toMarkdown` will be ignored.
Expand Down
20 changes: 12 additions & 8 deletions dist/me-markdown.no-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
options.events = options.events || ["input", "change"];
callback = callback || options.callback || function () {};

var toTurnDownOptions = options.toTurnDownOptions = Object(options.toTurnDownOptions);
toTurnDownOptions.converters = toTurnDownOptions.converters || [];
var toTurndownOptions = options.toTurndownOptions = Object(options.toTurndownOptions);
toTurndownOptions.converters = toTurndownOptions.converters || [];

if (!options.ignoreBuiltInConverters) {
toTurnDownOptions.converters.push({
if (!options.ignoreBuiltinConverters) {
toTurndownOptions.converters.push({
filter: function (node) {
return node.nodeName === "DIV" && !node.attributes.length;
}
Expand Down Expand Up @@ -67,14 +67,18 @@
normalizeList($lists[i]);
}

callback( new TurndownService(options.toTurnDownOptions).turndown($clone.innerHTML).split("\n").map(function (c) {
callback( new TurndownService(options.toTurndownOptions).turndown($clone.innerHTML).split("\n").map(function (c) {
return c.replace(rightWhitespace, '');
}).join("\n").replace(rightWhitespace, ''));
}.bind(this);

options.events.forEach(function (c) {
this.element.addEventListener(c, handler);
}.bind(this));
if (options.subscribeToMeEditableInput) {
this.base.subscribe('editableInput', handler);
} else {
options.events.forEach(function (c) {
this.element.addEventListener(c, handler);
}.bind(this));
}

handler();
};
Expand Down
2 changes: 1 addition & 1 deletion dist/me-markdown.no-deps.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions dist/me-markdown.standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,11 @@ return TurndownService;
options.events = options.events || ["input", "change"];
callback = callback || options.callback || function () {};

var toTurnDownOptions = options.toTurnDownOptions = Object(options.toTurnDownOptions);
toTurnDownOptions.converters = toTurnDownOptions.converters || [];
var toTurndownOptions = options.toTurndownOptions = Object(options.toTurndownOptions);
toTurndownOptions.converters = toTurndownOptions.converters || [];

if (!options.ignoreBuiltInConverters) {
toTurnDownOptions.converters.push({
if (!options.ignoreBuiltinConverters) {
toTurndownOptions.converters.push({
filter: function (node) {
return node.nodeName === "DIV" && !node.attributes.length;
}
Expand Down Expand Up @@ -1001,14 +1001,18 @@ return TurndownService;
normalizeList($lists[i]);
}

callback( new TurndownService(options.toTurnDownOptions).turndown($clone.innerHTML).split("\n").map(function (c) {
callback( new TurndownService(options.toTurndownOptions).turndown($clone.innerHTML).split("\n").map(function (c) {
return c.replace(rightWhitespace, '');
}).join("\n").replace(rightWhitespace, ''));
}.bind(this);

options.events.forEach(function (c) {
this.element.addEventListener(c, handler);
}.bind(this));
if (options.subscribeToMeEditableInput) {
this.base.subscribe('editableInput', handler);
} else {
options.events.forEach(function (c) {
this.element.addEventListener(c, handler);
}.bind(this));
}

handler();
};
Expand Down
2 changes: 1 addition & 1 deletion dist/me-markdown.standalone.min.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/medium-editor-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param {Object} options An object containing the following fields:
*
* - `events` (Array): An array with the events when the markdown code will be generated (default: `["input", "change"]`).
* - `subscribeToMeEditableInput` (Boolean): If this is true we will respond to the medium editor's custom "editableInput" event
* - `callback` (Function): The callback function. If the second argument is a function, then it has greater priority.
* - `toTurndownOptions` (Object): Options to pass to the markdown converter code.
* - `ignoreBuiltinConverters` (Boolean): If `true`, the default converters passed to `toMarkdown` will be ignored.
Expand Down Expand Up @@ -87,9 +88,13 @@ module.exports = function (options, callback) {
}).join("\n").replace(rightWhitespace, ''));
}.bind(this);

options.events.forEach(function (c) {
this.element.addEventListener(c, handler);
}.bind(this));
if (options.subscribeToMeEditableInput) {
this.base.subscribe('editableInput', handler);
} else {
options.events.forEach(function (c) {
this.element.addEventListener(c, handler);
}.bind(this));
}

handler();
};
Expand Down

0 comments on commit 9c3346d

Please sign in to comment.