#!/usr/bin/env python3 """ Jinja2 template filters. """ import re from markupsafe import Markup, escape def quotelink(line, post_links): """Checks if the quotelink is valid and adds an anchor tag if so.""" links = re.findall(r'>>(\d+)', line) for link in links: if int(link) in post_links: span = f'>>{link}' else: span = f'>>{link}' line = line.replace('>>' + link, span) return Markup(line)