diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_about.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_about.jinja2 index a3609729..36f8fd67 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_about.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_about.jinja2 @@ -2,7 +2,7 @@ diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 963783dd..ced52d07 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -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("<(?Pa.*?)>(?P.*?)") + 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}".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 diff --git a/src/octoprint/templates/dialogs/about/authors.jinja2 b/src/octoprint/templates/dialogs/about/authors.jinja2 index 42a59fe9..93e02640 100644 --- a/src/octoprint/templates/dialogs/about/authors.jinja2 +++ b/src/octoprint/templates/dialogs/about/authors.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 %} diff --git a/src/octoprint/templates/dialogs/about/changelog.jinja2 b/src/octoprint/templates/dialogs/about/changelog.jinja2 index 60c34b3a..672f2cba 100644 --- a/src/octoprint/templates/dialogs/about/changelog.jinja2 +++ b/src/octoprint/templates/dialogs/about/changelog.jinja2 @@ -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 %} diff --git a/src/octoprint/templates/dialogs/about/license.jinja2 b/src/octoprint/templates/dialogs/about/license.jinja2 index 38848981..5ef3980c 100644 --- a/src/octoprint/templates/dialogs/about/license.jinja2 +++ b/src/octoprint/templates/dialogs/about/license.jinja2 @@ -1 +1 @@ -{% include "_data/agpl.html" %} +{% filter externalize_links %}{% include "_data/agpl.html" %}{% endfilter %} diff --git a/src/octoprint/templates/dialogs/about/supporters.jinja2 b/src/octoprint/templates/dialogs/about/supporters.jinja2 index 3e6df586..d8bb5b3f 100644 --- a/src/octoprint/templates/dialogs/about/supporters.jinja2 +++ b/src/octoprint/templates/dialogs/about/supporters.jinja2 @@ -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 %} diff --git a/src/octoprint/templates/dialogs/about/thirdparty.jinja2 b/src/octoprint/templates/dialogs/about/thirdparty.jinja2 index ab4e48e4..1ea4b492 100644 --- a/src/octoprint/templates/dialogs/about/thirdparty.jinja2 +++ b/src/octoprint/templates/dialogs/about/thirdparty.jinja2 @@ -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 %}