Skip to content

Commit

Permalink
fix: use html-entity for consecutive newlines (fix #2394 #2586
Browse files Browse the repository at this point in the history
  • Loading branch information
kshnurov committed Feb 16, 2023
1 parent a5835ec commit 471fdc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 49 deletions.
50 changes: 10 additions & 40 deletions apps/editor/src/__test__/unit/convertor.spec.ts
Expand Up @@ -405,11 +405,11 @@ describe('Convertor', () => {
bar
<br>
&#32;
baz
<br>
<br>
&#32;
&#32;
qux
`;

Expand Down Expand Up @@ -441,21 +441,21 @@ describe('Convertor', () => {
const expected = source`
foo
<br>
&#32;
bar
<br>
<br>
&#32;
&#32;
baz
<br>
&#32;
qux
<br>
&#32;
quux
<br>
<br>
&#32;
&#32;
quuz
`;

Expand Down Expand Up @@ -1062,36 +1062,6 @@ describe('Convertor', () => {
});
});

it('should convert empty line between lists of wysiwig to <br>', () => {
const wwNodeJson = {
type: 'doc',
content: [
{
type: 'bulletList',
content: [
{
type: 'listItem',
content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'test_1' }] },
{ type: 'paragraph', content: [] },
],
},
{
type: 'listItem',
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'test_2' }] }],
},
],
},
],
};

const wwNode = Node.fromJSON(schema, wwNodeJson);

const result = convertor.toMarkdownText(wwNode);

expect(result).toBe(`* test\\_1\n<br>\n* test\\_2`);
});

it('should escape the backslash, which is a plain chracter in the middle of a sentence', () => {
const markdown = source`
backslash \\in the middle of a sentence
Expand Down
10 changes: 1 addition & 9 deletions apps/editor/src/convertors/toMarkdown/toMdNodeTypeWriters.ts
Expand Up @@ -81,16 +81,8 @@ export const nodeTypeWriters: ToMdNodeTypeWriterMap = {
const emptyNode = node.childCount === 0;

if (emptyNode && prevEmptyNode) {
state.write('<br>\n');
state.write('&#32;\n');
} else if (emptyNode && !prevEmptyNode && !firstChildNode) {
if (parent?.type.name === 'listItem') {
const prevDelim = state.getDelim();

state.setDelim('');
state.write('<br>');

state.setDelim(prevDelim);
}
state.write('\n');
} else {
state.convertInline(node);
Expand Down

0 comments on commit 471fdc2

Please sign in to comment.