diff --git a/src/bozodown.py b/src/bozodown.py index d55d8fc..224d51e 100644 --- a/src/bozodown.py +++ b/src/bozodown.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from collections.abc import Callable from typing import Any @@ -9,6 +11,15 @@ def _bozodown_render(id: str, text: str) -> str: if (id == "list"): print("error: list not supported") return "" + if (id == "block"): + style, to_parse = text[5:-5].split("---") + style = style.replace("\n", "") + content: str = render(to_parse) + return f""" +
+{content} +
+""" _specific_case_namespaces: dict[str, Callable[[str, str], str]] = { @@ -87,6 +98,11 @@ _converters: list[dict[str, str]] = [ "from_suffix": "", "to_prefix": "
", }, + { + "from_prefix": "-----", + "from_suffix": "-----", + "code": "bozodown:block" + }, ] _default_converter: dict[str, str] = { @@ -99,10 +115,8 @@ def _render_element(text: str, converter: dict[str, str]) -> str: code: str = converter.get("code") if (code is not None): namespace, id = code.split(":") - print(namespace, id) func = _specific_case_namespaces[namespace] return func(id, text) - print(converter) start: int = len(converter["from_prefix"]) stop: int = len(text) - len(converter.get("from_suffix", "")) return f"{converter['to_prefix']}{text[start:stop]}{converter['to_suffix']}" @@ -122,7 +136,7 @@ def _get_first_converter(text: str) -> tuple[str, dict] | None: return text[:start], _default_converter suffix: int = first_converter_found.get("from_suffix", "") prefix: int = first_converter_found['from_prefix'] - stop: int = text.find(suffix, start) + stop: int = text.find(suffix, start + len(prefix)) if (stop == -1): print(f"error: '{prefix}' was never finished by a '{suffix}'") return