2019-12-10 18:19:01 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Jinja2 template filters.
|
|
|
|
"""
|
|
|
|
import re
|
|
|
|
|
2019-12-11 19:47:19 -05:00
|
|
|
from markupsafe import Markup, escape
|
2019-12-10 18:19:01 -05:00
|
|
|
|
2019-12-11 19:47:19 -05:00
|
|
|
def quotelink(line, post_links):
|
2019-12-10 18:19:01 -05:00
|
|
|
"""Checks if the quotelink is valid and adds an anchor tag if so."""
|
|
|
|
links = re.findall(r'>>(\d+)', line)
|
|
|
|
for link in links:
|
2019-12-11 19:47:19 -05:00
|
|
|
if int(link) in post_links:
|
2019-12-10 18:19:01 -05:00
|
|
|
span = f'<a class="quotelink" href="#{link}">>>{link}</a>'
|
|
|
|
else:
|
|
|
|
span = f'<span class="deadlink">>>{link}</span>'
|
|
|
|
line = line.replace('>>' + link, span)
|
|
|
|
return Markup(line)
|