Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for disabling escaping HTML reserved characters #74

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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