You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromluxon.html.parserimportParserfromluxon.html.tagsimport*defmain():
parsed1=Parser.parse("<header/><main/><footer/>")
# returns a Root element (because more than 1 top-level tags) parsed2=Parser.parse("<!-- Hello world! --><ul><li>Banana</li><li>Mango</li><li>Apricot</li></ul>")
# returns a Root element# Find the first Main element and # add Root element's children to itparsed1.find_by_type(Main) \
.add(*parsed2)
# Find the first Ul element# and add new list item to itfruits: Ul=parsed1.find_by_type(Ul)
fruits.add_item("Pear")
# Sort child elementsfruits.sort(key=lambdafruit: fruit.read_text())
#sorted_fruits = sorted(fruits, key=lambda t: t.read_text())# Print source codeprint(parsed1.html(pretty=True))
if__name__=="__main__":
main()
HTML source code generator
fromluxon.html.tagsimport*defmain():
doc=Html().add(
Head().add(
Title("Example site"),
# Style defined this way shows up as <link> tag in source codeStyle("/assets/styles/base.css")
),
Body().add(
Header(),
Main().add(
Img("/assets/images/catgirl.png"),
Ul("Apple", "Mango", "Lime", "Banana")
),
Footer()
)
)
print(doc.html(pretty=True))
if__name__=="__main__":
main()
fromluxon.html.tagsimport*defmain():
# Yes, you can even do this but# it doesn't mean you should...ul=Ul() \
+ (Li("Finland") \
+ (Ul() \
+Li("Helsinki") \
+Li("Tampere") \
+Li("Hämeenlinna"))) \
+ (Li("Estonia") \
+ (Ul() \
+Li("Tallinn") \
+Li("Tartu") \
+Li("Narva")))
print(ul.html(pretty=True))
if__name__=="__main__":
main()
importrandomfromluxon.html.tagsimport*classSelective(Div):
"""This is a custom element that displays randomly chosen content every time it's source code is generated"""def__init__(self):
"""Construct a Selective element"""super().__init__()
defupdate(self):
self.set_body(
"I like ",
Span(random.choice(["cats", "dogs"]))
)