Skip to content

Commit

Permalink
Merge pull request #3359 from udecode/fix/trim-regex
Browse files Browse the repository at this point in the history
Replace potentially inefficient RegExp with `String.trim()`
  • Loading branch information
12joan authored Jul 13, 2024
2 parents a6691d7 + 92b0a3a commit e6ec43b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-pandas-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-serializer-md": patch
---

Replace potentially inefficient RegExp with String.trim()
23 changes: 10 additions & 13 deletions packages/serializer-md/src/serializer/serializeMdNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
serializeMdNode,
} from './serializeMdNode';

const trimNewlines = (str?: string) => str?.replace(/^\s+|\s+$/g, '') ?? '';

/** Convert Slate nodes to Markdown. */
export const serializeMdNodes = (
nodes: TDescendant[],
Expand Down Expand Up @@ -51,15 +49,14 @@ export const serializeMdNodes = (
return '';
}

return trimNewlines(
nodes
?.map((v) =>
serializeMdNode(v, {
...options,
customNodes: options.customNodes as any,
nodes: optionsNodes,
})
)
.join('')
);
return nodes
?.map((v) =>
serializeMdNode(v, {
...options,
customNodes: options.customNodes as any,
nodes: optionsNodes,
})
)
.join('')
.trim();
};

0 comments on commit e6ec43b

Please sign in to comment.