MCPcopy Index your code
hub / github.com/nodejs/node / PrettyPrintNode

Function PrettyPrintNode

tools/gyp/tools/pretty_vcproj.py:63–94  ·  view source on GitHub ↗
(node, indent=0)

Source from the content-addressed store, hash-verified

61
62
63def PrettyPrintNode(node, indent=0):
64 if node.nodeType == Node.TEXT_NODE:
65 if node.data.strip():
66 print("{}{}".format(" " * indent, node.data.strip()))
67 return
68
69 if node.childNodes:
70 node.normalize()
71 # Get the number of attributes
72 attr_count = 0
73 if node.attributes:
74 attr_count = node.attributes.length
75
76 # Print the main tag
77 if attr_count == 0:
78 print("{}<{}>".format(" " * indent, node.nodeName))
79 else:
80 print("{}<{}".format(" " * indent, node.nodeName))
81
82 all_attributes = []
83 for name, value in node.attributes.items():
84 all_attributes.append((name, value))
85 all_attributes.sort(CmpTuple())
86 for name, value in all_attributes:
87 print('{} {}="{}"'.format(" " * indent, name, value))
88 print("%s>" % (" " * indent))
89 if node.nodeValue:
90 print("{} {}".format(" " * indent, node.nodeValue))
91
92 for sub_node in node.childNodes:
93 PrettyPrintNode(sub_node, indent=indent + 2)
94 print("{}</{}>".format(" " * indent, node.nodeName))
95
96
97def FlattenFilter(node):

Callers 1

mainFunction · 0.85

Calls 6

CmpTupleClass · 0.85
sortMethod · 0.80
formatMethod · 0.65
printFunction · 0.50
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected