Created
December 13, 2014 20:05
-
-
Save HeirOfNorton/3dc2795f6307145cf7cb to your computer and use it in GitHub Desktop.
Pandoc filter to convert Tracked Changes (in docx reader) to CriticMarkup
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 | |
""" | |
Pandoc filter to convert Tracked Changes in docx | |
input to CriticMarkup in the output. | |
""" | |
from pandocfilters import toJSONFilter, Str, RawInline | |
def findValue (which, items): | |
for item in items: | |
if item[0] == which: | |
return item[1] | |
return 'Unknown' | |
def makeCriticPart (kind, attr, contents): | |
if kind == 'insertion': | |
start = Str('{++') | |
end = Str('++}') | |
else: | |
start = Str('{--') | |
end = Str('--}') | |
author = findValue('author', attr) | |
date = findValue('date', attr) | |
comment = RawInline('html',"{>>author: %s, date: %s<<}" % (author, date)) | |
result = [start] | |
result.extend(contents) | |
result.append(end) | |
result.append(comment) | |
return result | |
def convertCritic (key, value, format, meta): | |
if key == 'Span': | |
classes = value[0][1] | |
if 'insertion' in classes: | |
return makeCriticPart('insertion', value[0][2], value[1]) | |
elif 'deletion' in classes: | |
return makeCriticPart('deletion', value[0][2], value[1]) | |
else: | |
return None | |
if __name__ == "__main__": | |
toJSONFilter(convertCritic) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment