Commit 660ca0df authored by Laurent Peuch's avatar Laurent Peuch
Browse files

feat(deprecated-warnings): highlight source code

parent 6fec7c1f4c4a
......@@ -8,6 +8,30 @@ import zipfile
from collections import defaultdict
from rdflib import ConjunctiveGraph
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters.html import HtmlFormatter
def highlight_code(file_content, lineno):
file_content = file_content.split("\n")[:lineno + 4]
# si on est à la ligne 3
# d'un fichier de 4 lignes
if len(file_content) > lineno:
hl_lines = [5]
file_content = file_content[lineno - 5:]
linenostart = lineno - 4
else:
hl_lines = [lineno]
linenostart = 1
file_content = "\n".join(file_content)
return highlight(file_content, get_lexer_by_name("python", stripnl=False),
HtmlFormatter(wrapcode=True, linenos=True,
linenostart=linenostart, hl_lines=hl_lines))
def download_heptapod_trig():
gl = gitlab.Gitlab('https://forge.extranet.logilab.fr', oauth_token=os.environ["GITLAB_TOKEN"])
......@@ -108,5 +132,9 @@ for key, value in all_artifacts.items():
result = sorted(result.items(), key=lambda x: -x[1]["count"])
rendered_template = jinja2.Template(open("template/deprecated-warnings.html", "r").read()).render(warnings=result, files_to_url=files_to_url_cache)
rendered_template = jinja2.Template(open("template/deprecated-warnings.html",
"r").read()).render(warnings=result,
files_to_url=files_to_url_cache,
highlight_code=highlight_code,
pygment_css=HtmlFormatter().get_style_defs())
open("public/deprecated-warnings.html", "w").write(rendered_template)
......@@ -3,6 +3,9 @@
<head>
<title>Collected deprecated warnings</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style>
{{ pygment_css }}
</style>
</head>
<body>
<h1>Collected deprecated warnings</h1>
......@@ -23,9 +26,7 @@
{% endif %}
{% if file_content %}
<pre>
{{ "\n".join(file_content.split("\n")[lineno - 5:lineno + 4]) }}
</pre>
{{ highlight_code(file_content, lineno) }}
{% endif %}
{% endfor %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment