Skip to content
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
68 changes: 51 additions & 17 deletions src/extensions/base/BaseSchema/BaseSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,62 @@ import {builders} from 'prosemirror-test-builder';

import {createMarkupChecker} from '../../../../tests/sameMarkup';
import {ExtensionsManager} from '../../../core';
import {BlockquoteSpecs, blockquoteNodeName} from '../../markdown/Blockquote/BlockquoteSpecs';

import {BaseNode, BaseSchemaSpecs} from './BaseSchemaSpecs';

const {
schema,
markupParser: parser,
serializer,
} = new ExtensionsManager({
extensions: (builder) => builder.use(BaseSchemaSpecs, {}),
}).buildDeps();

const {doc, p} = builders<'doc' | 'p'>(schema, {
doc: {nodeType: BaseNode.Doc},
p: {nodeType: BaseNode.Paragraph},
});
describe('BaseSchema extension', () => {
describe('common', () => {
const {
schema,
markupParser: parser,
serializer,
} = new ExtensionsManager({
extensions: (builder) => builder.use(BaseSchemaSpecs, {}),
}).buildDeps();

const {same} = createMarkupChecker({parser, serializer});
const {doc, p} = builders<'doc' | 'p'>(schema, {
doc: {nodeType: BaseNode.Doc},
p: {nodeType: BaseNode.Paragraph},
});

describe('BaseSchema extension', () => {
it('should parse a paragraph', () => same('hello!', doc(p('hello!'))));
const {same} = createMarkupChecker({parser, serializer});

it('should parse a paragraph', () => same('hello!', doc(p('hello!'))));

it('should parse a few paragraphs', () => {
same(['hello', '', 'world!'].join('\n'), doc(p('hello'), p('world!')));
});
});

describe('preserveEmptyRows=true', () => {
const {
schema,
markupParser: parser,
serializer,
} = new ExtensionsManager({
extensions: (builder) =>
builder.use(BaseSchemaSpecs, {preserveEmptyRows: true}).use(BlockquoteSpecs),
}).buildDeps();

const {doc, p, bq} = builders<'doc' | 'p' | 'bq'>(schema, {
doc: {nodeType: BaseNode.Doc},
p: {nodeType: BaseNode.Paragraph},
bq: {nodeType: blockquoteNodeName},
});

const {same} = createMarkupChecker({parser, serializer});

it('should serialize empty paragraph as &nbsp;', () =>
same(
'hello!\n\n&nbsp;\n\nworld!',
doc(p('hello!'), p(String.fromCharCode(160 /* &nbsp; */)), p('world!')),
));

it('should parse a few paragraphs', () => {
same(['hello', '', 'world!'].join('\n'), doc(p('hello'), p('world!')));
it('should correct insert &nbsp; inside other nodes', () =>
same(
'> hello!\n>\n> &nbsp;\n> \n> world!',
doc(bq(p('hello!'), p(String.fromCharCode(160 /* &nbsp; */)), p('world!'))),
));
});
});
3 changes: 2 additions & 1 deletion src/extensions/base/BaseSchema/BaseSchemaSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
}

if (!isParentEmpty) {
state.write('&nbsp;\n\n');
state.write('&nbsp;\n');
state.write('\n');
}
} else {
state.renderInline(node);
Expand Down
Loading