Skip to content

Commit

Permalink
Merge pull request #18 from aguingand/fix-expel-whitespaces
Browse files Browse the repository at this point in the history
Fix expel whitespaces
  • Loading branch information
aguingand authored Jun 8, 2023
2 parents d6f9ec1 + 5efc72f commit d6ed80d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion __tests__/serialize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ describe('serialize', () => {
},
})).toEqual('<sup>example</sup>');
});
test('expels whitespaces', () => {
expect(serialize('My <strong> example </strong>')).toEqual('My **example** ');
expect(serialize('My <em> example </em>')).toEqual('My *example* ');
});
test('trim inline', () => {
expect(serialize('My<strong>, example</strong>')).toEqual('My, **example**');
expect(serialize('My<em>. example</em>')).toEqual('My. *example*');
});
});
describe('nodes', () => {
test('paragraph', () => {
Expand Down Expand Up @@ -229,7 +237,7 @@ describe('serialize', () => {
})).toEqual('<block-element>\na<br>b\n</block-element>');
});
test('html inline', () => {
expect(serialize('<p> <inline-element>example1</inline-element> <inline-element>example2</inline-element> </p>', {
expect(serialize('<p><inline-element>example1</inline-element> <inline-element>example2</inline-element></p>', {
html: true,
htmlNode: {
group: 'inline',
Expand Down
4 changes: 3 additions & 1 deletion __tests__/utils/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export function serialize(content, { htmlNode, htmlMark, ...markdownOptions } =
markdownOptions,
});
const doc = DOMParser.fromSchema(editor.schema)
.parse(elementFromString(content));
.parse(elementFromString(content), {
preserveWhitespace: true, // to ensure whitespaces handling
});

return editor.storage.markdown.serializer.serialize(doc);
}
1 change: 1 addition & 0 deletions example/src/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ___

***

Aenean ut eros et nisl sagittis vestibulum. Donec vitae orci sed dolor rutrum auctor. Vestibulum rutrum, mi nec elementum vehicula, eros quam gravida nisl, id fringilla neque ante vel mi.

## Emphasis

Expand Down
1 change: 1 addition & 0 deletions src/serialize/MarkdownSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class MarkdownSerializer {
const serialize = getMarkdownSpec(mark)?.serialize;
return serialize
? {
...serialize,
open: typeof serialize.open === 'function' ? serialize.open.bind({ editor: this.editor, options: mark.options }) : serialize.open,
close: typeof serialize.close === 'function' ? serialize.close.bind({ editor: this.editor, options: mark.options }) : serialize.close,
}
Expand Down

0 comments on commit d6ed80d

Please sign in to comment.