diff --git a/searx/templates/oscar/help.html b/searx/templates/oscar/help.html
index bf311fb4a..06823594d 100644
--- a/searx/templates/oscar/help.html
+++ b/searx/templates/oscar/help.html
@@ -8,5 +8,6 @@
{% endfor %}
+
{{page.title}}
{{ page.content | safe }}
{% endblock %}
diff --git a/searx/templates/simple/help.html b/searx/templates/simple/help.html
index 5f571ae01..1db5989a1 100644
--- a/searx/templates/simple/help.html
+++ b/searx/templates/simple/help.html
@@ -8,5 +8,6 @@
{% endfor %}
+{{page.title}}
{{ page.content | safe }}
{% endblock %}
diff --git a/searx/user_help.py b/searx/user_help.py
index 251e14462..0be198d18 100644
--- a/searx/user_help.py
+++ b/searx/user_help.py
@@ -31,7 +31,24 @@ class Template(string.Template):
idpattern = '(:?[a-z._:]+)'
-def render(app: flask.Flask):
+def render(markdown: str, variables=Dict[str, str], filename='') -> HelpPage:
+ first_line, markdown = markdown.split('\n', maxsplit=1)
+ assert first_line.startswith('# ')
+
+ try:
+ markdown = Template(markdown).substitute(variables)
+ except KeyError as e:
+ print('[FATAL ERROR] undefined variable ${} in {}'.format(e.args[0], filename))
+ print('available variables are:')
+ for key in variables:
+ print('\t' + key)
+ sys.exit(1)
+
+ content: str = mistletoe.markdown(markdown)
+ return HelpPage(title=first_line.strip('# '), content=content)
+
+
+def initialize(app: flask.Flask):
"""
Renders the user documentation. Must be called after all Flask routes have been
registered, because the documentation might try to link to them with Flask's `url_for`.
@@ -57,21 +74,10 @@ def render(app: flask.Flask):
for pagename in _TOC:
filename = 'help/en/' + pagename + '.md'
file_content = pkg_resources.resource_string(__name__, filename).decode()
- try:
- markdown = Template(file_content).substitute(variables)
- except KeyError as e:
- print('[FATAL ERROR] undefined variable ${} in {}'.format(e.args[0], filename))
- print('available variables are:')
- for key in variables:
- print('\t' + key)
- sys.exit(1)
- assert file_content.startswith('# ')
- title = file_content.split('\n', maxsplit=1)[0].strip('# ')
- content: str = mistletoe.markdown(markdown)
if pagename == 'about':
try:
- content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode()
+ file_content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode()
except FileNotFoundError:
pass
- PAGES[pagename] = HelpPage(title=title, content=content)
+ PAGES[pagename] = render(file_content, variables, filename=filename)
diff --git a/searx/webapp.py b/searx/webapp.py
index 5e05f9781..6503da58f 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -1391,7 +1391,7 @@ werkzeug_reloader = flask_run_development or (searx_debug and __name__ == "__mai
if not werkzeug_reloader or (werkzeug_reloader and os.environ.get("WERKZEUG_RUN_MAIN") == "true"):
plugin_initialize(app)
search_initialize(enable_checker=True, check_network=True, enable_metrics=settings['general']['enable_metrics'])
- user_help.render(app)
+ user_help.initialize(app)
def run():