Export table on as_dom
.
This commit is contained in:
parent
c2968283f3
commit
28d8b69146
@ -50,6 +50,24 @@ class ListGroupNode:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<List: {}>".format(len(self.children))
|
return "<List: {}>".format(len(self.children))
|
||||||
|
|
||||||
|
class TableNode:
|
||||||
|
def __init__(self):
|
||||||
|
self.children = []
|
||||||
|
|
||||||
|
def append(self, child):
|
||||||
|
self.children.append(child)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<Table: {}>".format(len(self.children))
|
||||||
|
|
||||||
|
class TableSeparatorRow:
|
||||||
|
def __init__(self, orig=None):
|
||||||
|
self.orig = orig
|
||||||
|
|
||||||
|
class TableRow:
|
||||||
|
def __init__(self, cells, orig=None):
|
||||||
|
self.cells = cells
|
||||||
|
self.orig = orig
|
||||||
|
|
||||||
class Text:
|
class Text:
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
|
@ -332,6 +332,7 @@ class Headline:
|
|||||||
self.keywords
|
self.keywords
|
||||||
+ self.contents
|
+ self.contents
|
||||||
+ self.list_items
|
+ self.list_items
|
||||||
|
+ self.table_rows
|
||||||
+ self.properties
|
+ self.properties
|
||||||
+ self.structural
|
+ self.structural
|
||||||
+ self.delimiters
|
+ self.delimiters
|
||||||
@ -377,20 +378,22 @@ class Headline:
|
|||||||
elif isinstance(current_node, dom.LogbookDrawerNode):
|
elif isinstance(current_node, dom.LogbookDrawerNode):
|
||||||
current_node.append(dom.Text(line))
|
current_node.append(dom.Text(line))
|
||||||
else:
|
else:
|
||||||
if type(current_node) not in NON_FINISHED_GROUPS:
|
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))
|
raise NotImplementedError('Not implemented node type: {}'.format(current_node))
|
||||||
current_node = None
|
current_node = None
|
||||||
contents = []
|
contents = []
|
||||||
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):
|
||||||
current_node = dom.ListGroupNode()
|
current_node = dom.ListGroupNode()
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
indentation_tree = [current_node]
|
indentation_tree = [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):
|
||||||
logging.warning("Expected a {}, found: {} on line {}".format(dom.ListGroupNode, current_node, line.linenum))
|
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 (
|
||||||
@ -431,6 +434,22 @@ class Headline:
|
|||||||
node = dom.ListItem(text_to_dom(line.tag, line), text_to_dom(line.content, line), orig=line)
|
node = dom.ListItem(text_to_dom(line.tag, line), text_to_dom(line.content, line), orig=line)
|
||||||
current_node.append(node)
|
current_node.append(node)
|
||||||
|
|
||||||
|
elif isinstance(line, TableRow):
|
||||||
|
if current_node is None:
|
||||||
|
current_node = dom.TableNode()
|
||||||
|
tree.append(current_node)
|
||||||
|
indentation_tree = [current_node]
|
||||||
|
if not isinstance(current_node, dom.TableNode):
|
||||||
|
if not isinstance(current_node, dom.TableNode):
|
||||||
|
logging.warning("Expected a {}, found: {} on line {}".format(dom.TableNode, current_node, line.linenum))
|
||||||
|
# This can happen. Frequently inside a LogDrawer
|
||||||
|
|
||||||
|
if len(line.cells) > 0 and len(line.cells[0]) > 0 and line.cells[0][0] == '-':
|
||||||
|
node = dom.TableSeparatorRow(orig=line)
|
||||||
|
else:
|
||||||
|
node = dom.TableRow(line.cells, orig=line)
|
||||||
|
current_node.append(node)
|
||||||
|
|
||||||
elif (
|
elif (
|
||||||
isinstance(line, DelimiterLine)
|
isinstance(line, DelimiterLine)
|
||||||
and line.delimiter_type == DelimiterLineType.BEGIN_BLOCK
|
and line.delimiter_type == DelimiterLineType.BEGIN_BLOCK
|
||||||
|
Loading…
Reference in New Issue
Block a user