Skip to content

Commit

Permalink
Allow to pass writer to render_html (for saving to string etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
abitrolly committed Apr 7, 2019
1 parent 91a8970 commit c9e801f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/panela/panela_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def parse(self):
# end of line
self.data.append([x, y, None, None, None])

def render_html(self, colorize=True):
def render_html(self, colorize=True, writer=sys.stdout):

prev_style = (None, None)

Expand All @@ -645,30 +645,30 @@ def render_html(self, colorize=True):
if char == None: # end of line
if colorize:
if prev_style != (None, None):
sys.stdout.write("</span>")
writer.write("</span>")
prev_style = (None, None)
sys.stdout.write("\n")
writer.write("\n")
else:
if colorize:
if style != prev_style:
if prev_style != (None, None):
sys.stdout.write("</span>")
writer.write("</span>")
if style != (None, None):
fore = style[0] if style[0] else 'unset'
back = style[1] if style[1] else 'unset'
sys.stdout.write("<span style=\"" +
writer.write("<span style=\"" +
"color: %s; " % fore +
"background-color: %s\">" % back)
prev_style = style

if char == '<':
sys.stdout.write("&lt;")
writer.write("&lt;")
elif char == '>':
sys.stdout.write("&gt;")
writer.write("&gt;")
elif char == '&':
sys.stdout.write("&amp;")
writer.write("&amp;")
else:
sys.stdout.write(char)
writer.write(char)


def apply_mask(self):
Expand Down

0 comments on commit c9e801f

Please sign in to comment.