git » git-arr » commit dff4ff6

css: Work around Pygments' element layout changes

author Alberto Bertogli
2022-09-26 01:43:55 UTC
committer Alberto Bertogli
2022-10-13 21:32:21 UTC
parent 6ea59bad517948bd8b5fd82f4c621811ee5c6b88

css: Work around Pygments' element layout changes

Pygments 2.12 changes the element layout slightly, adding a wrapper
<div> that was accidentally removed before:
https://github.com/pygments/pygments/issues/632.

This patch adds a workaround, so the styling is consistent on both 2.11
and 2.12.

static/git-arr.css +17 -7
views/blob.html +2 -0
views/commit.html +2 -0

diff --git a/static/git-arr.css b/static/git-arr.css
index 3c3c648..03e7c06 100644
--- a/static/git-arr.css
+++ b/static/git-arr.css
@@ -268,21 +268,31 @@ table.blob-binary tr.etc {
 
 
 /* Pygments overrides. */
+div.colorized-src {
+    font-size: larger;
+}
+
+div.colorized-src .source_code {
+    /* Ignore pygments style's background. */
+    background: var(--body-bg);
+}
+
+td.code > div.source_code {
+    /* This is a workaround, in pygments 2.11 there's a bug where the wrapper
+     * div is inside the table, so we need to override the descendant (because
+     * the style sets it on ".source_code" and the most specific value wins).
+     * Once we no longer support 2.11, we can remove this. */
+    background: var(--body-bg);
+}
+
 div.linenodiv {
     padding-right: 0.5em;
-    font-size: larger;
-    /* must match div.source_code */
 }
 
 div.linenodiv a {
     color: var(--text-lowcontrast-fg);
 }
 
-div.source_code {
-    background: inherit;
-    font-size: larger;
-}
-
 
 /* Repository information table. */
 table.repo_info tr:hover {
diff --git a/views/blob.html b/views/blob.html
index f1c6ad0..67ac11c 100644
--- a/views/blob.html
+++ b/views/blob.html
@@ -77,7 +77,9 @@
 {{!markdown_blob(blob.utf8_content)}}
 </div>
 % elif can_colorize(blob.utf8_content):
+<div class="colorized-src">
 {{!colorize_blob(fname.raw, blob.utf8_content)}}
+</div>
 % else:
 <pre class="blob-body">
 {{blob.utf8_content}}
diff --git a/views/commit.html b/views/commit.html
index e21ff04..f753377 100644
--- a/views/commit.html
+++ b/views/commit.html
@@ -56,7 +56,9 @@
 <hr/>
 
 % if can_colorize(c.diff.body):
+<div class="colorized-src">
 {{!colorize_diff(c.diff.body)}}
+</div>
 % else:
 <pre class="diff-body">
 {{c.diff.body}}