Skip to content

Commit

Permalink
finished implementing html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
István Bozsó committed Feb 21, 2020
1 parent 559fbb8 commit 9eafbf1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
43 changes: 40 additions & 3 deletions utils/html/tag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from utils import export, str_t, namespace
from utils import str_t, namespace

__all__ = (
"tags", "t", "stags", "st",
)


class BaseTag(object):
__slots__ = (
Expand Down Expand Up @@ -65,17 +70,49 @@ def render(self):
"center",
"cite", "code", "colgroup", "data", "dd", "del", "details",
"dfn", "dialog",

# TODO: deprecation warning
"dir",
"div", "dl", "dt", "em", "fieldset", "figcaption", "figure",
"font", "footer", "form", "frameset", "head", "header",
"html", "i", "iframe", "ins", "kbd", "label", "legend",
"li", "main", "map", "mark", "meter", "nav", "noframes",
"noscript", "object", "ol", "optgroup", "option", "output",
"p", "picture", "pre", "progress", "q", "rp", "rt", "ruby",
"s", "samp", "script", "section", "select", "small", "span",
"strike", "strong", "style", "sub", "summary", "sup",
"svg", "table", "tbody", "td", "template", "textarea",
"tfoot", "th", "thead", "time", "title", "tr", "tt", "u",
"ul", "var", "video", "wbr",
}

tags |= {"h%d" % ii for ii in range(7)}


tags = type("Tags", (object,),
{
key: type(key, (Tag,), {})
for key in tags
}
)

t = tags

stags = {
"area", "base", "basefont", "col", "input",
"area", "base", "basefont", "col", "embed", "frame", "img",
"input", "link", "meta", "param", "source", "track",

}

stags = type("SelfClosingTags", (object,),
{
key: type(key, (Tag,), {})
for key in stags
}
)

st = stags

symbols = namespace(
linebreak = "<br>",
thematic_break = "<hr>",
)
21 changes: 14 additions & 7 deletions utils/html/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@


def main():
t = \
div(
p("a", klass="klass"),
p("b"),
div(
p("c"),
d = \
t.div(
t.p("a", klass="klass"),
t.p("b"),
t.div(
t.p("c"),
),


t.ul(
t.li("1"),
t.li("2"),
),

controls=True, src="a/b"
)

print(t.render())
print(d.render())

if __name__ == "__main__":
main()

0 comments on commit 9eafbf1

Please sign in to comment.