fix(datasheet): broken images, replace scanchain info with mux

- fix some of the broken images
- render the mux's info doc in place of the scanchain doc
This commit is contained in:
Uri Shaked
2023-07-30 23:09:31 +03:00
parent 7842384b6a
commit 1aa125fdd5
8 changed files with 44 additions and 221 deletions
+18
View File
@@ -1,3 +1,4 @@
import os
import mistune
from mistune.renderers.markdown import MarkdownRenderer
@@ -15,3 +16,20 @@ class HeadingsRenderer(MarkdownRenderer):
def limit_markdown_headings(source: str, min_level: int) -> str:
markdown = mistune.create_markdown(renderer=HeadingsRenderer(min_level))
return markdown(source)
class ImagePathRewriterRenderer(MarkdownRenderer):
def __init__(self, prefix: str):
super().__init__()
self.prefix = prefix
def image(self, token, state):
url = token["attrs"]["url"]
if not "://" in url and not url.startswith("/"):
token["attrs"]["url"] = os.path.join(self.prefix, url)
return super().image(token, state)
def rewrite_image_paths(source: str, prefix: str) -> str:
markdown = mistune.create_markdown(renderer=ImagePathRewriterRenderer(prefix))
return markdown(source)