Skip to content

Commit

Permalink
Fix #65 - OSC hyperlinks do not work with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
drudru committed Apr 7, 2021
1 parent 8fc5736 commit aaec94d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ansi_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var PacketKind;
})(PacketKind || (PacketKind = {}));
var AnsiUp = (function () {
function AnsiUp() {
this.VERSION = "5.0.0";
this.VERSION = "5.0.1";
this.setup_palettes();
this._use_classes = false;
this.bold = false;
Expand Down Expand Up @@ -227,7 +227,7 @@ var AnsiUp = (function () {
}
}
if (!this._osc_regex) {
this._osc_regex = rgx(__makeTemplateObject(["\n ^ # beginning of line\n #\n \u001B]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n ([!-~]+) # TEXT capture\n \u001B]8;; # OSC Hyperlink End\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n "], ["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x21-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "]));
this._osc_regex = rgx(__makeTemplateObject(["\n ^ # beginning of line\n #\n \u001B]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n ([ -~]+) # TEXT capture\n \u001B]8;; # OSC Hyperlink End\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n "], ["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x20-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "]));
}
var match = this._buffer.match(this._osc_regex);
if (match === null) {
Expand Down
4 changes: 2 additions & 2 deletions ansi_up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface TextPacket {

class AnsiUp
{
VERSION = "5.0.0";
VERSION = "5.0.1";

//
// *** SEE README ON GITHUB FOR PUBLIC API ***
Expand Down Expand Up @@ -467,7 +467,7 @@ class AnsiUp
| # alternate
(?:\x07) # BEL (what xterm did)
)
([\x21-\x7e]+) # TEXT capture
([\x20-\x7e]+) # TEXT capture
\x1b\]8;; # OSC Hyperlink End
(?: # ST
(?:\x1b\\) # ESC \
Expand Down
4 changes: 2 additions & 2 deletions dist/ansi_up.js.include
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var PacketKind;
})(PacketKind || (PacketKind = {}));
var AnsiUp = (function () {
function AnsiUp() {
this.VERSION = "5.0.0";
this.VERSION = "5.0.1";
this.setup_palettes();
this._use_classes = false;
this.bold = false;
Expand Down Expand Up @@ -208,7 +208,7 @@ var AnsiUp = (function () {
}
}
if (!this._osc_regex) {
this._osc_regex = rgx(__makeTemplateObject(["\n ^ # beginning of line\n #\n \u001B]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n ([!-~]+) # TEXT capture\n \u001B]8;; # OSC Hyperlink End\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n "], ["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x21-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "]));
this._osc_regex = rgx(__makeTemplateObject(["\n ^ # beginning of line\n #\n \u001B]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n ([ -~]+) # TEXT capture\n \u001B]8;; # OSC Hyperlink End\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n "], ["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x20-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "]));
}
var match = this._buffer.match(this._osc_regex);
if (match === null) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansi_up",
"version": "5.0.0",
"version": "5.0.1",
"description": "Convert ansi sequences in strings to colorful HTML",
"keywords": [
"ansi",
Expand Down
8 changes: 8 additions & 0 deletions test/ansi_up-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ describe('ansi_up', function () {
l.should.eql(expected);
});

it('should allow spaces in anchor text', function () {
var start = "ABC \x1b]8;;http://example.com\x1b\\A Link\x1b]8;;\x1b\\ DEF"
var expected = "ABC <a href=\"http://example.com\">A Link</a> DEF";

var au = new AnsiUp();
var l = au.ansi_to_html(start);
l.should.eql(expected);
});

});

Expand Down

0 comments on commit aaec94d

Please sign in to comment.