From 0c90817db407e6c1285b190304ca0eb3395ea3b2 Mon Sep 17 00:00:00 2001 From: Haoming Date: Fri, 25 Apr 2025 11:02:16 +0800 Subject: [PATCH] emoticons --- javascript/prompt_format.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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; }