diff options
author | jaseg <git@jaseg.de> | 2025-07-26 16:16:09 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2025-07-26 16:16:09 +0200 |
commit | ccd6338503549e61b74b51c2904617edbfd604cc (patch) | |
tree | 2f7f721ef1920b37a86126e0ad13cbbc1c01f84c /hack/rst2html | |
parent | 02abb0154935c7525f17429a420bb43a261ea3bb (diff) | |
parent | df627459f2520e11b16ebd54e3a6ec95133599ad (diff) | |
download | blog-ccd6338503549e61b74b51c2904617edbfd604cc.tar.gz blog-ccd6338503549e61b74b51c2904617edbfd604cc.tar.bz2 blog-ccd6338503549e61b74b51c2904617edbfd604cc.zip |
deploy.py auto-commit
Diffstat (limited to 'hack/rst2html')
-rwxr-xr-x | hack/rst2html | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/hack/rst2html b/hack/rst2html deleted file mode 100755 index f9c9146..0000000 --- a/hack/rst2html +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python3 -# Based on https://gist.github.com/mastbaum/2655700 for the basic plugin scaffolding - -import sys -import re - -import docutils.core -from docutils.transforms import Transform -from docutils.nodes import TextElement, Inline, Text -from docutils.parsers.rst import Directive, directives -from docutils.writers.html4css1 import Writer, HTMLTranslator - - -class UnfuckedHTMLTranslator(HTMLTranslator): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - 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">') - - def depart_literal_block(self, node): - self.in_literal_block = False - self.body.append('\n</span></pre>\n') - - def visit_Text(self, node): - if self.in_literal_block: - for match in re.finditer('([^\n]*)(\n|$)', node.astext()): - text, end = match.groups() - - if text: - super().visit_Text(Text(text)) - - if end == '\n': - if isinstance(node.parent, Inline): - self.depart_inline(node.parent) - self.body.append(f'</span>\n<span class="lineno"></span><span class="line">') - if isinstance(node.parent, Inline): - self.visit_inline(node.parent) - - else: - super().visit_Text(node) - - -html_writer = Writer() -html_writer.translator_class = UnfuckedHTMLTranslator -docutils.core.publish_cmdline(writer=html_writer) - |