Compare commits
No commits in common. "440f0bd4b79b02b9b3706df13d79f7dd4d3b52e2" and "5e4a9f8ff2df3deac85b6fd4d08cadf4be6361e3" have entirely different histories.
440f0bd4b7
...
5e4a9f8ff2
@ -1,23 +1,32 @@
|
|||||||
class DrawerNode:
|
class PropertyDrawerNode:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
def append(self, child):
|
def append(self, child):
|
||||||
self.children.append(child)
|
self.children.append(child)
|
||||||
|
|
||||||
|
|
||||||
class PropertyDrawerNode(DrawerNode):
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Properties: {}>".format(len(self.children))
|
return "<Properties: {}>".format(len(self.children))
|
||||||
|
|
||||||
|
|
||||||
class LogbookDrawerNode(DrawerNode):
|
class LogbookDrawerNode:
|
||||||
|
def __init__(self):
|
||||||
|
self.children = []
|
||||||
|
|
||||||
|
def append(self, child):
|
||||||
|
self.children.append(child)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<LogBook: {}>".format(len(self.children))
|
return "<LogBook: {}>".format(len(self.children))
|
||||||
|
|
||||||
|
|
||||||
class ResultsDrawerNode(DrawerNode):
|
class ResultsDrawerNode:
|
||||||
|
def __init__(self):
|
||||||
|
self.children = []
|
||||||
|
|
||||||
|
def append(self, child):
|
||||||
|
self.children.append(child)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Results: {}>".format(len(self.children))
|
return "<Results: {}>".format(len(self.children))
|
||||||
|
|
||||||
@ -73,16 +82,12 @@ class ListItem:
|
|||||||
|
|
||||||
|
|
||||||
class BlockNode:
|
class BlockNode:
|
||||||
def __init__(self):
|
|
||||||
self.children = []
|
|
||||||
|
|
||||||
def append(self, child):
|
def append(self, child):
|
||||||
self.children.append(child)
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class CodeBlock(BlockNode):
|
class CodeBlock(BlockNode):
|
||||||
def __init__(self, header, subtype):
|
def __init__(self, header, subtype):
|
||||||
super().__init__()
|
|
||||||
self.header = header
|
self.header = header
|
||||||
self.lines = None
|
self.lines = None
|
||||||
self.subtype = subtype
|
self.subtype = subtype
|
||||||
|
@ -378,7 +378,7 @@ class Headline:
|
|||||||
elif isinstance(line, Text):
|
elif isinstance(line, Text):
|
||||||
if isinstance(current_node, dom.BlockNode):
|
if isinstance(current_node, dom.BlockNode):
|
||||||
current_node.append(dom.Text(line))
|
current_node.append(dom.Text(line))
|
||||||
elif isinstance(current_node, dom.DrawerNode):
|
elif isinstance(current_node, dom.LogbookDrawerNode):
|
||||||
current_node.append(dom.Text(line))
|
current_node.append(dom.Text(line))
|
||||||
else:
|
else:
|
||||||
if isinstance(current_node, dom.TableNode):
|
if isinstance(current_node, dom.TableNode):
|
||||||
@ -390,18 +390,13 @@ class Headline:
|
|||||||
tree.append(dom.Text(text_to_dom(line.contents, line)))
|
tree.append(dom.Text(text_to_dom(line.contents, line)))
|
||||||
|
|
||||||
elif isinstance(line, ListItem):
|
elif isinstance(line, ListItem):
|
||||||
if (current_node is None
|
if current_node is None or isinstance(current_node, dom.TableNode):
|
||||||
or isinstance(current_node, dom.TableNode)
|
|
||||||
or isinstance(current_node, dom.BlockNode)
|
|
||||||
or isinstance(current_node, dom.DrawerNode)
|
|
||||||
):
|
|
||||||
current_node = dom.ListGroupNode()
|
current_node = dom.ListGroupNode()
|
||||||
if current_node is None:
|
tree.append(current_node)
|
||||||
tree.append(current_node)
|
indentation_tree = [current_node]
|
||||||
indentation_tree.append(current_node)
|
|
||||||
if not isinstance(current_node, dom.ListGroupNode):
|
if not isinstance(current_node, dom.ListGroupNode):
|
||||||
if not isinstance(current_node, dom.ListGroupNode):
|
if not isinstance(current_node, dom.ListGroupNode):
|
||||||
raise Exception("Expected a {}, found: {} on line {} on {}".format(dom.ListGroupNode, current_node, line.linenum, self.doc.path))
|
logging.warning("Expected a {}, found: {} on line {} on {}".format(dom.ListGroupNode, current_node, line.linenum, self.doc.path))
|
||||||
# This can happen. Frequently inside a LogDrawer
|
# This can happen. Frequently inside a LogDrawer
|
||||||
|
|
||||||
if len(indentation_tree) > 0 and (
|
if len(indentation_tree) > 0 and (
|
||||||
@ -446,7 +441,6 @@ class Headline:
|
|||||||
if current_node is None:
|
if current_node is None:
|
||||||
current_node = dom.TableNode()
|
current_node = dom.TableNode()
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
# TODO: Allow indentation of this element inside others
|
|
||||||
indentation_tree = [current_node]
|
indentation_tree = [current_node]
|
||||||
if not isinstance(current_node, dom.TableNode):
|
if not isinstance(current_node, dom.TableNode):
|
||||||
if not isinstance(current_node, dom.TableNode):
|
if not isinstance(current_node, dom.TableNode):
|
||||||
@ -488,39 +482,36 @@ class Headline:
|
|||||||
assert current_node is None
|
assert current_node is None
|
||||||
current_node = dom.PropertyDrawerNode()
|
current_node = dom.PropertyDrawerNode()
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
# TODO: Check if this can be nested
|
|
||||||
indentation_tree = [current_node]
|
|
||||||
elif content.strip().upper() == ":LOGBOOK:":
|
elif content.strip().upper() == ":LOGBOOK:":
|
||||||
assert current_node is None
|
assert current_node is None
|
||||||
current_node = dom.LogbookDrawerNode()
|
current_node = dom.LogbookDrawerNode()
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
# TODO: Check if this can be nested
|
|
||||||
indentation_tree = [current_node]
|
|
||||||
elif content.strip().upper() == ":END:":
|
elif content.strip().upper() == ":END:":
|
||||||
if current_node is None and len(indentation_tree) == 0:
|
if current_node is None:
|
||||||
logging.error('Finished node (:END:) with no known starter')
|
logging.warning('Finished node (:END:) with no known starter')
|
||||||
else:
|
else:
|
||||||
tree_up = list(indentation_tree)
|
tree_up = list(tree)
|
||||||
while len(tree_up) > 0:
|
while len(tree_up) > 0:
|
||||||
node = tree_up[-1]
|
node = tree_up[-1]
|
||||||
if isinstance(node, dom.DrawerNode):
|
if (isinstance(
|
||||||
indentation_tree = tree_up
|
node, dom.PropertyDrawerNode
|
||||||
|
) or isinstance(
|
||||||
|
node, dom.LogbookDrawerNode
|
||||||
|
) or isinstance(
|
||||||
|
node, dom.ResultsDrawerNode
|
||||||
|
)):
|
||||||
|
tree = tree_up
|
||||||
current_node = node
|
current_node = node
|
||||||
tree_up.pop(-1)
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
tree_up.pop(-1)
|
tree_up.pop(-1)
|
||||||
else:
|
else:
|
||||||
raise Exception('Unexpected node ({}) on headline (id={}), line {}'.format(current_node, self.id, linenum))
|
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
|
current_node = None
|
||||||
|
tree.pop()
|
||||||
elif content.strip().upper() == ":RESULTS:":
|
elif content.strip().upper() == ":RESULTS:":
|
||||||
assert current_node is None
|
assert current_node is None
|
||||||
current_node = dom.ResultsDrawerNode()
|
current_node = dom.ResultsDrawerNode()
|
||||||
|
|
||||||
# TODO: Allow indentation of these blocks inside others
|
|
||||||
indentation_tree = [current_node]
|
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown structural line: {}".format(line))
|
raise Exception("Unknown structural line: {}".format(line))
|
||||||
|
Loading…
Reference in New Issue
Block a user