Skip to content

Commit

Permalink
Merge pull request #23 from JensTimmerman/python2.4
Browse files Browse the repository at this point in the history
Python2.4
  • Loading branch information
ralphbean committed Oct 22, 2012
2 parents e40b727 + 966a77b commit 6fcc5ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ansi2html/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .converter import Ansi2HTMLConverter
from ansi2html.converter import Ansi2HTMLConverter
__all__ = ['Ansi2HTMLConverter']
29 changes: 14 additions & 15 deletions ansi2html/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
from __future__ import print_function

import re
import sys
Expand All @@ -28,20 +27,20 @@
except ImportError:
from ordereddict import OrderedDict

from .style import get_styles
from ansi2html.style import get_styles
import six
from six.moves import map
from six.moves import zip

_template = six.u("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset={output_encoding}">
<style type="text/css">\n{style}\n</style>
<meta http-equiv="Content-Type" content="text/html; charset=%(output_encoding)s">
<style type="text/css">\n%(style)s\n</style>
</head>
<body class="body_foreground body_background" style="font-size: {font_size};" >
<body class="body_foreground body_background" style="font-size: %(font_size)s;" >
<pre>
{content}
%(content)s
</pre>
</body>
Expand Down Expand Up @@ -214,17 +213,17 @@ def convert(self, ansi, full=True):
if not full:
return attrs["body"]
else:
return _template.format(
style="\n".join(map(str, get_styles(self.dark_bg))),
font_size=self.font_size,
content=attrs["body"],
output_encoding=self.output_encoding,
)
return _template % {
'style' : "\n".join(map(str, get_styles(self.dark_bg))),
'font_size' : self.font_size,
'content' : attrs["body"],
'output_encoding' : self.output_encoding,
}

def produce_headers(self):
return '<style type="text/css">\n{style}\n</style>\n'.format(
style="\n".join(map(str, get_styles(self.dark_bg)))
)
return '<style type="text/css">\n%(style)s\n</style>\n' % {
'style' : "\n".join(map(str, get_styles(self.dark_bg)))
}


def main():
Expand Down
8 changes: 3 additions & 5 deletions ansi2html/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals
from __future__ import absolute_import
import sys


Expand Down Expand Up @@ -51,10 +49,10 @@ def index2(grey):
def get_styles(dark_bg=True):

css = [
Rule('.body_foreground', color='#AAAAAA' if dark_bg else '#000000'),
Rule('.body_background', background_color="#000000" if dark_bg else "#AAAAAA"),
Rule('.body_foreground', color=('#000000', '#AAAAAA')[dark_bg]),
Rule('.body_background', background_color=('#AAAAAA', '#000000')[dark_bg]),
Rule('.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold',
color="#FFFFFF" if dark_bg else "#000000", font_weight="normal" if dark_bg else "bold"),
color=('#000000', '#FFFFFF')[dark_bg], font_weight=('bold', 'normal')[dark_bg]),
Rule('.ansi1', font_weight='bold'),
Rule('.ansi3', font_weight='italic'),
Rule('.ansi4', text_decoration='underline'),
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

# Ridiculous as it may seem, we need to import multiprocessing and
# logging here in order to get tests to pass smoothly on python 2.7.
import multiprocessing

# no multiprocessing in python < 2.6
#import multiprocessing
import logging

requires = [
Expand Down

0 comments on commit 6fcc5ab

Please sign in to comment.