Skip to content

Commit

Permalink
Merge pull request #74 from Taitava/Taitava-option-disable-escape
Browse files Browse the repository at this point in the history
Option for disabling escaping HTML reserved characters
  • Loading branch information
drudru authored Mar 31, 2023
2 parents 94cc84b + 88a8362 commit 4177b16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://www.w3schools.com/html/html_entities.asp">HTML entities</a> 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)

Expand Down
14 changes: 14 additions & 0 deletions ansi_up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class AnsiUp
private _osc_regex:RegExp;

private _url_whitelist:{};
private _escape_html:boolean;

private _buffer:string;

Expand All @@ -93,6 +94,7 @@ class AnsiUp
this._buffer = '';

this._url_whitelist = { 'http':1, 'https':1 };
this._escape_html = true;
}

set use_classes(arg:boolean)
Expand All @@ -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
{
Expand Down Expand Up @@ -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 "&amp;";
if (str === "<") return "&lt;";
Expand Down

0 comments on commit 4177b16

Please sign in to comment.