1616import yaml
1717from typing_extensions import NotRequired
1818
19+ from pyhtml .__render_options import RenderOptions
20+
1921TAGS_YAML = "meta/tags.yml"
2022"""File location to load custom tag data from"""
2123
@@ -118,6 +120,15 @@ class AttrYmlItem(TypedDict):
118120 """Python type to accept for the attribute"""
119121
120122
123+ class RenderOptionsYmlItem (TypedDict ):
124+ """
125+ Render options as a dictionary
126+ """
127+
128+ indent : NotRequired [str ]
129+ spacing : NotRequired [str ]
130+
131+
121132class TagsYmlItem (TypedDict ):
122133 """
123134 A tag which has suggested keys
@@ -143,6 +154,11 @@ class TagsYmlItem(TypedDict):
143154 Pre-content for the element (eg `<!DOCTYPE html>`)
144155 """
145156
157+ render_options : NotRequired [RenderOptionsYmlItem ]
158+ """
159+ Render options for this element
160+ """
161+
146162
147163TagsYaml = dict [str , TagsYmlItem ]
148164"""Type alias for type of tags.yml file"""
@@ -216,6 +232,11 @@ class TagInfo:
216232 Pre-content for the element (eg `<!DOCTYPE html>`)
217233 """
218234
235+ render_options : Optional [RenderOptions ]
236+ """
237+ Render options
238+ """
239+
219240
220241def fetch_mdn ():
221242 """
@@ -468,6 +489,21 @@ def get_tag_pre_content(tags: TagsYaml, tag_name: str) -> Optional[str]:
468489 return tag .get ("pre_content" , None )
469490
470491
492+ def get_tag_render_options (
493+ tags : TagsYaml , tag_name : str
494+ ) -> Optional [RenderOptions ]:
495+ """
496+ Return pre-content for the tag
497+ """
498+ if tag_name not in tags :
499+ return None
500+ tag = tags [tag_name ]
501+ if "render_options" in tag :
502+ return RenderOptions (** tag ["render_options" ])
503+ else :
504+ return None
505+
506+
471507def make_mdn_link (tag : str ) -> str :
472508 """Generate an MDN docs link for the given tag"""
473509 return f"{ MDN_ELEMENT_PAGE } /{ tag } "
@@ -496,6 +532,7 @@ def elements_to_element_structs(
496532 escape_children = get_tag_escape_children (tag_attrs , name ),
497533 attributes = attr_entries_to_object (tag_attrs , name ),
498534 pre_content = get_tag_pre_content (tag_attrs , name ),
535+ render_options = get_tag_render_options (tag_attrs , name ),
499536 )
500537 )
501538
0 commit comments