mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-29 09:34:02 +01:00
feat(compare): compare list properties and attribute-only properties
TabList, AllNestedStyles and other list-typed <Properties> children are compared as one canonical string. Empty property elements such as BulletChar are compared by their attributes.
This commit is contained in:
1 parent
6475d01841
commit
7c95144d4a
1 file changed
+14
-1
+14
-1
@@ -124,14 +124,27 @@ def norm(v):
|
||||
return " ".join(fix(t) for t in v.split(" "))
|
||||
|
||||
|
||||
def canon(el):
|
||||
"""A structured property (TabList, AllNestedStyles, ...) as one string:
|
||||
each leaf as tag=text with numbers normalised, in document order."""
|
||||
if len(el) == 0 and el.get("type") != "list":
|
||||
return f"{el.tag}={norm(el.text or '')}"
|
||||
return el.tag + "[" + ",".join(canon(c) for c in el) + "]"
|
||||
|
||||
|
||||
def props(el):
|
||||
"""Attributes plus <Properties> children (as P.Name)."""
|
||||
a = dict(el.attrib)
|
||||
p = el.find("Properties")
|
||||
if p is not None:
|
||||
for c in p:
|
||||
if len(c) == 0:
|
||||
if c.get("type") == "list":
|
||||
a["P." + c.tag] = canon(c)
|
||||
elif len(c) == 0:
|
||||
text = c.text or ""
|
||||
extra = sorted((k, v) for k, v in c.attrib.items() if k != "type")
|
||||
if extra:
|
||||
text = " ".join(f"{k}={v}" for k, v in extra)
|
||||
if c.tag == "Contents":
|
||||
n = norm(text)
|
||||
text = f"md5:{hashlib.md5(n.encode()).hexdigest()} {len(n)}"
|
||||
|
||||
Reference in new issue
Block a user