Skip to content

Commit

Permalink
Fix whitespace on the ends of italics/bold/strikethrough breaking `fi…
Browse files Browse the repository at this point in the history
…elds.markdoc` (#1178)
  • Loading branch information
emmatown authored Jun 17, 2024
1 parent 34dee8c commit a588cb2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-bulldogs-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystatic/core': patch
---

Fix whitespace on the ends of italics/bold/strikethrough breaking `fields.markdoc`
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function _inline(
{},
textblockChildren(
fragment,
(text): MarkdocNode => new Ast.Node('text', { value: text }),
(content): MarkdocNode => new Ast.Node('text', { content }),
node => getLeafContent(node, state),
mark => getWrapperForMark(mark, state)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,24 @@ test('more', () => {
"
`);
});

for (const [mark, symbol] of [
['bold', '**'],
['italic', '*'],
['strikethrough', '~~'],
] as const) {
test(`whitespace is ejected from ${mark}`, () => {
const editor = (
<doc>
<paragraph>
<text>something</text>
<text {...{ [mark]: true }}>
<cursor /> a{' '}
</text>
<text>something</text>
</paragraph>
</doc>
);
expect(toMarkdoc(editor)).toBe(`something ${symbol}a${symbol} something\n`);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -932,3 +932,24 @@ test('more', () => {
"
`);
});

for (const [mark, symbol] of [
['bold', '**'],
['italic', '*'],
['strikethrough', '~~'],
] as const) {
test(`whitespace is ejected from ${mark}`, () => {
const editor = (
<doc>
<paragraph>
<text>something</text>
<text {...{ [mark]: true }}>
<cursor /> a{' '}
</text>
<text>something</text>
</paragraph>
</doc>
);
expect(toMDX(editor)).toBe(`something ${symbol}a${symbol} something\n`);
});
}

0 comments on commit a588cb2

Please sign in to comment.