Coding 2024-09-27
Okay, here's what's running through my head currently. Blocks and elements are to be represented with Python objects. There is some way to render these objects to HTML. I am going to assume that there is one way to render a given block/element. Therefore, because the question of what is available while rendering is so tied up in the relevant class definition, I think I'll store templates in ClassVar[str] attributes, rather than in files. Common code should go in the template files, but I don't see that it makes sense to separate Python class definitions from template code, when they're so coupled. Figuring out how to make the proper template environments available is going to be a bit of a thing, probably, but it's fine.
What goes into rendering a template for a block/element? Well, the block/element object has to say what kind of tag to use, and provide any required attributes. It also has to provide class information in the form of an appropriately-typed flag object. Finally, the tag contents. Optional template string. If None, then there is no end-tag. (HTML has void tags but not self-closing tags.) If anything else, including the empty string, then it is rendered with {"self": self} as the context and inserted between the start tag and end tag.
I think this all makes sense; I'll have to try it out later and see.
Good night.