Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Mobiledoc 0.3.2 #22

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/renderer-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Renderer_0_2, {
} from './renderers/0-2';
import Renderer_0_3, {
MOBILEDOC_VERSION_0_3,
MOBILEDOC_VERSION_0_3_1
MOBILEDOC_VERSION_0_3_1,
MOBILEDOC_VERSION_0_3_2
} from './renderers/0-3';
import RENDER_TYPE from './utils/render-type';
/**
Expand Down Expand Up @@ -64,6 +65,7 @@ export default class RendererFactory {
case null:
case MOBILEDOC_VERSION_0_3:
case MOBILEDOC_VERSION_0_3_1:
case MOBILEDOC_VERSION_0_3_2:
return new Renderer_0_3(mobiledoc, this.state).render();
default:
throw new Error(`Unexpected Mobiledoc version "${version}"`);
Expand Down
5 changes: 3 additions & 2 deletions lib/renderers/0-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import {

export const MOBILEDOC_VERSION_0_3 = '0.3.0';
export const MOBILEDOC_VERSION_0_3_1 = '0.3.1';
export const MOBILEDOC_VERSION = MOBILEDOC_VERSION_0_3_1;
export const MOBILEDOC_VERSION_0_3_2 = '0.3.2';

function validateVersion(version) {
if (
version !== MOBILEDOC_VERSION_0_3 &&
version !== MOBILEDOC_VERSION_0_3_1
version !== MOBILEDOC_VERSION_0_3_1 &&
version !== MOBILEDOC_VERSION_0_3_2
) {
throw new Error(`Unexpected Mobiledoc version "${version}"`);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Renders mobiledoc input to text (string) output",
"main": "dist/commonjs/mobiledoc-text-renderer/index.js",
"scripts": {
"start": "broccoli serve",
"test": "testem ci",
"build": "rm -rf dist/ && broccoli build dist"
},
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/renderers/0-3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
const { test, module } = QUnit;
const MOBILEDOC_VERSION_0_3= '0.3.0';
const MOBILEDOC_VERSION_0_3_1 = '0.3.1';
const MOBILEDOC_VERSION_0_3_2 = '0.3.2';

let renderer;
module('Unit: Mobiledoc Text Renderer - 0.3', {
Expand Down Expand Up @@ -71,6 +72,20 @@ test('renders a mobiledoc 0.3.1 without markers with aside', (assert) => {
'hello world');
});

test('renders a mobiledoc 0.3.2', (assert) => {
let mobiledoc = {
version: MOBILEDOC_VERSION_0_3_2,
atoms: [],
cards: [],
markups: [],
sections: []
};
let {result: rendered} = renderer.render(mobiledoc);

assert.equal(rendered,
'');
});

test('renders a mobiledoc with simple (no attributes) marker', (assert) => {
let mobiledoc = {
version: MOBILEDOC_VERSION_0_3,
Expand Down Expand Up @@ -638,3 +653,26 @@ test('rendering unknown atom uses unknownAtomHandler', (assert) => {
renderer = new Renderer({atoms: [], unknownAtomHandler, cardOptions});
renderer.render(mobiledoc);
});

test('renders a mobiledoc 0.3.2 with attributes', (assert) => {
let mobiledoc = {
version: MOBILEDOC_VERSION_0_3_2,
atoms: [],
cards: [],
markups: [],
sections: [
[
MARKUP_SECTION_TYPE,
'P',
[
[0, [], 0, "Simple aligned example"]
],
['data-md-text-align', 'center']
]
]
};
let {result: rendered} = renderer.render(mobiledoc);

assert.equal(rendered,
'Simple aligned example');
});