#!/usr/bin/env python

import sys,json
import re

def do_ideas(node):
	for key, value in iter(sorted(node.get('ideas', dict()).iteritems())):
		trim_label(value)
	return

def trim_label(node):
	do_ideas(node)

	if node.get('title', None) == 'AND':
		return

	if node.get('title', None) == '...':
		return

	if not node.get('title', '').find('(*)') == -1:
		return

	title = node.get('title', '')
	title = re.sub(r'^\d+\..*?\s', '', title)
	title = re.sub(r'\(\d+\..*?\)', '(*)', title)
	node.update({'title': title})
	return

if len(sys.argv) < 1:
	fd_in=sys.stdin
else:
	fd_in=open(sys.argv[1], 'r')

data = json.load(fd_in)

if len(sys.argv) < 1:
	fd_out = sys.stdout
else:
	fd_in.close()
	fd_out=open(sys.argv[1],'w')


if 'id' in data and data['id'] == 'root':
	#version 2 mindmup
	do_ideas(data['ideas']['1'])
else:
	do_ideas(data)

str = json.dumps(data, indent=2, sort_keys=True)
str = re.sub(r'\s+$', '', str, 0, re.M)
str = re.sub(r'\s+$', '', str, flags=re.M)

fd_out.write(str)

if len(sys.argv) >= 1:
	fd_out.close()


@@ -164,16 +164,680 @@
 return%0A%0A
+def get_raw_description(node):%0A%09#prefer the mindmup 2.0 'note' to the 1.0 'attachment'%0A%09description = node.get('attr', dict()).get('note', dict()).get('text', '')%0A%09if description is '':%0A%09%09description = node.get('attr', dict()).get('attachment', dict()).get('content', '')%0A%0A%09return description%0A%0Adef set_raw_description(node, new_description):%0A%09#prefer the mindmup 2.0 'note' to the 1.0 'attachment'%0A%09description = node.get('attr', dict()).get('note', dict()).get('text', '')%0A%09if not description is '':%0A%09%09node.get('attr').get('note').update(%7B'text': new_description%7D)%0A%09else:%0A%09%09node.get('attr', dict()).get('attachment', dict()).update(%7B'content': new_description%7D)%0A%0A
 def trim
@@ -1143,16 +1143,174 @@
  title)%0A
+%0A%09description = get_raw_description(node)%0A%09description = re.sub(r'%5C*(.*?) %5C(%5Cd+%5C.%5Cd+%5C)%5C*', r'*%5C1 (*)*', description)%0A%09set_raw_description(node, description)%0A%0A
 %09node.up

remove the in-text references in the remove-numbered-ids too