import socket import ssl def htmlescape(text): return text.replace('<', '<').replace('>', '>') def gem2html(gem): html = [] state = 'text' blanklines = 0 for line in gem.split('\n'): if line.startswith('```'): if state == 'pre': newstate = 'text' blanklines = 0 else: newstate = 'pre' elif state == 'pre': newstate = 'pre' elif line.startswith('=>'): newstate = 'links' elif line.startswith('* '): newstate = 'list' else: newstate = 'text' if state != 'pre': if len(line.strip()) == 0: blanklines += 1 if blanklines > 1: html.append('
') continue blanklines = 0 if state != newstate: if state in ('links', 'list'): html.append('') elif state == 'pre': html.append('') if newstate in ('links', 'list'): html.append('