| 1 |
"""Does foo.svg --> foo.pdf with no change to the file.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import shutil |
| 6 |
from typing import TYPE_CHECKING |
| 7 |
|
| 8 |
from sphinx.transforms.post_transforms.images import ImageConverter |
| 9 |
|
| 10 |
if TYPE_CHECKING: |
| 11 |
import os |
| 12 |
|
| 13 |
from sphinx.application import Sphinx |
| 14 |
from sphinx.util.typing import ExtensionMetadata |
| 15 |
|
| 16 |
|
| 17 |
class MyConverter(ImageConverter): |
| 18 |
conversion_rules = [ |
| 19 |
('image/svg+xml', 'application/pdf'), |
| 20 |
] |
| 21 |
|
| 22 |
def is_available(self) -> bool: |
| 23 |
return True |
| 24 |
|
| 25 |
def convert( |
| 26 |
self, _from: str | os.PathLike[str], _to: str | os.PathLike[str] |
| 27 |
) -> bool: |
| 28 |
"""Mock converts the image from SVG to PDF.""" |
| 29 |
shutil.copyfile(_from, _to) |
| 30 |
return True |
| 31 |
|
| 32 |
|
| 33 |
def setup(app: Sphinx) -> ExtensionMetadata: |
| 34 |
app.add_post_transform(MyConverter) |
| 35 |
|
| 36 |
return { |
| 37 |
'version': 'builtin', |
| 38 |
'parallel_read_safe': True, |
| 39 |
'parallel_write_safe': True, |
| 40 |
} |