add: pictures menu in photo markdown

This commit is contained in:
2025-07-08 22:08:24 +02:00
parent e1f08f0312
commit 001a8c692e
2 changed files with 26 additions and 10 deletions

View File

@ -35,11 +35,6 @@ converters: list[str, dict[str, str]] = {
"to_prefix": "<strong>",
"to_suffix": "</strong>",
},
"list": {
"from_prefix": "- ",
"from_suffix": "\n",
"code": "bozodown:list",
},
"code": {
"from_prefix": "```",
"from_suffix": "```",

View File

@ -15,17 +15,38 @@ class Photodown(Bozodown):
self._specific_case_namespaces.update({"photohub": self._photohub_render})
image_converter = self._converters.get("image")
image_converter.update({"code": "photohub:image"})
self._converters.update({"pictures": {"from_prefix": "+++++","from_suffix": "+++++","code": "photohub:pictures",}})
self._bulk: list[Picture] = []
def add_bulk(self, bulk: list[Picture]):
self._bulk = bulk.copy()
def _render_image(self, url: str) -> str:
if (url.startswith("./")):
for picture in self._bulk:
if url == "." + picture.get_large().get_url()[:-4]:
return f"""<a href={picture.get_page().html.get_url()}><img src='{picture.get_small().get_url()}'></a>"""
return f"<img src='{url}'>"
def _render_pictures(self, config: dict[str, str | int], to_parse: str):
segments: list[str] = to_parse.split("--")
content: str = ""
for segment in segments:
content += f"<div class='pictures-item'>{self.render(segment)}</div>"
return f"<div class='pictures-menu'>{content}</div>"
def _photohub_render(self, id: str, text: str) -> str:
if (id == "image"):
picture_url = f"{text[2:-1]}"
if (picture_url.startswith("./")):
for picture in self._bulk:
if picture_url == "." + picture.get_large().get_url()[:-4]:
return f"""<a href={picture.get_page().html.get_url()}><img src='{picture.get_small().get_url()}'></a>"""
return f"<img src='{picture_url}'>"
return self._render_image(picture_url)
if (id == "pictures"):
config, style, to_parse = text[5:-5].split("---")
style = style.replace("\n", "")
config = {
k: v for line in config.strip().splitlines()
if ": " in line
for k, v in [line.split(": ", 1)]
}
content: str = self._render_pictures(config, to_parse)
return f"<div style='{style}'>{content}</div>"