Skip to content

Commit

Permalink
Merge branch 'feature/fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Mar 30, 2015
2 parents 74c4f1d + 5e55018 commit 100be7c
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 31 deletions.
37 changes: 22 additions & 15 deletions ansi2html/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.

import sys


class Rule(object):

Expand Down Expand Up @@ -49,21 +47,30 @@ def index2(grey):
return str(232 + grey)

# http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
SCHEME = { # black red green brown/yellow blue magenta cyan grey/white
'ansi2html': ("#000316", "#aa0000", "#00aa00", "#aa5500", "#0000aa",
"#E850A8", "#00aaaa", "#F5F1DE"),
'xterm': ("#000000", "#cd0000", "#00cd00", "#cdcd00", "#0000ee",
"#cd00cd", "#00cdcd", "#e5e5e5"),
'xterm-bright': ("#7f7f7f", "#ff0000", "#00ff00", "#ffff00", "#5c5cff",
"#ff00ff", "#00ffff", "#ffffff"),
'osx': ("#000000", "#c23621", "#25bc24", "#adad27", "#492ee1",
"#d338d3", "#33bbc8", "#cbcccd"),
SCHEME = {
# black red green brown/yellow blue magenta cyan grey/white
'ansi2html': (
"#000316", "#aa0000", "#00aa00", "#aa5500",
"#0000aa", "#E850A8", "#00aaaa", "#F5F1DE",
"#7f7f7f", "#ff0000", "#00ff00", "#ffff00",
"#5c5cff", "#ff00ff", "#00ffff", "#ffffff"),

'xterm': (
"#000000", "#cd0000", "#00cd00", "#cdcd00",
"#0000ee", "#cd00cd", "#00cdcd", "#e5e5e5",
"#7f7f7f", "#ff0000", "#00ff00", "#ffff00",
"#5c5cff", "#ff00ff", "#00ffff", "#ffffff"),

'osx': (
"#000000", "#c23621", "#25bc24", "#adad27",
"#492ee1", "#d338d3", "#33bbc8", "#cbcccd") * 2,

# http://ethanschoonover.com/solarized
'solarized': ("#262626", "#d70000", "#5f8700", "#af8700", "#0087ff",
"#af005f", "#00afaf", "#e4e4e4",
"#1c1c1c", "#d75f00", "#585858", "#626262", "#808080",
"#5f5faf", "#8a8a8a", "#ffffd7", ),
'solarized': (
"#262626", "#d70000", "#5f8700", "#af8700",
"#0087ff", "#af005f", "#00afaf", "#e4e4e4",
"#1c1c1c", "#d75f00", "#585858", "#626262",
"#808080", "#5f5faf", "#8a8a8a", "#ffffd7"),
}


Expand Down
35 changes: 34 additions & 1 deletion tests/ansicolor.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
#content { white-space: pre-wrap; word-wrap: break-word; }
.body_foreground { color: #AAAAAA; }
.body_background { background-color: #000000; }
.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { color: #FFFFFF; font-weight: normal; }
Expand Down Expand Up @@ -49,6 +50,38 @@
.inv46 { color: #00aaaa; }
.ansi47 { background-color: #F5F1DE; }
.inv47 { color: #F5F1DE; }
.ansi38-0 { color: #000316; }
.inv38-0 { background-color: #000316; }
.ansi38-1 { color: #aa0000; }
.inv38-1 { background-color: #aa0000; }
.ansi38-2 { color: #00aa00; }
.inv38-2 { background-color: #00aa00; }
.ansi38-3 { color: #aa5500; }
.inv38-3 { background-color: #aa5500; }
.ansi38-4 { color: #0000aa; }
.inv38-4 { background-color: #0000aa; }
.ansi38-5 { color: #E850A8; }
.inv38-5 { background-color: #E850A8; }
.ansi38-6 { color: #00aaaa; }
.inv38-6 { background-color: #00aaaa; }
.ansi38-7 { color: #F5F1DE; }
.inv38-7 { background-color: #F5F1DE; }
.ansi48-0 { background-color: #000316; }
.inv48-0 { color: #000316; }
.ansi48-1 { background-color: #aa0000; }
.inv48-1 { color: #aa0000; }
.ansi48-2 { background-color: #00aa00; }
.inv48-2 { color: #00aa00; }
.ansi48-3 { background-color: #aa5500; }
.inv48-3 { color: #aa5500; }
.ansi48-4 { background-color: #0000aa; }
.inv48-4 { color: #0000aa; }
.ansi48-5 { background-color: #E850A8; }
.inv48-5 { color: #E850A8; }
.ansi48-6 { background-color: #00aaaa; }
.inv48-6 { color: #00aaaa; }
.ansi48-7 { background-color: #F5F1DE; }
.inv48-7 { color: #F5F1DE; }
.ansi38-16 { color: #000000; }
.inv38-16 { background: #000000; }
.ansi48-16 { background: #000000; }
Expand Down Expand Up @@ -1012,7 +1045,7 @@
</style>
</head>
<body class="body_foreground body_background" style="font-size: normal;" >
<pre>
<pre id="content">
<span class="ansi40"></span><span class="ansi30 ansi40"> black </span><span class="ansi31 ansi40"> red </span><span class="ansi32 ansi40"> green </span><span class="ansi33 ansi40"> yellow </span><span class="ansi34 ansi40"> blue </span><span class="ansi35 ansi40"> magenta</span><span class="ansi36 ansi40"> cyan </span><span class="ansi37 ansi40"> white </span>
<span class="ansi1"></span><span class="ansi1 ansi40"></span><span class="ansi1 ansi30 ansi40"> black </span><span class="ansi1 ansi31 ansi40"> red </span><span class="ansi1 ansi32 ansi40"> green </span><span class="ansi1 ansi33 ansi40"> yellow </span><span class="ansi1 ansi34 ansi40"> blue </span><span class="ansi1 ansi35 ansi40"> magenta</span><span class="ansi1 ansi36 ansi40"> cyan </span><span class="ansi1 ansi37 ansi40"> white </span>
<span class="ansi41"></span><span class="ansi30 ansi41"> black </span><span class="ansi31 ansi41"> red </span><span class="ansi32 ansi41"> green </span><span class="ansi33 ansi41"> yellow </span><span class="ansi34 ansi41"> blue </span><span class="ansi35 ansi41"> magenta</span><span class="ansi36 ansi41"> cyan </span><span class="ansi37 ansi41"> white </span>
Expand Down
35 changes: 34 additions & 1 deletion tests/ansicolor_eix.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
#content { white-space: pre-wrap; word-wrap: break-word; }
.body_foreground { color: #AAAAAA; }
.body_background { background-color: #000000; }
.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { color: #FFFFFF; font-weight: normal; }
Expand Down Expand Up @@ -49,6 +50,38 @@
.inv46 { color: #00aaaa; }
.ansi47 { background-color: #F5F1DE; }
.inv47 { color: #F5F1DE; }
.ansi38-0 { color: #000316; }
.inv38-0 { background-color: #000316; }
.ansi38-1 { color: #aa0000; }
.inv38-1 { background-color: #aa0000; }
.ansi38-2 { color: #00aa00; }
.inv38-2 { background-color: #00aa00; }
.ansi38-3 { color: #aa5500; }
.inv38-3 { background-color: #aa5500; }
.ansi38-4 { color: #0000aa; }
.inv38-4 { background-color: #0000aa; }
.ansi38-5 { color: #E850A8; }
.inv38-5 { background-color: #E850A8; }
.ansi38-6 { color: #00aaaa; }
.inv38-6 { background-color: #00aaaa; }
.ansi38-7 { color: #F5F1DE; }
.inv38-7 { background-color: #F5F1DE; }
.ansi48-0 { background-color: #000316; }
.inv48-0 { color: #000316; }
.ansi48-1 { background-color: #aa0000; }
.inv48-1 { color: #aa0000; }
.ansi48-2 { background-color: #00aa00; }
.inv48-2 { color: #00aa00; }
.ansi48-3 { background-color: #aa5500; }
.inv48-3 { color: #aa5500; }
.ansi48-4 { background-color: #0000aa; }
.inv48-4 { color: #0000aa; }
.ansi48-5 { background-color: #E850A8; }
.inv48-5 { color: #E850A8; }
.ansi48-6 { background-color: #00aaaa; }
.inv48-6 { color: #00aaaa; }
.ansi48-7 { background-color: #F5F1DE; }
.inv48-7 { color: #F5F1DE; }
.ansi38-16 { color: #000000; }
.inv38-16 { background: #000000; }
.ansi48-16 { background: #000000; }
Expand Down Expand Up @@ -1012,7 +1045,7 @@
</style>
</head>
<body class="body_foreground body_background" style="font-size: normal;" >
<pre>
<pre id="content">
<span class="ansi38-252 ansi40">[</span><span class="ansi1 inv38-87 inv40">U</span><span class="ansi40"></span><span class="ansi38-252 ansi40">]</span><span class="ansi40"> </span><span class="ansi38-252 ansi40">dev-python</span><span class="ansi38-252 ansi40">/</span><span class="ansi1 ansi38-253 ansi40">pysvn</span><span class="ansi40"></span>
<span class="ansi40"> </span><span class="ansi38-34 ansi40">Available versions:</span><span class="ansi40"> </span><span class="ansi38-46 ansi40">1.7.6</span><span class="ansi40"> </span><span class="ansi38-190 ansi40">(~)</span><span class="inv38-190 inv40">1.7.7</span><span class="ansi40"></span><span class="ansi38-99 ansi40">^t</span><span class="ansi40"></span><span class="ansi1 ansi38-39 ansi40">{tbz2}</span><span class="ansi40"> </span><span class="ansi38-190 ansi40">(~)</span><span class="ansi1 ansi38-190 ansi40">1.7.8</span><span class="ansi40"></span><span class="ansi38-99 ansi40">^t</span><span class="ansi40"> </span><span class="ansi38-252 ansi40">{</span><span class="ansi38-38 ansi40">doc examples </span><span class="ansi38-115 ansi40">PYTHON_TARGETS="</span><span class="ansi38-38 ansi40">python2_6 python2_7 python3_2 python3_3</span><span class="ansi38-115 ansi40">"</span><span class="ansi40"></span><span class="ansi38-252 ansi40">}</span><span class="ansi40"></span>
<span class="ansi40"> </span><span class="ansi38-34 ansi40">Installed versions:</span><span class="ansi40"> </span><span class="ansi1 ansi38-33 ansi40">1.7.7</span><span class="ansi40"></span><span class="ansi38-99 ansi40">^t</span><span class="ansi40"></span><span class="ansi1 ansi38-39 ansi40">{tbz2}</span><span class="ansi40"></span><span class="ansi38-166 ansi40">(22:19:41 13.03.2013)</span><span class="ansi40"></span><span class="ansi38-252 ansi40">(</span><span class="ansi38-33 ansi40">-doc</span><span class="ansi40"> </span><span class="ansi38-33 ansi40">-examples</span><span class="ansi40"> </span><span class="ansi38-115 ansi40">PYTHON_TARGETS="</span><span class="ansi1 ansi38-125 ansi40">python2_7</span><span class="ansi40"> </span><span class="ansi1 ansi38-125 ansi40">python3_2</span><span class="ansi40"> </span><span class="ansi38-33 ansi40">-python2_5</span><span class="ansi40"> </span><span class="ansi38-33 ansi40">-python2_6</span><span class="ansi40"> </span><span class="ansi38-33 ansi40">-python3_1</span><span class="ansi40"></span><span class="ansi38-115 ansi40">"</span><span class="ansi40"></span><span class="ansi38-252 ansi40">)</span><span class="ansi40"></span>
Expand Down
33 changes: 33 additions & 0 deletions tests/produce_headers.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<style type="text/css">
#content { white-space: pre-wrap; word-wrap: break-word; }
.body_foreground { color: #AAAAAA; }
.body_background { background-color: #000000; }
.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { color: #FFFFFF; font-weight: normal; }
Expand Down Expand Up @@ -44,6 +45,38 @@
.inv46 { color: #00aaaa; }
.ansi47 { background-color: #F5F1DE; }
.inv47 { color: #F5F1DE; }
.ansi38-0 { color: #000316; }
.inv38-0 { background-color: #000316; }
.ansi38-1 { color: #aa0000; }
.inv38-1 { background-color: #aa0000; }
.ansi38-2 { color: #00aa00; }
.inv38-2 { background-color: #00aa00; }
.ansi38-3 { color: #aa5500; }
.inv38-3 { background-color: #aa5500; }
.ansi38-4 { color: #0000aa; }
.inv38-4 { background-color: #0000aa; }
.ansi38-5 { color: #E850A8; }
.inv38-5 { background-color: #E850A8; }
.ansi38-6 { color: #00aaaa; }
.inv38-6 { background-color: #00aaaa; }
.ansi38-7 { color: #F5F1DE; }
.inv38-7 { background-color: #F5F1DE; }
.ansi48-0 { background-color: #000316; }
.inv48-0 { color: #000316; }
.ansi48-1 { background-color: #aa0000; }
.inv48-1 { color: #aa0000; }
.ansi48-2 { background-color: #00aa00; }
.inv48-2 { color: #00aa00; }
.ansi48-3 { background-color: #aa5500; }
.inv48-3 { color: #aa5500; }
.ansi48-4 { background-color: #0000aa; }
.inv48-4 { color: #0000aa; }
.ansi48-5 { background-color: #E850A8; }
.inv48-5 { color: #E850A8; }
.ansi48-6 { background-color: #00aaaa; }
.inv48-6 { color: #00aaaa; }
.ansi48-7 { background-color: #F5F1DE; }
.inv48-7 { color: #F5F1DE; }
.ansi38-16 { color: #000000; }
.inv38-16 { background: #000000; }
.ansi48-16 { background: #000000; }
Expand Down
21 changes: 7 additions & 14 deletions tests/test_ansi2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from mock import patch
from nose.tools import eq_

import cgi
import unittest
import six
import textwrap
Expand All @@ -42,6 +41,7 @@


class TestAnsi2HTML(unittest.TestCase):
maxDiff = None

def test_linkify(self):
ansi = "http://threebean.org"
Expand Down Expand Up @@ -70,12 +70,9 @@ def test_conversion(self):
if html and html[-1] == '':
html = html[:-1]

eq_(len(html), len(expected_data))

for idx in range(len(expected_data)):
expected = expected_data[idx]
actual = html[idx]
self.assertEqual(expected, actual)
self.assertEqual(
'\n'.join(html),
'\n'.join(expected_data))

@patch("sys.argv", new_callable=lambda: ["ansi2html"])
@patch("sys.stdout", new_callable=six.StringIO)
Expand All @@ -96,8 +93,7 @@ def test_conversion_as_command(self, mock_stdout, mock_argv):

html = mock_stdout.getvalue()

eq_(len(html), len(expected_data), "Strings are not the same length.")
eq_(html, expected_data, "Strings are not the same.")
self.assertEqual(html, expected_data)

def test_unicode(self):
""" Ensure that the converter returns unicode(py2)/str(py3) objs. """
Expand Down Expand Up @@ -182,16 +178,13 @@ def test_inline(self):

def test_produce_headers(self):
conv = Ansi2HTMLConverter()
headers = conv.produce_headers().split("\n")
headers = conv.produce_headers()

inputfile = join(_here, "produce_headers.txt")
with open(inputfile, "rb") as produce_headers:
expected_data = read_to_unicode(produce_headers)

for idx in range(len(expected_data)):
expected = expected_data[idx].strip()
actual = headers[idx].strip()
self.assertEqual(expected, actual)
self.assertMultiLineEqual(headers, ''.join(expected_data))

def test_escaped_implicit(self):
test = "<p>awesome</p>"
Expand Down

0 comments on commit 100be7c

Please sign in to comment.