Skip to content

Commit

Permalink
4.12.9
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Aug 12, 2015
1 parent 98d7875 commit 8bd6c8d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
4.12.9 / 2015-08-12
==================
* Fix a regression in the paste extension related to `pasteHTML` function


4.12.8 / 2015-08-10
==================
* Fix issue with creating anchors and restoring selection at the beginning of paragraphs
Expand Down
53 changes: 28 additions & 25 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4806,7 +4806,7 @@ var PasteHandler;
},

cleanPaste: function (text) {
var i, elList,
var i, elList, tmp, workEl,
multiline = /<p|<br|<div/.test(text),
replacements = createReplacements().concat(this.cleanReplacements || []);

Expand All @@ -4818,10 +4818,34 @@ var PasteHandler;
return this.pasteHTML(text);
}

// create a temporary div to cleanup block elements
tmp = this.document.createElement('div');

// double br's aren't converted to p tags, but we want paragraphs.
elList = text.split('<br><br>');
tmp.innerHTML = '<p>' + text.split('<br><br>').join('</p><p>') + '</p>';

// block element cleanup
elList = tmp.querySelectorAll('a,p,div,br');
for (i = 0; i < elList.length; i += 1) {
workEl = elList[i];

// Microsoft Word replaces some spaces with newlines.
// While newlines between block elements are meaningless, newlines within
// elements are sometimes actually spaces.
workEl.innerHTML = workEl.innerHTML.replace(/\n/gi, ' ');

switch (workEl.nodeName.toLowerCase()) {
case 'p':
case 'div':
this.filterCommonBlocks(workEl);
break;
case 'br':
this.filterLineBreak(workEl);
break;
}
}

this.pasteHTML('<p>' + elList.join('</p><p>') + '</p>');
this.pasteHTML(tmp.innerHTML);
},

pasteHTML: function (html, options) {
Expand Down Expand Up @@ -4851,27 +4875,6 @@ var PasteHandler;
Util.cleanupTags(workEl, options.cleanTags);
}

// block element cleanup
elList = fragmentBody.querySelectorAll('a,p,div,br');
for (i = 0; i < elList.length; i += 1) {
workEl = elList[i];

// Microsoft Word replaces some spaces with newlines.
// While newlines between block elements are meaningless, newlines within
// elements are sometimes actually spaces.
workEl.innerHTML = workEl.innerHTML.replace(/\n/gi, ' ');

switch (workEl.nodeName.toLowerCase()) {
case 'p':
case 'div':
this.filterCommonBlocks(workEl);
break;
case 'br':
this.filterLineBreak(workEl);
break;
}
}

Util.insertHTMLCommand(this.document, fragmentBody.innerHTML.replace(/&nbsp;/g, ' '));
},

Expand Down Expand Up @@ -6698,7 +6701,7 @@ MediumEditor.version = (function (major, minor, revision) {
};
}).apply(this, ({
// grunt-bump looks for this:
'version': '4.12.8'
'version': '4.12.9'
}).version.split('.'));

return MediumEditor;
Expand Down
5 changes: 2 additions & 3 deletions dist/js/medium-editor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medium-editor",
"version": "4.12.8",
"version": "4.12.9",
"author": "Davi Ferreira <hi@daviferreira.com>",
"contributors": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/js/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ MediumEditor.version = (function (major, minor, revision) {
};
}).apply(this, ({
// grunt-bump looks for this:
'version': '4.12.8'
'version': '4.12.9'
}).version.split('.'));

0 comments on commit 8bd6c8d

Please sign in to comment.