This commit is contained in:
pika 2025-03-30 20:10:26 +02:00
parent 097b3dbf09
commit 539d6a6416
6 changed files with 61 additions and 10 deletions

View file

@ -1,8 +1,16 @@
import ipaddress
import markdown as md_package
from flask import Blueprint
bp = Blueprint('filters', __name__)
@bp.app_template_filter('markdown')
def markdown_filter(text):
"""Convert markdown text to HTML"""
if text:
return md_package.markdown(text, extensions=['tables', 'fenced_code'])
return ""
@bp.app_template_filter('ip_network')
def ip_network_filter(cidr):
"""Convert a CIDR string to an IP network object"""
@ -19,14 +27,6 @@ def ip_address_filter(ip):
except ValueError:
return None
@bp.app_template_filter('markdown')
def markdown_filter(text):
"""Convert markdown text to HTML"""
import markdown
if text:
return markdown.markdown(text, extensions=['tables', 'fenced_code'])
return ""
@bp.app_template_global('get_ip_network')
def get_ip_network(cidr):
"""Global function to get an IP network object from CIDR"""