def _get_para_node_props(para): """ return para node props ({num, indent, text, heading (if exists), prefix (if exists)}) if a paragraph node. Return empty props, if not a para node. """ props = {} if matchers.section_node(para): num_match = para['runs'][0]['text_re'] props['num'] = num_match.group('num') props['indent'] = len(num_match.group('spaces')) props['num2'] = None try: props['num2'] = num_match.group('num2') return props except: pass try: heading_match = para['runs'][1]['text_re'] except(IndexError, KeyError): skip = 1 else: skip = 2 props['heading'] = heading_match.group('heading') props['text'] = _para_text_content(para, skip) return props
def _get_para_node_props(para): """ return para node props ({num, indent, text, heading (if exists), prefix (if exists)}) if a paragraph node. Return empty props, if not a para node. """ props = {} if matchers.section_node(para): num_match = para['runs'][0]['text_re'] props['num'] = num_match.group('num') props['indent'] = len(num_match.group('spaces')) props['num2'] = None try: props['num2'] = num_match.group('num2') return props except: pass # gotta check if heading is the last node in the run. because lexis. if para.get('runs', [{}])[-1].get('properties', {}).get('i'): heading_para = para['runs'].pop() para['runs'].insert(1, heading_para) matchers.section_node(para) try: heading_match = para['runs'][1]['text_re'] except(IndexError, KeyError): skip = 1 else: skip = 2 props['heading'] = heading_match.group('heading') props['text'] = _para_text_content(para, skip) props['richtext'] = _para_rich_text_content(para, skip) return props