Compare commits

..

2 Commits

Author SHA1 Message Date
Sergio Martínez Portela
dbafafcba5 Indent list-group inside current node if part of a block. 2022-11-03 23:35:56 +01:00
Sergio Martínez Portela
3be4475ddf Support get_raw_contents of list groups. 2022-11-03 23:01:21 +01:00
2 changed files with 12 additions and 28 deletions

View File

@ -376,32 +376,18 @@ class Headline:
current_node.append(dom.PropertyNode(line.key, line.value))
elif isinstance(line, Text):
tree_up = list(indentation_tree)
while len(tree_up) > 0:
node = tree_up[-1]
if (isinstance(node, dom.BlockNode)
or isinstance(node, dom.DrawerNode)
):
node.append(dom.Text(line))
current_node = node
contents = []
break
elif ((not isinstance(node, dom.TableNode)) and
(type(node) not in NON_FINISHED_GROUPS)
):
raise NotImplementedError('Not implemented node type: {} (headline_id={}, line={}, doc={})'.format(
node,
self.id,
line.linenum,
self.doc.path,
))
else:
tree_up.pop(-1)
if isinstance(current_node, dom.BlockNode):
current_node.append(dom.Text(line))
elif isinstance(current_node, dom.DrawerNode):
current_node.append(dom.Text(line))
else:
if isinstance(current_node, dom.TableNode):
pass # No problem here
elif type(current_node) not in NON_FINISHED_GROUPS:
raise NotImplementedError('Not implemented node type: {}'.format(current_node))
current_node = None
contents = []
tree.append(dom.Text(text_to_dom(line.contents, line)))
indentation_tree = tree_up
elif isinstance(line, ListItem):
if (current_node is None
@ -448,7 +434,7 @@ class Headline:
)
> len(line.indentation)
):
rem = indentation_tree.pop(-1)
rem = indentation_tree.pop()
if len(indentation_tree) == 0:
indentation_tree.append(rem)
current_node = rem
@ -529,6 +515,8 @@ class Headline:
tree_up.pop(-1)
else:
raise Exception('Unexpected node ({}) on headline (id={}), line {}'.format(current_node, self.id, linenum))
if self.id == 'd07fcf27-d6fc-41e3-a9d0-b2e2902aec23':
print("Found node:", current_node)
current_node = None
elif content.strip().upper() == ":RESULTS:":
assert current_node is None

View File

@ -1,10 +1,8 @@
import uuid
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, ListItem, Strike, Text,
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, Strike, Text,
Underlined, Verbatim)
from .org_rw import dump_contents
def get_hl_raw_contents(doc: Headline) -> str:
lines = []
@ -38,8 +36,6 @@ def get_raw_contents(doc) -> str:
return "".join([get_raw_contents(chunk) for chunk in doc])
if isinstance(doc, (Text, Bold, Code, Italic, Strike, Underlined, Verbatim)):
return doc.get_raw()
if isinstance(doc, ListItem):
return dump_contents(doc)[1]
print("Unhandled type: " + str(doc))
raise NotImplementedError("Unhandled type: " + str(doc))