From 20b2da9cd09c36da35e470656ad9eea661f66c7a Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 5 Apr 2021 11:05:42 +0200 Subject: [PATCH] Add line numbers on code samples --- articles/static/code.css | 23 +++++++++++++++++++++++ articles/templates/articles/base.html | 1 + articles/utils.py | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 articles/static/code.css diff --git a/articles/static/code.css b/articles/static/code.css new file mode 100644 index 0000000..fb1b8b2 --- /dev/null +++ b/articles/static/code.css @@ -0,0 +1,23 @@ +.codehilitetable td { + border: none; + margin: 0; + padding: 0; +} + +.codehilitetable .linenos { + max-width: 20px; +} + +.codehilitetable .linenos pre { + border-right: none; + border-top-right-radius: 0; + border-bottom-right-radius: 0; + padding-right: 0; +} + +.codehilitetable .code pre { + border-left: none; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + padding-left: .1rem; +} diff --git a/articles/templates/articles/base.html b/articles/templates/articles/base.html index e5f43dd..35f214e 100644 --- a/articles/templates/articles/base.html +++ b/articles/templates/articles/base.html @@ -19,6 +19,7 @@ {% if article and article.has_code %} + {% endif %} {% if user.is_authenticated %} diff --git a/articles/utils.py b/articles/utils.py index 4ee6af4..5bfc339 100644 --- a/articles/utils.py +++ b/articles/utils.py @@ -20,7 +20,7 @@ def format_article_content(content): extensions=[ "extra", "admonition", - CodeHiliteExtension(linenums=False, guess_lang=False), + CodeHiliteExtension(linenums=True, guess_lang=False), LazyLoadingImageExtension(), ] )