MV Coloring text inside JS plugin doesn't work

I'm fixing some stuff in my project like removing not used resources (imgs, snds, js's) and generaly reorganizing my project and I've encountered strange thing... Very strange though...

This is my plugin allowing to obtain text from external txt file
Spoiler
JavaScript:
/*:
* @plugindesc v1.00 Allows to display dialouges from external txt file
* @help Requires Yanfly's Message Core for most comfortable usage
*
* @author Soulrender
*
* @param --Settings--
* @default
*
* @param Main Directory
* @parent --Settings--
* @type Text
* @desc Specify your directory for dialouges, place it in game project folder
* @default data_proto
*
* @param File name prefix
* @parent --Settings--
* @type Text
* @desc It can be any text you want, but I recommend to use very familiar word to you
* @default Map
*
* @param Use Asynchronous Requests
* @parent --Settings--
* @type boolean
* @default false
* @desc asynchronous requests should be preferred to synchronous requests for performance reasons.
*
* @param --Colors--
* @default
*
* @param Actor Name Color
* @parent --Colors--
* @type Text
* @desc Choose HEX color for actor name
* @default ffcc00
*
* @param Actor Message Color
* @parent --Colors--
* @type Text
* @desc Every message will be colored with that hex, unless you use another coloring tag inside message
* @default ffffff
*/

var soulrender = soulrender || {};
soulrender.Parameters = PluginManager.parameters('SOL_DialougesFromTxt');
soulrender.directory = String(soulrender.Parameters['Main Directory'] || "data_proto");
soulrender.filePrefix = String(soulrender.Parameters['File name prefix'] || "Map");
soulrender.asyncRequests = soulrender.Parameters['Use Asynchronous Requests'] || false;
soulrender.actorNameColor = (soulrender.Parameters['Actor Name Color'] || 'ffcc00');
soulrender.actorMsgColor = (soulrender.Parameters['Actor Message Color'] || 'ffffff');


Game_System.prototype.readFile = function(filename){
    var xhr = new XMLHttpRequest();
    xhr.async = soulrender.asyncRequests;
  
    try{
        xhr.open("GET", filename, false);
        xhr.send(null);
        var fileContent = xhr.responseText;
        return fileContent; 
    }catch(e){
        console.log(e.stack);
    }
  
}

Game_System.prototype.explode = function(txt, delim){
    try{
        var source = txt.split(delim);
        if (source){
            return source;
        }
        else return false; 
    }catch(e){
        console.log(e.stack);
    }
}

Game_System.prototype.obtainData = function(id, database){
  
    var data = this.readFile('./' + soulrender.directory + '/' + database + '.txt');
    var proto = this.explode(data, "\n");
    var item = this.explode(proto[id], "|");
    return item;
}

Game_System.prototype.getSpeechFileByMapId = function(){

    var mapId = $gameMap._mapId;
    var file = soulrender.filePrefix + mapId.padZero(3);
    return file;
}

Game_System.prototype.ShowText = function(line){
  
    var aFile = this.getSpeechFileByMapId();
    var source = this.obtainData(line - 1, aFile);
    var actorName = source[0];
    var actorSpeech = source[1];
    var displayLine = '';
  
    if (Imported.YEP_MessageCore && Imported.YEP_X_ExtMesPack1)
    {
        displayLine = "\\hc[" + String(soulrender.actorNameColor) + "]" + actorName + ": \\hc[" + String(soulrender.actorMsgColor) + "]" + actorSpeech;
    }
    else
        {
            displayLine = "\\c[6]" + actorName + ": \\c[0]" + actorSpeech;
        }
    return displayLine;
}
So... The main issue is... While I pass any string with text code (any, like \c[color]) it's not parsed if it from any JS file, final output text always looks the same, displaying broken tags (like in this image - https://prnt.sc/w0razh) and it should look like this https://prnt.sc/w0rc8s

I tried everything (starting new projects several times, all plugins where removed, I've just keeped Message Core and it's extensions and still nothing. But in backup copy wich is made on the same version of MV (1.6.2) this problem does not exists...

EDIT:\\
I'm using this method to execute JS evals in MessageBoxes:

JavaScript:
(function(){
var _sol_convertAlias = Window_Base.prototype.convertEscapeCharacters;

    Window_Base.prototype.convertEscapeCharacters = function(text) {
       text = _sol_convertAlias.call(this, text);
       text = text.replace(/\x1bjs\[".*?"\]/gi, function() {
        if(SceneManager._scene.actor===undefined)
            var a = $gameParty.leader();
             else{
        var a = SceneManager._scene.actor();
       }
             var form = arguments[0].split("[\"")[1].split("\"]")[0];
             return eval(form);
       }.bind(this));
           text = text.replace(/\x1bjsv\[".*?"\]/gi, function() {
         var v = $gameVariables._data;
             var form = arguments[0].split("[\"")[1].split("\"]")[0];
             return eval(form);
       }.bind(this));
       return text;
    };  
})();
and that way I show obtained text from file - https://prnt.sc/w0rfxk
first guess would be that you need to double the escape code symbol
basically \\c[1] instead of \c[1].
I haven't checked your code, but that is a common problem when strings are processed to be processed again later
I have some experience in JS and I know how it works...

To parse text tag in JS double slash is needed.
if i had to guess, the problem is you're putting a variable into the color code ( \c[color]) and MV expects a number. you get this same issue when you try this with the game variables. you can't pass a variable into them, only an actual number. even forcing the variable type won't work, from my experience. someone with more knowledge may be able to help here, but i tried everything i could think of and it couldn't be done. must be in the MV/MZ core but i never went looking for it since it was easier to just abandon my planned feature.
I notice you've used a custom code \hc to change the colour (one of Yanfly's?). I assume that code has its own method for matching non-integer arguments.

From your screenshots, I think the expected output from the eval should be:
JavaScript:
'\x1bhc[ffcc00]Tallanar: \x1bhc[ffffff]'
Maybe manually replace backslashes in the eval result?
@caethyril The thing is... when I run in console following code:

$gameMessage.add($gameSystem.ShowText(1)) everythings work fine
And yes, that's Yanfly's tag from YEP_X_ExtMesPack1.js

but your answer actually fixed problem... But still I don't understand why on new project this code didn't work, while on old everything was fine... having the same version of core files...

On MZ also works fine without x1b tag.
so far I know, color codes dont work really in variables, and \x1b is used for
colors inside variables.

but it's also complcated in many ways, which Idont quite understand the \hc
or other parts of color/escape codes quite yet.
@Soulrender it needs to be \x1b here simply because you're running the code after the original method, in which backslashes get replaced:
JavaScript:
text = text.replace(/\\/g, "\x1b");
text = text.replace(/\x1b\x1b/g, "\\");
When you do $gameMessage.add($gameSystem.ShowText(1)), you're feeding the text in from the start, i.e. it'll have its backslashes replaced. If I recall correctly, MZ uses the same structure for all of this, so the same logic applies.

Note that \x1b is simply another character, "ESC" = ASCII 0x1B (27 in decimal). \x## is native JS string escape notation, typically used to write characters without a more convenient representation.

Perhaps you edited your plugin since successfully testing it (e.g. moving the replacement from before the alias to after), but forgot you made the edit? I've done that before... 😴

Regardless, good to hear it's working! 😂
@caethyril Another excelent answer, but too bad we are far away from each other, because I would immediately buy the finest 6-pack of beer and deliver it personally to you 🙂 (Yes, there were some edits... But I forgot what I did ... )

Original thread: https://forums.rpgmakerweb.com/threads/coloring-text-inside-js-plugin-doesnt-work.130870/