summaryrefslogtreecommitdiff
path: root/hack/rst2html
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-10-14 17:41:48 +0200
committerjaseg <git@jaseg.de>2023-10-14 17:41:48 +0200
commit3a636e545bc258ba3ecec3ede8b31ac113309313 (patch)
tree69752120c8d41f0d9eb954b20585f1b9bae8920f /hack/rst2html
parent5fb6e37fdc3829a63ef0fbec4f503442d57394c6 (diff)
parentb45763668be3275e6b1234eec55c99ec32ecee27 (diff)
downloadblog-3a636e545bc258ba3ecec3ede8b31ac113309313.tar.gz
blog-3a636e545bc258ba3ecec3ede8b31ac113309313.tar.bz2
blog-3a636e545bc258ba3ecec3ede8b31ac113309313.zip
deploy.py auto-commit
Diffstat (limited to 'hack/rst2html')
-rwxr-xr-xhack/rst2html50
1 files changed, 0 insertions, 50 deletions
diff --git a/hack/rst2html b/hack/rst2html
deleted file mode 100755
index e3a390d..0000000
--- a/hack/rst2html
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python3
-# https://gist.github.com/mastbaum/2655700
-
-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):
- 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)
-