From 7c95144d4a7daafb4d321c6cf5e6cfc3a436427f Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Tue, 6 Oct 2026 21:14:52 +0000 Subject: [PATCH] feat(compare): compare list properties and attribute-only properties TabList, AllNestedStyles and other list-typed children are compared as one canonical string. Empty property elements such as BulletChar are compared by their attributes. --- tools/compare.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/compare.py b/tools/compare.py index 9f271af..39a2c4c 100644 --- a/tools/compare.py +++ b/tools/compare.py @@ -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 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)}"