Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump flask from 2.3.3 to 3.0.0 #774

Merged
merged 9 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/linters/.python-lint
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=flask,
flask_talisman,
flaskext.markdown,
google.auth.exceptions,
google.cloud,
jinja2,
jinja2.ext,
markdown,
matplotlib,
matplotlib.pyplot,
mistune,
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Flask==2.3.3
Flask-Markdown==0.3
Flask==3.0.0
flask-talisman==1.1.0
google-cloud-storage==2.13.0
gunicorn==21.2.0
markdown==3.5
pytest==7.4.3
pytest-watch==4.2.0
pytest-cov==4.1.0
Expand Down
9 changes: 7 additions & 2 deletions server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
url_for as flask_url_for,
)
from werkzeug.http import HTTP_STATUS_CODES
from flaskext.markdown import Markdown
from flask_talisman import Talisman
from urllib.parse import urlparse, urlunparse
from .markdown import Markdown, markdown


from .csp import csp
Expand Down Expand Up @@ -57,7 +57,12 @@ def get_send_file_max_age(self, name):
__name__, template_folder=TEMPLATES_DIR, static_folder=STATIC_DIR
)

Markdown(app)
# register jinja2 extensions and filters

app.jinja_options = app.jinja_options.copy()
app.jinja_env.add_extension(Markdown)
app.jinja_env.filters["markdown"] = markdown

talisman = Talisman(
app,
content_security_policy=csp,
Expand Down
57 changes: 57 additions & 0 deletions server/markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Based on https://gist.github.com/mikefromit/5a6fdfecc9310712f15a872df9f41f03

from jinja2 import pass_environment, nodes
from jinja2.ext import Extension
import markdown as md


@pass_environment
def markdown(env, value):
"""
Markdown filter with support for extensions.
"""
output = value
# insert custom markdown extensions here
extensions = [
"markdown.extensions.meta",
"markdown.extensions.attr_list",
"markdown.extensions.toc",
"markdown.extensions.def_list",
]

d = dict()
d["extensions"] = list()
d["extensions"].extend(extensions)

marked = md.Markdown(**d)

return marked.convert(output)


class Markdown(Extension):
"""
A wrapper around the markdown filter for syntactic sugar.
"""

tags = set(["markdown"])

def parse(self, parser): # pragma: no cover
"""
Parses the statements and defers to the callback
for markdown processing.
"""
lineno = next(parser.stream).lineno
body = parser.parse_statements(["name:endmarkdown"], drop_needle=True)

return nodes.CallBlock(
self.call_method("_render_markdown"), [], [], body
).set_lineno(lineno)

def _render_markdown(self, caller=None): # pragma: no cover
"""
Calls the markdown filter to transform the output.
"""
if not caller:
return ""
output = caller().strip()
return markdown(self.environment, output)
2 changes: 1 addition & 1 deletion templates/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1>

<div class="container">
<div id="answers" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
{{ faq.FAQ | markdown }}
{{ faq.FAQ | markdown | safe }}
</div>
</div>
</section>
Expand Down
4 changes: 2 additions & 2 deletions templates/report/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1>
{% block reportName %}{{ report.name }}{% endblock %}
</h1>

{{ report.summary | markdown }}
{{ report.summary | markdown | safe }}

<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
Expand Down Expand Up @@ -177,7 +177,7 @@ <h2 class="metric-header">
</button>
</h2>
{% if metric.description %}
{{ metric.description | markdown }}
{{ metric.description | markdown | safe }}
{% endif %}
{% for report_id, report_name in metric.similar_reports.items() %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion templates/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2>
</a>
</h2>

{{ report.summary | markdown }}
{{ report.summary | markdown | safe }}

<a href="{{ url }}" class="btn">View the {{ report.name }}{% if not report.name.endswith('Report') %} Report{% endif %}</a>

Expand Down