Skip to content

Commit

Permalink
fix: fix table serialization having incorrect trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
b-kelly committed Apr 12, 2022
1 parent 82cb165 commit 5a4c9b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/rich-text/markdown-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ const customMarkdownSerializerNodes: MarkdownSerializerNodes = {
columnAlignments = serializeTableRow(headRow);
}
});
state.ensureNewLine();

// write table header separator
for (const alignment of columnAlignments) {
Expand All @@ -357,7 +358,6 @@ const customMarkdownSerializerNodes: MarkdownSerializerNodes = {
);
}
state.write("|");
state.ensureNewLine();
}

function serializeTableBody(body: ProsemirrorNode) {
Expand All @@ -366,11 +366,11 @@ const customMarkdownSerializerNodes: MarkdownSerializerNodes = {
serializeTableRow(bodyRow);
}
});
state.ensureNewLine();
}

function serializeTableRow(row: ProsemirrorNode): string[] {
const columnAlignment: string[] = [];
state.ensureNewLine();
row.forEach((cell) => {
if (
cell.type === richTextSchema.nodes.table_header ||
Expand All @@ -381,7 +381,6 @@ const customMarkdownSerializerNodes: MarkdownSerializerNodes = {
}
});
state.write("|");
state.ensureNewLine();
return columnAlignment;
}

Expand Down Expand Up @@ -416,8 +415,7 @@ const customMarkdownSerializerNodes: MarkdownSerializerNodes = {
serializeTableBody(table_child);
});

state.ensureNewLine();
state.write("\n");
state.closeBlock(node);
},

tagLink(state, node) {
Expand Down
8 changes: 5 additions & 3 deletions test/rich-text/markdown-serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe("markdown-serializer", () => {
/**
* Represents different types of data that were rendered differently in markup.
* All entries should render exactly the same before and after rich-text conversion.
* NOTE: some serialization tests are in the tests for the plugin that implemented the feature (e.g. html)
*/
const markupSerializeData = [
/* Nodes */
Expand All @@ -100,7 +101,7 @@ describe("markdown-serializer", () => {
"~~~\ntest\n~~~",
`<pre><code>test</code></pre>`,
`# ATX heading`,
//`Setext heading\n===`,
//`Setext heading\n===`, // TODO
`<h1>html heading</h1>`,
`<h2>html heading</h2>`,
`<h3>html heading</h3>`,
Expand Down Expand Up @@ -150,8 +151,9 @@ describe("markdown-serializer", () => {
`test<br>test`,
`test<br/>test`,
`test<br />test`,
// TODO html_inline, html_block, html_block_container
// TODO stack_snippet, table, taglink, spoiler
/* Tables */
`| foo | bar |\n| --- | --- |\n| baz | bim |`,
`| abc | def | ghi |\n|:---:|:--- | ---:|\n| foo | bar | baz |`,
/* Marks */
`*test*`,
`_test_`,
Expand Down

0 comments on commit 5a4c9b0

Please sign in to comment.