From 058732bb76ecfcee5c5967e8cd10e5c98d4459ef Mon Sep 17 00:00:00 2001 From: Jarkko Linnanvirta Date: Sun, 19 Mar 2023 07:22:10 +0200 Subject: [PATCH] Option for disabling escaping --- ansi_up.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ansi_up.ts b/ansi_up.ts index f2aaf8d..b0cccad 100644 --- a/ansi_up.ts +++ b/ansi_up.ts @@ -76,6 +76,7 @@ class AnsiUp private _osc_regex:RegExp; private _url_whitelist:{}; + private _escape_html:boolean; private _buffer:string; @@ -93,6 +94,7 @@ class AnsiUp this._buffer = ''; this._url_whitelist = { 'http':1, 'https':1 }; + this._escape_html = true; } set use_classes(arg:boolean) @@ -115,6 +117,16 @@ class AnsiUp return this._url_whitelist; } + set escape_html(arg:boolean) + { + this._escape_html = arg; + } + + get escape_html():boolean + { + return this._escape_html; + } + private setup_palettes():void { @@ -649,7 +661,8 @@ class AnsiUp if (txt.length === 0) return txt; - txt = this.escape_txt_for_html(txt); + if (this._escape_html) + txt = this.escape_txt_for_html(txt); // If colors not set, default style is used if (!fragment.bold && !fragment.italic && !fragment.underline && fragment.fg === null && fragment.bg === null) @@ -717,7 +730,9 @@ class AnsiUp if (! this._url_whitelist[parts[0]]) return ''; - let result = `${this.escape_txt_for_html(pkt.text)}`; + let result = `${this._escape_html ? this.escape_txt_for_html(pkt.text) : pkt.text}`; + // Escape href="" even if this._escape_html is false, to avoid breaking the in case pkt.url contains a double quote. + return result; } }