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
fromcuddleimportDocument, Node, NodeList, dumps, loadsloaded_doc=loads('''// Nodes can be separated into multiple linestitle \ "Some title"// Nested nodes are fully supportedcontents { section "First section" { paragraph "This is the first paragraph" paragraph "This is the second paragraph" }}// Files must be utf8 encoded!smile "😁"// Instead of anonymous nodes, nodes and properties can be wrapped// in "" for arbitrary node names."!@#$@$%Q#$%~@!40" "1.2.3" "!!!!!"=true// The following is a legal bare identifier:foo123~!@#$%^&*.:'|/?+ "weeee"// And you can also use unicode!ノード お名前="☜(゚ヮ゚☜)"// kdl specifically allows properties and values to be// interspersed with each other, much like CLI commands.foo bar=true "baz" quux=false 1 2 3''')
print(dumps(loaded_doc))
print()
# Creating documents from scratch is a bit verbosenodes= []
child_node=Node("complex name here!", None)
nodes.append(
Node("simple-name", None, arguments=[123], children=[child_node])
)
nodes.append(
Node("second-node", None, properties={"key": "value"})
)
node_list=NodeList(nodes)
doc=Document(node_list)
print(dumps(doc))