Example #1
0
	def _parse_section_nodes(para):
		nonlocal next_parser, level, in_child, para_node
		props = _get_para_node_props(para)
		if props:
			if level is None:
				level = props['indent']
			if not matchers.isint(level) or props['indent'] > level:
				success = next_parser(para)
				in_child = in_child or success
				return success
			elif props['indent'] < level:
				# if not handled by a parent parser,
				# but still less than our indent level, then
				# don't know how to handle
				raise Exception('unknown indent for', para['index'], para)
			elif props['indent'] == level:
				para_node = _aaa(dom, 'para', **props)
				next_parser = parse_section_nodes(para_node, NextParser)
				if props['num2']:
					in_child = True
					_merge(para, {'runs': [{'text': lambda t: parens_re.sub('  ', t, 1)}]})
					para['text'] = _para_text_content(para)
					para['richtext'] = _para_rich_text_content(para)
					return next_parser(para)

				in_child = False
				return True

		elif matchers.section_heading(para):
			match = para['text_re']
			if level is None:
				level = match.group('prefix')

			if level == match.group('prefix'):
				heading_node = _aaa(dom, 'para', **match.groupdict())
				next_parser = parse_section_nodes(heading_node, NextParser)
				in_child = True
				return True
			else:
				success = next_parser(para)
				in_child = in_child or success
				return success
		elif not matchers.empty(para):
			if in_child and next_parser(para):
				return True
			elif not matchers.centered(para):
				# lookahead to determine if text belongs to node or its parent
				next_level = _get_next_level(para)
				if para_node is not None and next_level and (not matchers.isint(level) or next_level >= level):
					_make_text(para_node, para['richtext'], para=para['index'])
				else:
					_make_text(dom, para['richtext'], para=para['index'], after=True)
				return True
			else:
				return False
		else:
			return False
	def __init__(self, paras, para=None):
		self._paras = paras
		if not paras:
			return None
		if para is None:
			para = paras[0]
		if isint(para):
			para = paras[paras[0]['index'] + para]
		super().__init__(para)
 def __init__(self, paras, para=None):
     self._paras = paras
     if not paras:
         return None
     if para is None:
         para = paras[0]
     if isint(para):
         para = paras[paras[0]['index'] + para]
     super().__init__(para)