Skip to content

Commit

Permalink
Close #148: Add tag() class for create custom elements
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Aug 4, 2021
1 parent 479e4ea commit ee5cd72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dominate/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,14 @@ class font(html_tag):
pass


class tag(html_tag):
def __init__(self, tagname, *args, **kwargs):
'''
Creates a new custom html tag instance.
'''
self.tagname = tagname
super(tag, self).__init__(*args, **kwargs)

# Additional markup
class comment(html_tag):
'''
Expand Down
5 changes: 5 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,8 @@ def test_xhtml():

assert span('hi', br(), 'there').render(xhtml=False) == \
'''<span>hi<br>there</span>'''


def test_custom_tag():
assert tag('custom-element', div(), 'text', attr = 1).render() == \
'''<custom-element attr="1">\n <div></div>text\n</custom-element>'''

0 comments on commit ee5cd72

Please sign in to comment.