From 54769850e823fc957fde740043554f220fac8869 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 20 Sep 2023 13:53:18 +0530 Subject: [PATCH] refactor: remove manual clean methods --- .../dashboard/helper/editorHelper.js | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/app/javascript/dashboard/helper/editorHelper.js b/app/javascript/dashboard/helper/editorHelper.js index 4e3c05d97..795c3af1b 100644 --- a/app/javascript/dashboard/helper/editorHelper.js +++ b/app/javascript/dashboard/helper/editorHelper.js @@ -11,29 +11,12 @@ import { export const SIGNATURE_DELIMITER = '--'; /** - * Remove trailing spaces from each line in a markdown text - * @param {string} markdownText - * @returns - */ -function removeTrailingSpaces(markdownText) { - return markdownText - .split('\n') - .map(line => line.replace(/\s+$/, '')) - .join('\n'); -} - -/** - * Trim the signature and remove all " \r" from the signature - * 1. Trim any extra lines or spaces at the start or end of the string - * 2. Converts all \r or \r\n to \f + * Parse and Serialize the markdown text to remove any extra spaces or new lines */ export function cleanSignature(signature) { // convert from markdown to common mark format const nodes = new MessageMarkdownTransformer(messageSchema).parse(signature); - const md = MessageMarkdownSerializer.serialize(nodes); - - const cleaned = md.trim().replace(/\r\n?/g, '\n'); - return removeTrailingSpaces(cleaned); + return MessageMarkdownSerializer.serialize(nodes); } /**