Last active
June 19, 2024 09:25
-
-
Save myint/2f72ab1c7cf166990b5f571a0efb742a to your computer and use it in GitHub Desktop.
Outputs XML content of PowerPoint slides for use by "git diff"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Outputs XML content of PowerPoint slides. | |
See the following for how to make "git diff" work with PowerPoint files. | |
In "~/.gitconfig", append: | |
[diff "pptx"] | |
textconv = pptx-to-text | |
In the repository's ".gitattributes", append: | |
*.pptx diff=pptx | |
""" | |
import argparse | |
import re | |
import sys | |
import xml.dom.minidom | |
import zipfile | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('filename') | |
args = parser.parse_args() | |
with zipfile.ZipFile(args.filename, 'r') as input_file: | |
for name in sorted(input_file.namelist()): | |
if re.match('ppt/.*/.*\.xml$', name): | |
raw_xml_content = input_file.read(name) | |
xml_content = xml.dom.minidom.parseString( | |
raw_xml_content).toprettyxml(indent=' ') | |
print(xml_content, end='') | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment