mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
2f9b30c30c
* 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>
20 lines
675 B
TypeScript
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;
|
|
}
|