Add nonprintable/invisible to obfuscate code snippets
Inserting such characters can be done as shown below. However:
- If inserted into the code before HTML-formatting it, the highlighting is broken
- If naively inserted into the HTML-formatted code, it breaks HTML
Characters have to be inserted after HTML-formatting, but only into the innermost text nodes.
invisible_chars = [
u'\u007f',
u'\u061c',
u'\u202a',
u'\u202b',
u'\u202c',
u'\u202d',
u'\u202e',
u'\u2061',
u'\u2062',
u'\u2063',
u'\u2064',
u'\u206a',
u'\u206b',
u'\u206c',
u'\u206d',
u'\u206e',
u'\u206f',
]
# Insert random invisible characters at random positions
code = u''.join(f"{x}{random.choice(invisible_chars) if random.randint(0,1) else ''}" for x in code)