You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
1.1 KiB

def convert_table(lines):
def from_ascii():
out = []
first, header, third, *body, last = lines
first = first.translate(str.maketrans({'-': '', '+': ''}))
out.append(f'┏{first[1:-1]}┓')
header = header.translate(str.maketrans({'|': ''}))
out.append(f'┃{header[1:-1]}┃')
third = third.translate(str.maketrans({'-': '', '+': ''}))
out.append(f'┠{third[1:-1]}┨')
for line in body:
line = line.translate(str.maketrans({'|': ''}))
line = line.replace('yes', '')
out.append(f'┃{line[1:-1]}┃')
last = last.translate(str.maketrans({'-': '', '+': ''}))
out.append(f'┗{last[1:-1]}┛')
return '\n'.join(out)
def from_unicode():
out = []
for line in lines:
line = line.translate(str.maketrans('┏┓┗┛┠┼┨┯┷━─┃│', '+++++++++--||'))
line = line.replace('', 'yes')
out.append(line)
return '\n'.join(out)
if lines[0][0] == '+':
return from_ascii()
return from_unicode()