37
|
37
|
|
# TODO this should be renamed. It's only a way to pretty print dates
|
38
|
38
|
|
'title': lambda date: dateutil.parser.parse(date).strftime('%b %-d, %Y - %H:%M%z%Z'),
|
39
|
39
|
|
# Convert markdown to plain text
|
40
|
|
- |
'md2txt': lambda text: bleach.clean (markdown.markdown (text),
|
41
|
|
- |
tags=[], attributes={}, styles=[], strip=True),
|
|
40
|
+ |
'md2txt': lambda text: bleach.clean (markdown.markdown(text),
|
|
41
|
+ |
tags=[], attributes={}, strip=True),
|
42
|
42
|
|
# Convert markdown to html
|
43
|
43
|
|
'md2html': lambda text: bleach.clean (bleach.linkify (markdown.markdown (
|
44
|
44
|
|
text,
|
66
|
66
|
|
# "bleach" library is used to sanitize the HTML output of jinja2's "md2html"
|
67
|
67
|
|
# filter. The library has only a very restrictive list of white-listed
|
68
|
68
|
|
# tags, so we add some more here.
|
69
|
|
- |
bleach.sanitizer.ALLOWED_TAGS += [ 'br', 'img', 'p', 'pre', 'h1', 'h2', 'h3', 'hr' ]
|
|
69
|
+ |
# The list() casting is required because it's of type "frozenlist"
|
|
70
|
+ |
bleach.sanitizer.ALLOWED_TAGS = list(bleach.sanitizer.ALLOWED_TAGS) + [ 'br', 'img', 'p', 'pre', 'h1', 'h2', 'h3', 'hr' ]
|
70
|
71
|
|
bleach.sanitizer.ALLOWED_ATTRIBUTES.update ({
|
71
|
72
|
|
'img': [ 'src' ]
|
72
|
73
|
|
})
|