Added externalize_links filter for jinja2
Links from documents (like changelog, licenses etc) should also be target blank & rel noopener/noreferrer
This commit is contained in:
parent
7a8e6b6b6d
commit
7c6b9eac48
7 changed files with 21 additions and 6 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<ul>
|
||||
{% for plugin in plugin_pluginmanager_thirdparty %}
|
||||
<li><a href="{{ plugin.url }}">{{ plugin.name }}</a>: {% if plugin.license %}{{ plugin.license }}{% else %}-{% endif %}</li>
|
||||
<li>{% if plugin.url %}<a href="{{ plugin.url }}" target="_blank" rel="noreferrer noopener">{% endif %}{{ plugin.name }}{% if plugin.url %}</a>{% endif %}: {% if plugin.license %}{{ plugin.license }}{% else %}-{% endif %}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -703,9 +703,24 @@ class Server(object):
|
|||
return "{hashs} {content}".format(hashs="#" * number, content=match.group("content"))
|
||||
return markdown_header_regex.sub(repl, s)
|
||||
|
||||
html_link_regex = re.compile("<(?P<tag>a.*?)>(?P<content>.*?)</a>")
|
||||
def externalize_links(text):
|
||||
def repl(match):
|
||||
tag = match.group("tag")
|
||||
if not u"href" in tag:
|
||||
return match.group(0)
|
||||
|
||||
if not u"target=" in tag and not u"rel=" in tag:
|
||||
tag += u" target=\"_blank\" rel=\"noreferrer noopener\""
|
||||
|
||||
content = match.group("content")
|
||||
return u"<{tag}>{content}</a>".format(tag=tag, content=content)
|
||||
return html_link_regex.sub(repl, text)
|
||||
|
||||
app.jinja_env.filters["regex_replace"] = regex_replace
|
||||
app.jinja_env.filters["offset_html_headers"] = offset_html_headers
|
||||
app.jinja_env.filters["offset_markdown_headers"] = offset_markdown_headers
|
||||
app.jinja_env.filters["externalize_links"] = externalize_links
|
||||
|
||||
# configure additional template folders for jinja2
|
||||
import jinja2
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/AUTHORS.md" ignore missing %}{% endfilter %}{% endfilter %}
|
||||
{% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/AUTHORS.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/CHANGELOG.md" ignore missing %}{% endfilter %}{% endfilter %}
|
||||
{% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/CHANGELOG.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{% include "_data/agpl.html" %}
|
||||
{% filter externalize_links %}{% include "_data/agpl.html" %}{% endfilter %}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/SUPPORTERS.md" ignore missing %}{% endfilter %}{% endfilter %}
|
||||
{% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/SUPPORTERS.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/THIRDPARTYLICENSES.md" ignore missing %}{% endfilter %}{% endfilter %}
|
||||
{% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/THIRDPARTYLICENSES.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue