Skip to content

Instantly share code, notes, and snippets.

@NHDaly
Forked from bycpx/config
Last active April 15, 2019 02:23
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NHDaly/7669596 to your computer and use it in GitHub Desktop.
Save NHDaly/7669596 to your computer and use it in GitHub Desktop.
Enable textual diff of iWork '09 Pages documents. (Forked and updated from a gist that works for older Pages documents)
*.pages diff=iworkpages
#!/bin/bash
# output folder for unzipping the .pages file (really long name to avoid name conflicts)
FOLDER_NAME=$1.unzipped.for.git.diff.text.comparison
# exit if a file already exists with $FOLDER_NAME so we don't delete it later.. (but this is really unlikely)
mkdir $FOLDER_NAME || { echo 'mkdir failed.. $FOLDER_NAME already exists' ; exit 1; }
# unzip the .pages file into the folder
unzip -qq -o $1 -d $FOLDER_NAME
# convert to text and print the text to stdout
xsltproc Pages.xsl $FOLDER_NAME/index.xml
# clean up our work
rm -rf $FOLDER_NAME
#run this command from your git working directory:
echo '
[diff "iworkpages"]
textconv = $GIT_DIR/../ConvertPagesToText.sh
' >> .git/config
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sf="http://developer.apple.com/namespaces/sf">
<xsl:template match="sf:p">
<xsl:apply-templates/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="sf:lnbr">
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template>
<xsl:value-of select="text()"/>
</xsl:template>
</xsl:stylesheet>
@NHDaly
Copy link
Author

NHDaly commented Nov 27, 2013

Including these files in your git repo will allow you to perform git diff on *.pages files!

Apple had changed the format of the .pages files since @bycpx wrote their Gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment