Skip to content

Instantly share code, notes, and snippets.

@danielrichman
Created June 27, 2013 22:37
Show Gist options
  • Save danielrichman/5881025 to your computer and use it in GitHub Desktop.
Save danielrichman/5881025 to your computer and use it in GitHub Desktop.
Flask/Jinja2 filter to insert zero width spaces into a long string (in this case a session ID) so that it word wraps as soon as the screen gets thin.
@app.template_filter('sidsplit')
def sidsplit(sid, chunk_size=10):
n = len(sid) / chunk_size
chunks = [sid[i * chunk_size : (i + 1) * chunk_size] for i in range(n)]
if len(sid) % chunk_size:
chunks.append(sid[n * chunk_size:])
return Markup('<wbr>').join(chunks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment