add: pictures menu in photo markdown
This commit is contained in:
@ -35,11 +35,6 @@ converters: list[str, dict[str, str]] = {
|
|||||||
"to_prefix": "<strong>",
|
"to_prefix": "<strong>",
|
||||||
"to_suffix": "</strong>",
|
"to_suffix": "</strong>",
|
||||||
},
|
},
|
||||||
"list": {
|
|
||||||
"from_prefix": "- ",
|
|
||||||
"from_suffix": "\n",
|
|
||||||
"code": "bozodown:list",
|
|
||||||
},
|
|
||||||
"code": {
|
"code": {
|
||||||
"from_prefix": "```",
|
"from_prefix": "```",
|
||||||
"from_suffix": "```",
|
"from_suffix": "```",
|
||||||
|
@ -15,17 +15,38 @@ class Photodown(Bozodown):
|
|||||||
self._specific_case_namespaces.update({"photohub": self._photohub_render})
|
self._specific_case_namespaces.update({"photohub": self._photohub_render})
|
||||||
image_converter = self._converters.get("image")
|
image_converter = self._converters.get("image")
|
||||||
image_converter.update({"code": "photohub:image"})
|
image_converter.update({"code": "photohub:image"})
|
||||||
|
self._converters.update({"pictures": {"from_prefix": "+++++","from_suffix": "+++++","code": "photohub:pictures",}})
|
||||||
self._bulk: list[Picture] = []
|
self._bulk: list[Picture] = []
|
||||||
|
|
||||||
def add_bulk(self, bulk: list[Picture]):
|
def add_bulk(self, bulk: list[Picture]):
|
||||||
self._bulk = bulk.copy()
|
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:
|
def _photohub_render(self, id: str, text: str) -> str:
|
||||||
if (id == "image"):
|
if (id == "image"):
|
||||||
picture_url = f"{text[2:-1]}"
|
picture_url = f"{text[2:-1]}"
|
||||||
if (picture_url.startswith("./")):
|
return self._render_image(picture_url)
|
||||||
for picture in self._bulk:
|
if (id == "pictures"):
|
||||||
if picture_url == "." + picture.get_large().get_url()[:-4]:
|
config, style, to_parse = text[5:-5].split("---")
|
||||||
return f"""<a href={picture.get_page().html.get_url()}><img src='{picture.get_small().get_url()}'></a>"""
|
style = style.replace("\n", "")
|
||||||
return f"<img src='{picture_url}'>"
|
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>"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user