Bugzilla – Attachment 193909 Details for
Bug 159366
List styles add paragraph direct formatting on loading Writer document
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
python script to remove list-style-name from automatic styles
remove-direct-liststylename.py (text/x-python), 3.45 KB, created by
Michael Stahl (allotropia)
on 2024-04-30 16:35:21 UTC
(
hide
)
Description:
python script to remove list-style-name from automatic styles
Filename:
MIME Type:
Creator:
Michael Stahl (allotropia)
Created:
2024-04-30 16:35:21 UTC
Size:
3.45 KB
patch
obsolete
> >import re >import sys >import xml.etree.ElementTree as ET >import zipfile > ># Remove text:list-style-name attribute on automatic paragraph style, if its ># parent style already has it. ># Such attribute may or may not be wrongly inserted by LO 7.6.[0-6]/24.2.[0-2] >def replace(filename, targetname): > changed = False > zip = zipfile.ZipFile(filename) > contentfile = zip.open("content.xml") > stylesfile = zip.open("styles.xml") > contentxml = ET.parse(contentfile) > stylesxml = ET.parse(stylesfile) > autos = contentxml.getroot().find("{urn:oasis:names:tc:opendocument:xmlns:office:1.0}automatic-styles") > candidates = {} > for style in autos.findall("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}style"): > family = style.get("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}family") > if family and family == "paragraph": > liststylename = style.get("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}list-style-name") > if liststylename: > props = style.find("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}paragraph-properties") > if props is None or props.get("{urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0}margin-left") is None: > parent = style.get("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}parent-style-name") > if parent in candidates: > d = candidates[parent] > if liststylename in d: > d[liststylename].append(style) > else: > d[liststylename] = [style] > else: > candidates[parent] = { liststylename: [style] } > styles = stylesxml.getroot().find("{urn:oasis:names:tc:opendocument:xmlns:office:1.0}styles") > for style in styles.findall("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}style"): > # TODO recursive search ? > family = style.get("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}family") > if family and family == "paragraph": > name = style.get("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}name") > if name in candidates: > liststylename = style.get("{urn:oasis:names:tc:opendocument:xmlns:style:1.0}list-style-name") > if liststylename in candidates[name]: > for autostyle in candidates[name][liststylename]: > del autostyle.attrib["{urn:oasis:names:tc:opendocument:xmlns:style:1.0}list-style-name"] > changed = True > print(filename + ": '" + name + "' '" + liststylename + "'") > if changed: > # shutil.copy2(filename, targetname) > # there is no "remove" in zipfile :( > with zipfile.ZipFile(targetname, mode="w") as targetzip: > for info in zip.infolist(): > if info.filename == "content.xml": > with targetzip.open("content.xml", mode="w") as targetcontent: > contentxml.write(targetcontent, encoding="UTF-8", xml_declaration=True) > else: > targetzip.writestr(info, zip.read(info)) > print("wrote: " + targetname) > else: > print("no list-style-name to be replaced in: " + filename) > >if __name__ == "__main__": > if len(sys.argv) != 3 or sys.argv[1] == sys.argv[2]: > print("usage: " + sys.argv[0] + " inputfile outputfile") > sys.exit(1) > else: > replace(sys.argv[1], sys.argv[2]) >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 159366
:
192153
| 193909