diff --git a/javascript/prompt_format.js b/javascript/prompt_format.js index e476180..ffbc4ac 100644 --- a/javascript/prompt_format.js +++ b/javascript/prompt_format.js @@ -68,12 +68,29 @@ class LeFormatter { return tags; } + /** @param {string} input @returns {string} */ + static #toExpression(input) { + return input + .replace(/[,\n]\s*> <\s*[,\n]/g, ", $SHY$,") + .replace(/[,\n]\s*:3\s*[,\n]/g, ", $CAT$,"); + } + + /** @param {string} input @returns {string} */ + static #fromExpression(input) { + return input + .replace("$SHY$", "> <") + .replace("$CAT$", ":3"); + } + /** @param {string} input @param {boolean} dedupe @param {boolean} removeUnderscore @returns {string} */ static formatString(input, dedupe, removeUnderscore) { // Remove Underscore input = removeUnderscore ? this.#removeUnderscore(input) : input; + // Special Tags + input = this.#toExpression(input); + // Fix Commas inside Brackets input = input .replace(/,+\s*\)/g, '),') @@ -128,6 +145,8 @@ class LeFormatter { // Remove empty before Colon input = input.replace(/\,\s*\:(\d)/g, ':$1'); + input = this.#fromExpression(input); + return input; }