Skip to content

Commit e6ec43b

Browse files
authored
Merge pull request #3359 from udecode/fix/trim-regex
Replace potentially inefficient RegExp with `String.trim()`
2 parents a6691d7 + 92b0a3a commit e6ec43b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

.changeset/stale-pandas-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@udecode/plate-serializer-md": patch
3+
---
4+
5+
Replace potentially inefficient RegExp with String.trim()

packages/serializer-md/src/serializer/serializeMdNodes.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
serializeMdNode,
1212
} from './serializeMdNode';
1313

14-
const trimNewlines = (str?: string) => str?.replace(/^\s+|\s+$/g, '') ?? '';
15-
1614
/** Convert Slate nodes to Markdown. */
1715
export const serializeMdNodes = (
1816
nodes: TDescendant[],
@@ -51,15 +49,14 @@ export const serializeMdNodes = (
5149
return '';
5250
}
5351

54-
return trimNewlines(
55-
nodes
56-
?.map((v) =>
57-
serializeMdNode(v, {
58-
...options,
59-
customNodes: options.customNodes as any,
60-
nodes: optionsNodes,
61-
})
62-
)
63-
.join('')
64-
);
52+
return nodes
53+
?.map((v) =>
54+
serializeMdNode(v, {
55+
...options,
56+
customNodes: options.customNodes as any,
57+
nodes: optionsNodes,
58+
})
59+
)
60+
.join('')
61+
.trim();
6562
};

0 commit comments

Comments
 (0)