Add code listing CSS hack article

This commit is contained in:
jaseg 2025-07-26 16:03:33 +02:00
parent 338de75fb4
commit f5d03ed1cf
3 changed files with 286 additions and 57 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3
# https://gist.github.com/mastbaum/2655700
# Based on https://gist.github.com/mastbaum/2655700 for the basic plugin scaffolding
import sys
import re
@ -17,6 +17,9 @@ class UnfuckedHTMLTranslator(HTMLTranslator):
self.in_literal_block = False
def visit_literal_block(self, node):
# Insert an empty "lineno" span before each line. We insert the line numbers using pure CSS in a ::before
# pseudo-element. This has the added advantage that the line numbers don't get included in text selection.
# These line number spans are also used to show line continuation markers when a line is wrapped.
self.in_literal_block = True
self.body.append(self.starttag(node, 'pre', CLASS='literal-block'))
self.body.append('<span class="lineno"></span><span class="line">')