Added word wrapping to email view
This commit is contained in:
parent
749e9ce7ac
commit
7af20c15e9
3 changed files with 34 additions and 3 deletions
|
|
@ -27,7 +27,7 @@
|
||||||
<dt>Date:
|
<dt>Date:
|
||||||
<dd>{{ mail.date.strftime('%Y-%m-%d @ %H:%M') }}
|
<dd>{{ mail.date.strftime('%Y-%m-%d @ %H:%M') }}
|
||||||
</dl>
|
</dl>
|
||||||
<pre>{{ mail.rendered_text }}</pre>
|
<pre>{{ mail.rendered_text() }}</pre>
|
||||||
{% if mail.children %}
|
{% if mail.children %}
|
||||||
<div class=children>{{ loop(mail.children) }}</div>
|
<div class=children>{{ loop(mail.children) }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import creoleparser
|
import creoleparser
|
||||||
from genshi import builder
|
from genshi import builder
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
@ -13,6 +14,8 @@ from flask_website.database import User
|
||||||
|
|
||||||
pygments_formatter = HtmlFormatter(style=FlaskyStyle)
|
pygments_formatter = HtmlFormatter(style=FlaskyStyle)
|
||||||
|
|
||||||
|
_ws_split_re = re.compile(r'(\s+)')
|
||||||
|
|
||||||
|
|
||||||
class CodeBlock(PreBlock):
|
class CodeBlock(PreBlock):
|
||||||
|
|
||||||
|
|
@ -46,6 +49,34 @@ def format_creole(text):
|
||||||
return Markup(_parser.render(text, encoding=None))
|
return Markup(_parser.render(text, encoding=None))
|
||||||
|
|
||||||
|
|
||||||
|
def split_lines_wrapping(text, width=74, threshold=82):
|
||||||
|
lines = text.splitlines()
|
||||||
|
if all(len(line) <= threshold for line in lines):
|
||||||
|
return lines
|
||||||
|
result = []
|
||||||
|
for line in lines:
|
||||||
|
if len(line) <= threshold:
|
||||||
|
result.append(line)
|
||||||
|
continue
|
||||||
|
line_width = 0
|
||||||
|
line_buffer = []
|
||||||
|
for piece in _ws_split_re.split(line):
|
||||||
|
line_width += len(piece)
|
||||||
|
if line_width > width:
|
||||||
|
result.append(u''.join(line_buffer))
|
||||||
|
line_buffer = []
|
||||||
|
if not piece.isspace():
|
||||||
|
line_buffer.append(piece)
|
||||||
|
line_width = len(piece)
|
||||||
|
else:
|
||||||
|
line_width = 0
|
||||||
|
else:
|
||||||
|
line_buffer.append(piece)
|
||||||
|
if line_buffer:
|
||||||
|
result.append(u''.join(line_buffer))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def requires_login(f):
|
def requires_login(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated_function(*args, **kwargs):
|
def decorated_function(*args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from hashlib import md5
|
||||||
from werkzeug import parse_date
|
from werkzeug import parse_date
|
||||||
from jinja2.utils import urlize
|
from jinja2.utils import urlize
|
||||||
from flask import Module, render_template, json, url_for, abort, Markup
|
from flask import Module, render_template, json, url_for, abort, Markup
|
||||||
|
from flask_website.utils import split_lines_wrapping
|
||||||
from flask_website import config
|
from flask_website import config
|
||||||
|
|
||||||
mailinglist = Module(__name__, url_prefix='/mailinglist')
|
mailinglist = Module(__name__, url_prefix='/mailinglist')
|
||||||
|
|
@ -19,11 +20,10 @@ class Mail(object):
|
||||||
self.children = [Mail(x) for x in d['children']]
|
self.children = [Mail(x) for x in d['children']]
|
||||||
self.text = d['text']
|
self.text = d['text']
|
||||||
|
|
||||||
@property
|
|
||||||
def rendered_text(self):
|
def rendered_text(self):
|
||||||
result = []
|
result = []
|
||||||
in_sig = False
|
in_sig = False
|
||||||
for line in self.text.splitlines():
|
for line in split_lines_wrapping(self.text):
|
||||||
if line == u'-- ':
|
if line == u'-- ':
|
||||||
in_sig = True
|
in_sig = True
|
||||||
if in_sig:
|
if in_sig:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue