Compare commits
3 Commits
dbafafcba5
...
ccebe90ea8
Author | SHA1 | Date | |
---|---|---|---|
|
ccebe90ea8 | ||
|
bf10c51e61 | ||
|
28ddd3e44f |
@ -7,7 +7,6 @@ class DrawerNode:
|
|||||||
|
|
||||||
|
|
||||||
class PropertyDrawerNode(DrawerNode):
|
class PropertyDrawerNode(DrawerNode):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Properties: {}>".format(len(self.children))
|
return "<Properties: {}>".format(len(self.children))
|
||||||
|
|
||||||
@ -38,6 +37,9 @@ class ListGroupNode:
|
|||||||
def append(self, child):
|
def append(self, child):
|
||||||
self.children.append(child)
|
self.children.append(child)
|
||||||
|
|
||||||
|
def get_raw(self):
|
||||||
|
return '\n'.join([c.get_raw() for c in self.children])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<List: {}>".format(len(self.children))
|
return "<List: {}>".format(len(self.children))
|
||||||
|
|
||||||
@ -64,6 +66,9 @@ class Text:
|
|||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
|
def get_raw(self):
|
||||||
|
return ''.join(self.content.get_raw())
|
||||||
|
|
||||||
|
|
||||||
class ListItem:
|
class ListItem:
|
||||||
def __init__(self, tag, content, orig=None):
|
def __init__(self, tag, content, orig=None):
|
||||||
@ -71,6 +76,9 @@ class ListItem:
|
|||||||
self.content = content
|
self.content = content
|
||||||
self.orig = orig
|
self.orig = orig
|
||||||
|
|
||||||
|
def get_raw(self):
|
||||||
|
return get_raw_contents(self.orig)
|
||||||
|
|
||||||
|
|
||||||
class BlockNode:
|
class BlockNode:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -92,3 +100,5 @@ class CodeBlock(BlockNode):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Code: {}>".format(len(self.lines))
|
return "<Code: {}>".format(len(self.lines))
|
||||||
|
|
||||||
|
from .utils import get_raw_contents
|
||||||
|
@ -376,18 +376,32 @@ class Headline:
|
|||||||
current_node.append(dom.PropertyNode(line.key, line.value))
|
current_node.append(dom.PropertyNode(line.key, line.value))
|
||||||
|
|
||||||
elif isinstance(line, Text):
|
elif isinstance(line, Text):
|
||||||
if isinstance(current_node, dom.BlockNode):
|
tree_up = list(indentation_tree)
|
||||||
current_node.append(dom.Text(line))
|
while len(tree_up) > 0:
|
||||||
elif isinstance(current_node, dom.DrawerNode):
|
node = tree_up[-1]
|
||||||
current_node.append(dom.Text(line))
|
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)
|
||||||
else:
|
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
|
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)))
|
||||||
|
indentation_tree = tree_up
|
||||||
|
|
||||||
elif isinstance(line, ListItem):
|
elif isinstance(line, ListItem):
|
||||||
if (current_node is None
|
if (current_node is None
|
||||||
@ -395,9 +409,12 @@ class Headline:
|
|||||||
or isinstance(current_node, dom.BlockNode)
|
or isinstance(current_node, dom.BlockNode)
|
||||||
or isinstance(current_node, dom.DrawerNode)
|
or isinstance(current_node, dom.DrawerNode)
|
||||||
):
|
):
|
||||||
|
was_node = current_node
|
||||||
current_node = dom.ListGroupNode()
|
current_node = dom.ListGroupNode()
|
||||||
if current_node is None:
|
if was_node is None:
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
|
else:
|
||||||
|
was_node.append(current_node)
|
||||||
indentation_tree.append(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):
|
||||||
@ -431,7 +448,7 @@ class Headline:
|
|||||||
)
|
)
|
||||||
> len(line.indentation)
|
> len(line.indentation)
|
||||||
):
|
):
|
||||||
rem = indentation_tree.pop()
|
rem = indentation_tree.pop(-1)
|
||||||
if len(indentation_tree) == 0:
|
if len(indentation_tree) == 0:
|
||||||
indentation_tree.append(rem)
|
indentation_tree.append(rem)
|
||||||
current_node = rem
|
current_node = rem
|
||||||
@ -512,8 +529,6 @@ class Headline:
|
|||||||
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
|
||||||
elif content.strip().upper() == ":RESULTS:":
|
elif content.strip().upper() == ":RESULTS:":
|
||||||
assert current_node is None
|
assert current_node is None
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, Strike, Text,
|
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, ListItem, Strike, Text,
|
||||||
Underlined, Verbatim)
|
Underlined, Verbatim)
|
||||||
|
|
||||||
|
from .org_rw import dump_contents
|
||||||
|
|
||||||
|
|
||||||
def get_hl_raw_contents(doc: Headline) -> str:
|
def get_hl_raw_contents(doc: Headline) -> str:
|
||||||
lines = []
|
lines = []
|
||||||
@ -36,6 +38,8 @@ def get_raw_contents(doc) -> str:
|
|||||||
return "".join([get_raw_contents(chunk) for chunk in doc])
|
return "".join([get_raw_contents(chunk) for chunk in doc])
|
||||||
if isinstance(doc, (Text, Bold, Code, Italic, Strike, Underlined, Verbatim)):
|
if isinstance(doc, (Text, Bold, Code, Italic, Strike, Underlined, Verbatim)):
|
||||||
return doc.get_raw()
|
return doc.get_raw()
|
||||||
|
if isinstance(doc, ListItem):
|
||||||
|
return dump_contents(doc)[1]
|
||||||
print("Unhandled type: " + str(doc))
|
print("Unhandled type: " + str(doc))
|
||||||
raise NotImplementedError("Unhandled type: " + str(doc))
|
raise NotImplementedError("Unhandled type: " + str(doc))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user