diff --git a/Readme.md b/Readme.md index 23f39fa..e739b67 100644 --- a/Readme.md +++ b/Readme.md @@ -120,6 +120,11 @@ See the examples directory for a complete CSS theme for these classes. ## Properties +#### escape_html +(default: true) + +By default, HTML's reserved characters `& < > " '` are replaced with HTML entities to make them appear as literal characters in your application, rather than being interpreted as HTML structure. If you prefer keeping HTML's reserved characters untouched, you can set this to false. + #### use_classes (default: false) diff --git a/ansi_up.ts b/ansi_up.ts index f2aaf8d..f2abf8b 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 { @@ -176,6 +188,8 @@ class AnsiUp private escape_txt_for_html(txt:string):string { + if (!this._escape_html) + return txt; return txt.replace(/[&<>"']/gm, (str) => { if (str === "&") return "&"; if (str === "<") return "<";