refactor: remove manual clean methods
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user