diff --git a/meta/generate_tag_defs.py b/meta/generate_tag_defs.py index 32ba837..c1f5d0b 100644 --- a/meta/generate_tag_defs.py +++ b/meta/generate_tag_defs.py @@ -43,7 +43,7 @@ def generate_tag_class(output: TextIO, tag: TagInfo): prop_unions_gen = [] for prop in tag.properties: # Yucky hard-coded spaces, I can't be bothered to fix this - prop_args_gen.append(f" {prop.name}: Any = None,") + prop_args_gen.append(f" {prop.name}: Any = {prop.default!r},") prop_unions_gen.append(f" '{prop.name}': {prop.name},") prop_args = '\n'.join(prop_args_gen).strip() diff --git a/meta/scrape_tags.py b/meta/scrape_tags.py index ff09490..78d828e 100644 --- a/meta/scrape_tags.py +++ b/meta/scrape_tags.py @@ -98,11 +98,23 @@ def domXrefReplace(lookup: str, presentation: Optional[str] = None) -> str: """Type definition for info grabbed from MDN docs""" +class PropYmlItem(TypedDict): + """ + Properties of a tag, defined in tags.yml + """ + + doc: str + """Documentation for the property""" + + default: NotRequired[str] + """Default value of the property""" + + class TagsYmlItem(TypedDict): """ A tag which has suggested keys """ - properties: NotRequired[dict[str, str]] + properties: NotRequired[dict[str, str | PropYmlItem]] """Mapping of properties used by the tag (name: description)""" base: NotRequired[str] @@ -127,9 +139,14 @@ class Prop: Name of the property """ - description: Optional[str] + doc: Optional[str] """ - Description of the property if applicable + Documentation of the property if applicable + """ + + default: Optional[str] + """ + Default value for the property """ @@ -347,8 +364,14 @@ def prop_entries_to_object( return [] props = [] - for name, description in tag_data['properties'].items(): - props.append(Prop(name, description)) + for name, value in tag_data['properties'].items(): + if isinstance(value, str): + doc: Optional[str] = value + default: Optional[str] = None + else: + doc = value.get("doc") + default = value.get("default") + props.append(Prop(name, doc, default)) return props diff --git a/meta/tags.yml b/meta/tags.yml index 529f5a7..ca9bf2a 100644 --- a/meta/tags.yml +++ b/meta/tags.yml @@ -23,6 +23,12 @@ a: href: URL of page to link to target: Use "_blank" to open in a new tab +script: + properties: + type: + doc: Type of script to use + default: text/javascript + p: base: StylableTag diff --git a/pyhtml/__tags/generated.py b/pyhtml/__tags/generated.py index 8f09ef6..32e15e1 100644 --- a/pyhtml/__tags/generated.py +++ b/pyhtml/__tags/generated.py @@ -3340,7 +3340,7 @@ class script(Tag): def __init__( self, *children: Any, - + type: Any = 'text/javascript', **properties: Any, ) -> None: """ @@ -3349,14 +3349,14 @@ def __init__( [View full documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) """ properties |= { - + 'type': type, } super().__init__(*children, **properties) def __call__( self, *children: Any, - + type: Any = 'text/javascript', **properties: Any, ): """ @@ -3365,7 +3365,7 @@ def __call__( [View full documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) """ properties |= { - + 'type': type, } return super().__call__(*children, **properties) diff --git a/tests/basic_rendering_test.py b/tests/basic_rendering_test.py index daebd04..0a21613 100644 --- a/tests/basic_rendering_test.py +++ b/tests/basic_rendering_test.py @@ -103,7 +103,8 @@ def test_larger_page(): ' ', ' Hello, world!', ' ', - ' ', + ' ', ' ', ' ', '

',