Skip to content

Commit 4efe4fa

Browse files
committed
Render .pnl as .html (without background colors for now)
1 parent 4afec1e commit 4efe4fa

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lib/panela/panela_colors.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def __init__(self):
570570

571571
# [x, y, char, color, bg_color], ...
572572
# colors are in #000000 format or None
573+
# char is None for the end of line
573574
self.data = []
574575

575576
self._colors = {
@@ -622,6 +623,7 @@ def parse(self):
622623
self.data = []
623624

624625
for y, line in enumerate(lines):
626+
x = 0
625627
for x, char in enumerate(line):
626628
color = None
627629
bg_color = None
@@ -632,6 +634,39 @@ def parse(self):
632634
bg_color = self._bg_colors.get(m)
633635

634636
self.data.append([x, y, char, color, bg_color])
637+
# end of line
638+
self.data.append([x, y, None, None, None])
639+
640+
def render_html(self, colorize=True):
641+
642+
prev_color = None
643+
prev_bg = None
644+
645+
for x, y, char, color, bg_color in self.data:
646+
if char == None: # end of line
647+
if colorize:
648+
if prev_color != None:
649+
sys.stdout.write("</span>")
650+
prev_color = None
651+
sys.stdout.write("\n")
652+
else:
653+
if colorize:
654+
if color != prev_color:
655+
if prev_color != None:
656+
sys.stdout.write("</span>")
657+
if color != None:
658+
sys.stdout.write("<span style=\"color: %s\">" % color)
659+
prev_color = color
660+
661+
if char == '<':
662+
sys.stdout.write("&lt;")
663+
elif char == '>':
664+
sys.stdout.write("&gt;")
665+
elif char == '&':
666+
sys.stdout.write("&amp;")
667+
else:
668+
sys.stdout.write(char)
669+
635670

636671
def apply_mask(self):
637672

lib/pnl2html.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
head = '''\
77
<title></title>
8+
<style>
9+
body {
10+
color: white;
11+
background-color: black;
12+
}
13+
</style>
814
<pre>
915
'''
1016

@@ -27,8 +33,11 @@
2733
pnl = Template()
2834
pnl.read(pnlfile)
2935
pnl.parse()
30-
pnl.apply_mask()
31-
print(pnl.show())
36+
pnl.render_html()
37+
38+
#pnl.apply_mask()
39+
#print(pnl.show())
40+
3241

3342
print(foot)
3443

0 commit comments

Comments
 (0)