refactor: remove manual clean methods

This commit is contained in:
Shivam Mishra
2023-09-20 13:54:24 +05:30
parent 986e89b7c0
commit 54769850e8
@@ -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);
}
/**