Skip to content

Commit

Permalink
fix slab#862
Browse files Browse the repository at this point in the history
iOS native toolbar formatting inserts <b> and <i> nodes
  • Loading branch information
jhchen committed Aug 22, 2016
1 parent d31827f commit e431bce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
19 changes: 17 additions & 2 deletions formats/bold.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import Inline from '../blots/inline';

class Bold extends Inline { }
class Bold extends Inline {
static create(value) {
return super.create();
}

static formats(domNode) {
return true;
}

optimize() {
super.optimize();
if (this.domNode.tagName !== this.statics.tagName[0]) {
this.replaceWith(this.statics.blotName);
}
}
}
Bold.blotName = 'bold';
Bold.tagName = 'STRONG';
Bold.tagName = ['STRONG', 'B'];

export default Bold;
6 changes: 3 additions & 3 deletions formats/italic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Inline from '../blots/inline';
import Bold from './bold';

class Italic extends Inline { }
class Italic extends Bold { }
Italic.blotName = 'italic';
Italic.tagName = 'EM';
Italic.tagName = ['EM', 'I'];

export default Italic;
1 change: 1 addition & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import './unit/formats/code';
import './unit/formats/header';
import './unit/formats/indent';
import './unit/formats/list';
import './unit/formats/bold';

import './unit/modules/clipboard';
import './unit/modules/history';
Expand Down
13 changes: 13 additions & 0 deletions test/unit/formats/bold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Scroll from '../../../blots/scroll';


describe('Bold', function() {
it('optimize and merge', function() {
let scroll = this.initialize(Scroll, '<p><strong>a</strong>b<strong>c</strong></p>');
let bold = document.createElement('b');
bold.appendChild(scroll.domNode.firstChild.childNodes[1]);
scroll.domNode.firstChild.insertBefore(bold, scroll.domNode.firstChild.lastChild);
scroll.update();
expect(scroll.domNode).toEqualHTML('<p><strong>abc</strong></p>');
});
});

0 comments on commit e431bce

Please sign in to comment.