Skip to content

Instantly share code, notes, and snippets.

@myint
Last active August 6, 2016 13:51
Show Gist options
  • Save myint/2f72ab1c7cf166990b5f571a0efb742a to your computer and use it in GitHub Desktop.
Save myint/2f72ab1c7cf166990b5f571a0efb742a to your computer and use it in GitHub Desktop.
Outputs XML content of PowerPoint slides for use by "git diff"
#!/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