Add interlink support

This commit is contained in:
Tim Van Baak 2021-02-21 19:21:03 -08:00
parent 6cddcbbc1b
commit f663291067
2 changed files with 11 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import json
import logging import logging
import os import os
import random import random
import re
import string import string
from flask import ( from flask import (
@ -44,6 +45,14 @@ def inject_edit():
return {'edit': current_app.config['edit']} return {'edit': current_app.config['edit']}
@app.template_filter('interlink')
def interlink_filter(value):
return re.sub(
r'\[\[([^|]+)\|([^|]+)\]\]',
lambda match: f'<a href="{match[2]}">{match[1]}</a>',
value)
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def root(): def root():
return redirect(url_for('index')) return redirect(url_for('index'))

View File

@ -63,10 +63,11 @@ window.onload = function () {
</div> </div>
{% endmacro %} {% endmacro %}
{# TODO: tag.interlink #}
{% macro make_tag_value(tag) -%} {% macro make_tag_value(tag) -%}
{%- if tag.options.hyperlink -%} {%- if tag.options.hyperlink -%}
<a href="{{ tag.value }}">{{ tag.value }}</a> <a href="{{ tag.value }}">{{ tag.value }}</a>
{%- elif tag.options.interlink -%}
{{ tag.value|interlink }}
{%- else -%} {%- else -%}
{{ tag.value }} {{ tag.value }}
{%- endif -%} {%- endif -%}