commit 79d7715fcecf3a0ab9f1e0a380b5140e03fefcd0
Author: jakub-g <jakub.g.opensource@gmail.com>
Date: Sun Feb 15 03:40:36 2015 +0100
fix Extra closing escape at EOL breaking stuff
diff --git a/examples/git-show.htm b/examples/git-show.htm
new file mode 100644
index 0000000..daa096c
--- /dev/null
+++ b/examples/git-show.htm
@@ -0,0 +1,29 @@
+<!DOCTYPE html><html><head><meta charset="utf-8"><style> .ansi_bold{font-weight:bold} .ansi_italic{font-style:italic} .ansi_console_snippet{font-family:monospace; white-space: pre; display: block; unicode-bidi: embed; overflow:auto; padding:5px;} .ansi_console_snippet{ background-color:#222222; color:#eeeeee; } .ansi_fg_black {color:#222222} .ansi_fg_red {color:#dd0000} .ansi_fg_green {color:#00cc3e} .ansi_fg_yellow {color:#eeee00} .ansi_fg_blue {color:#0099ff} .ansi_fg_purple {color:#bb00bb} .ansi_fg_cyan {color:#eeeeee} .ansi_fg_white {color:#eeeeee} .ansi_bg_black {background-color:#222222} .ansi_bg_red {background-color:#dd0000} .ansi_bg_green {background-color:#00cc3e} .ansi_bg_yellow {background-color:#eeee00} .ansi_bg_blue {background-color:#0099ff} .ansi_bg_purple {background-color:#bb00bb} .ansi_bg_cyan {background-color:#eeeeee} .ansi_bg_white {background-color:#eeeeee} </style></head><body>
+<span class="ansi_console_snippet"><span class="ansi_fg_yellow">commit 64a950282b54aa65eedefbd277e49fdf82f4ecd9</span>
+Author: jakub-g <jakub.g.opensource@gmail.com>
+Date: Sun Feb 15 03:20:37 2015 +0100
+
+ 0.0.1
+
+<span class="">diff --git a/package.json b/package.json</span>
+<span class="">index 0c715cb..5cf9e49 100644</span>
+<span class="">--- a/package.json</span>
+<span class="">+++ b/package.json</span>
+<span class="ansi_fg_cyan">@@ -1,6 +1,6 @@</span>
+ {
+ "name": "ansi2html-extended",
+<span class="ansi_fg_white ansi_bg_red">- "version": "0.0.0",</span>
+<span class="ansi_fg_green">+</span><span class="ansi_fg_green"> "version": "0.0.1",</span>
+ "description": "Convert colored console output (ANSI shell escape codes) to HTML.",
+ "author": "Jakub Gieryluk <jakub.g.opensource@gmail.com>",
+ "license": "MIT",
+<span class="ansi_fg_cyan">@@ -31,7 +31,5 @@</span>
+ "devDependencies": {
+ "jshint": "2.5.10"
+ },
+<span class="ansi_fg_white ansi_bg_red">- "dependencies": {</span>
+<span class="ansi_fg_white ansi_bg_red">- }</span>
+<span class="ansi_fg_green">+</span><span class="ansi_fg_green"> "dependencies": {}</span>
+ }
+<span class="ansi_fg_white ansi_bg_red">-</span>
+</span></body></html>
\ No newline at end of file
diff --git a/examples/git-show.txt b/examples/git-show.txt
new file mode 100644
index 0000000..711e0d9
--- /dev/null
+++ b/examples/git-show.txt
@@ -0,0 +1,27 @@
+commit 64a950282b54aa65eedefbd277e49fdf82f4ecd9
+Author: jakub-g <jakub.g.opensource@gmail.com>
+Date: Sun Feb 15 03:20:37 2015 +0100
+
+ 0.0.1
+
+diff --git a/package.json b/package.json
+index 0c715cb..5cf9e49 100644
+--- a/package.json
++++ b/package.json
+@@ -1,6 +1,6 @@
+ {
+ "name": "ansi2html-extended",
+- "version": "0.0.0",
++ "version": "0.0.1",
+ "description": "Convert colored console output (ANSI shell escape codes) to HTML.",
+ "author": "Jakub Gieryluk <jakub.g.opensource@gmail.com>",
+ "license": "MIT",
+@@ -31,7 +31,5 @@
+ "devDependencies": {
+ "jshint": "2.5.10"
+ },
+- "dependencies": {
+- }
++ "dependencies": {}
+ }
+-
diff --git a/lib/ansi2html.js b/lib/ansi2html.js
index a41a0fa..96345be 100644
--- a/lib/ansi2html.js
+++ b/lib/ansi2html.js
@@ -81,7 +81,15 @@ var footer = '</body></html>';
*/
function processString (inputString, options) {
inputString = options.escapeHtml ? escapeHtml(inputString) : inputString;
- return ansispan2(inputString);
+ var str = ansispan2(inputString);
+ var openSpanCount = (str.match(/<span/g) || []).length;
+ var closeSpanCount = (str.match(/<\/span/g) || []).length;
+ if (closeSpanCount > openSpanCount) {
+ // we may have extra closing escape sequence at the end of the line
+ // that doesn't really close anything
+ str = str.replace(/<\/span>$/, "");
+ }
+ return str;
}
/**