protect_start_spaces

This commit is contained in:
Edward Betts 2017-02-22 21:52:59 +00:00
parent 9927e6bd86
commit 264e4f6b30

View file

@ -1,5 +1,6 @@
import humanize import humanize
from datetime import date, timedelta from datetime import date, timedelta
from jinja2 import Markup
def display_datetime(dt): def display_datetime(dt):
if dt is None: if dt is None:
@ -10,4 +11,16 @@ def display_datetime(dt):
else: else:
return dt.strftime('%a, %d %b %Y') return dt.strftime('%a, %d %b %Y')
def nbsp_at_start(line):
''' Protect spaces at the start of a string. '''
space_count = 0
for c in line:
if c != ' ':
break
space_count += 1
# return Markup(' ') * space_count + line[space_count:]
return '\u00A0' * space_count + line[space_count:]
def protect_start_spaces(text):
return '\n'.join(nbsp_at_start(line) for line in text.splitlines())