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.

26 lines
1.1 KiB

  1. def convert_table(lines):
  2. def from_ascii():
  3. out = []
  4. first, header, third, *body, last = lines
  5. first = first.translate(str.maketrans({'-': '', '+': ''}))
  6. out.append(f'┏{first[1:-1]}┓')
  7. header = header.translate(str.maketrans({'|': ''}))
  8. out.append(f'┃{header[1:-1]}┃')
  9. third = third.translate(str.maketrans({'-': '', '+': ''}))
  10. out.append(f'┠{third[1:-1]}┨')
  11. for line in body:
  12. line = line.translate(str.maketrans({'|': ''}))
  13. line = line.replace('yes', '')
  14. out.append(f'┃{line[1:-1]}┃')
  15. last = last.translate(str.maketrans({'-': '', '+': ''}))
  16. out.append(f'┗{last[1:-1]}┛')
  17. return '\n'.join(out)
  18. def from_unicode():
  19. out = []
  20. for line in lines:
  21. line = line.translate(str.maketrans('┏┓┗┛┠┼┨┯┷━─┃│', '+++++++++--||'))
  22. line = line.replace('', 'yes')
  23. out.append(line)
  24. return '\n'.join(out)
  25. if lines[0][0] == '+':
  26. return from_ascii()
  27. return from_unicode()