Created
December 21, 2010 01:20
-
-
Save adambyrtek/749332 to your computer and use it in GitHub Desktop.
Quick and dirty OmniOutliner to plain-text conversion
This file contains hidden or 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 | |
import xml.etree.ElementTree as ET | |
import sys | |
import re | |
class OutlinerParser: | |
def __init__(self): | |
self.indent = 0 | |
self.is_note = False | |
self.is_root = False | |
def start(self, tag, attr): | |
if re.match('^{.+}item$', tag): | |
self.indent += 1 | |
if re.match('^{.+}note$', tag): | |
self.is_note = True | |
if re.match('^{.+}root$', tag): | |
self.is_root = True | |
def end(self, tag): | |
if re.match('^{.+}item$', tag): | |
self.indent -= 1 | |
if re.match('^{.+}note$', tag): | |
self.is_note = False | |
if re.match('^{.+}root$', tag): | |
self.is_root = False | |
def data(self, data): | |
if not self.is_root: | |
return | |
print '\t' * self.indent, | |
if self.is_note: | |
print '| ', | |
print data.encode('utf-8') | |
def close(self): | |
pass | |
def main(): | |
parser = ET.XMLTreeBuilder(target=OutlinerParser()) | |
parser.feed(sys.stdin.read()) | |
parser.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment