Skip to content

Instantly share code, notes, and snippets.

@aanari
Created May 8, 2012 02:13
Show Gist options
  • Save aanari/2632027 to your computer and use it in GitHub Desktop.
Save aanari/2632027 to your computer and use it in GitHub Desktop.
Recover InDesign File
#!/usr/bin/python
#-*-coding:utf-8-*-
import re, string, os
inddtags = re.compile('@\S+')
xmltags = re.compile("""<(?:([a-zA-Z\?][\w:\-]*)(\s(?:\s*[a-zA-Z][\w:\-]*(?:\s*=(?:\s*"(?:\\"|[^"])*"|\s*'(?:\\'|[^'])*'|[^\s>]+))?)*)?(\s*[\/\?]?)|\/([a-zA-Z][\w:\-]*)\s*|!--((?:[^\-]|-(?!->))*)--|!\[CDATA\[((?:[^\]]|\](?!\]>))*)\]\])>""")
cleanup = re.compile('[^a-zA-Z0-9\n ]+')
smash = re.compile('(\S+){16}')
inputfile = open('1.indd', 'rb')
output1 = open('1.txt', 'wb')
for line in inputfile:
output1.write(xmltags.sub('', inddtags.sub('', line)))
inputfile.close()
output1.close()
output1 = open('1.txt', 'rb')
output2 = open('2.txt', 'wb')
for line in output1:
output2.write(cleanup.sub('', line))
output1.close()
output2.close()
output2 = open('2.txt', 'rb')
output3 = open('3.txt', 'wb')
for line in output2:
output3.write(smash.sub('', line))
output2.close()
output3.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment