Files
outline/shared/editor/lib/markdown/normalize.ts
T
Tom Moor 2f9b30c30c fix: Extra newlines in pasted code blocks (#10958)
* fix: Extra newlines in pasted code blocks

This code is super old, came across with the old markdown editor.

It seems to not have any real effect on well-formatted markdown

* Add tests for normalizePastedMarkdown internal logic (#10959)

* Initial plan

* Add comprehensive tests for normalizePastedMarkdown

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
2025-12-18 18:11:55 -05:00

20 lines
675 B
TypeScript

/**
* Add support for additional syntax that users paste even though it isn't
* supported by the markdown parser directly by massaging the text content.
*
* @param text The incoming pasted plain text
*/
export default function normalizePastedMarkdown(text: string): string {
const CHECKBOX_REGEX = /^\s?(\[(X|\s|_|-)\]\s(.*)?)/gim;
// find checkboxes not contained in a list and wrap them in list items
while (text.match(CHECKBOX_REGEX)) {
text = text.replace(CHECKBOX_REGEX, (match) => `- ${match.trim()}`);
}
// find multiple newlines and insert a hard break to ensure they are respected
text = text.replace(/\n{3,}/g, "\n\n\\\n");
return text;
}