Skip to content

Commit

Permalink
editor#serialize accepts version parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Feb 8, 2016
1 parent 81f94f1 commit e27bf9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { DIRECTION } from 'mobiledoc-kit/utils/key';
import { TAB, SPACE } from 'mobiledoc-kit/utils/characters';
import assert from '../utils/assert';
import MutationHandler from 'mobiledoc-kit/editor/mutation-handler';
import { MOBILEDOC_VERSION } from 'mobiledoc-kit/renderers/mobiledoc';

export const EDITOR_ELEMENT_CLASS_NAME = '__mobiledoc-editor';

Expand Down Expand Up @@ -392,8 +393,8 @@ class Editor {
}
}

serialize() {
return mobiledocRenderers.render(this.post);
serialize(version=MOBILEDOC_VERSION) {
return mobiledocRenderers.render(this.post, version);
}

removeAllViews() {
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/editor/editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ test('editor parses and renders mobiledoc format', (assert) => {
'serialized editor === mobiledoc');
});

test('#serialize serializes to MOBILEDOC_VERSION by default', (assert) => {
let mobiledoc2 = Helpers.mobiledoc.build(({post, markupSection, marker}) => {
return post([markupSection('p', [marker('abc')])]);
}, '0.2.0');
let mobiledoc3 = Helpers.mobiledoc.build(({post, markupSection, marker}) => {
return post([markupSection('p', [marker('abc')])]);
}, '0.3.0');
editor = Helpers.mobiledoc.renderInto(editorElement, ({post, markupSection, marker}) => {
return post([markupSection('p', [marker('abc')])]);
});

assert.deepEqual(editor.serialize('0.2.0'), mobiledoc2, 'serializes 0.2.0');
assert.deepEqual(editor.serialize('0.3.0'), mobiledoc3, 'serializes 0.3.0');

assert.throws(
() => editor.serialize('unknown'),
/Unknown version/
);
});

test('editor parses and renders html', (assert) => {
editorElement.innerHTML = '<p>something here</p>';
editor = new Editor({html: '<p>hello world</p>'});
Expand Down

0 comments on commit e27bf9b

Please sign in to comment.