|
1 | 1 | import os |
2 | 2 | import pathlib |
| 3 | +import re |
3 | 4 | import urllib |
4 | 5 |
|
| 6 | +from docutils import nodes |
5 | 7 | import sphinx.application |
6 | 8 | import sphinx.util.logging |
| 9 | +from sphinx.transforms.post_transforms import SphinxPostTransform |
7 | 10 |
|
8 | 11 |
|
9 | 12 | DOMAIN = "packaging.python.org" |
|
12 | 15 | logger = sphinx.util.logging.getLogger(__name__) |
13 | 16 |
|
14 | 17 |
|
| 18 | +_LATEX_EMOJI_RE = re.compile(r"[ \t]*[😊✨🌟🍰🚀🐍📦](?:[ \t]+[😊✨🌟🍰🚀🐍📦])*") |
| 19 | + |
| 20 | + |
| 21 | +class LatexEmojiTransform(SphinxPostTransform): |
| 22 | + default_priority = 500 |
| 23 | + formats = ("latex",) |
| 24 | + |
| 25 | + def run(self, **kwargs: object) -> None: |
| 26 | + for text_node in self.document.findall(nodes.Text): |
| 27 | + sanitized = _LATEX_EMOJI_RE.sub("", text_node.astext()) |
| 28 | + if sanitized != text_node.astext(): |
| 29 | + text_node.parent.replace(text_node, nodes.Text(sanitized)) |
| 30 | + |
| 31 | + |
15 | 32 | def resolve_local_html_link(app: sphinx.application.Sphinx, url_path: str) -> str: |
16 | 33 | """Takes path of a link pointing an HTML render of the current project, |
17 | 34 | and returns local path of the referenced document. |
@@ -79,6 +96,7 @@ def rewrite_local_uri(app: sphinx.application.Sphinx, uri: str) -> str: |
79 | 96 |
|
80 | 97 | def setup(app: sphinx.application.Sphinx) -> dict[str, bool]: |
81 | 98 | app.connect("linkcheck-process-uri", rewrite_local_uri) |
| 99 | + app.add_post_transform(LatexEmojiTransform) |
82 | 100 |
|
83 | 101 | return { |
84 | 102 | "parallel_read_safe": True, |
|
0 commit comments