Closed jackoconnordev closed 6 months ago
This is an example of a code-block from a page on djangoproject.com which was generated by sphinx. The code starts from the left-most side of the code block.
Added a bit more elaboration on why I went with turning off the indentor vs using pre tags to the original PR description.
@jackoconnordev Thanks :+1: Welcome aboard :boat:
Merged in 69e8325f92d402f3ccb91c207d2ae2d7daaca006.
Woohoo 🥳. Thanks @felixxm
Description
This fixes code blocks on www.djangoproject.com/start page not displaying with correct Python indentation (and includes my best guess at correct PEP8 styling).
Fixes https://github.com/django/djangoproject.com/issues/1453
Fix
The DjHTML code indenter was automatically changing the indentation for the code blocks which were colorised by
{% pygment 'python' %}
. This led to incorrectly formatted Python code which would neither pass a Python interpreter's indentation checks or conform to PEP8.The DjHTML indenter can be temporarily turned off for certain lines by making use of
{# fmt:off #}
and{# fmt:on #}
. This is the method I think works best in this specific use-case. See https://github.com/rtts/djhtml#fmtoff-and-fmton.\ vs fmt:off
The DjHTML indentation can also be stopped from being applied by using
<pre>
tags. However, the<pre>
tags cause lots of extra vertical whitespace on the website so I feel just disabling the formatter is the better way to go.If pre tags are included within the pygment block then they get treated as plain text instead of markup. If pre tags wrap the pygment block then the newlines at the end of the open and close pygment lines lead to the increased vertical white space since whitespace is preserved
Screenshots
I have the current djangoproject.com/start/ page vs this PR's djangoproject/start/ page visualised side-by-side. Old on the left, new on the right.
Admin section
Forms and Authentications sections
Internationalisation section
Object Relational Mapper section
URLs and Views section