[F] Fix tripple-quote escaping #222
This commit is contained in:
parent
807eed022d
commit
caa1547e8c
13 changed files with 63 additions and 36 deletions
|
|
@ -141,16 +141,20 @@ def export_distro(d: AsciiArt) -> str:
|
|||
|
||||
# Escape/unescape ascii
|
||||
ascii = d.ascii.replace("\\\\", "\\")
|
||||
while '"""' in ascii:
|
||||
ascii = ascii.replace('"""', '"\\""')
|
||||
|
||||
quotes = '"""'
|
||||
if '"""' in ascii:
|
||||
quotes = "'''"
|
||||
if "'''" in ascii:
|
||||
print(f"TODO: Cannot escape ascii because both \"\"\" and ''' exist: {ascii}")
|
||||
|
||||
script = f"""# This file is automatically generated. Please do not modify.
|
||||
|
||||
from . import AsciiArt
|
||||
|
||||
{varname} = AsciiArt(match=r'''{d.match}''', color='{d.color}', ascii=r\"""
|
||||
{varname} = AsciiArt(match=r'''{d.match}''', color='{d.color}', ascii=r{quotes}
|
||||
{ascii}
|
||||
\""")
|
||||
{quotes})
|
||||
"""
|
||||
write(Path(__file__).parent.parent / f'hyfetch/distros/{varname}.py', script)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue