Compare commits
4 Commits
3b90723250
...
24dc516d64
Author | SHA1 | Date | |
---|---|---|---|
![]() |
24dc516d64 | ||
![]() |
7375a69229 | ||
![]() |
e07964af55 | ||
![]() |
df178d08d8 |
@ -24,6 +24,14 @@ class ResultsDrawerNode(DrawerNode):
|
||||
return "<Results: {}>".format(len(self.children))
|
||||
|
||||
|
||||
class GenericDrawerNode(DrawerNode):
|
||||
def __init__(self, drawer_name):
|
||||
self.drawer_name = drawer_name
|
||||
|
||||
def __repr__(self):
|
||||
return "<Drawer(): {}>".format(self.drawer_name, len(self.children))
|
||||
|
||||
|
||||
class PropertyNode:
|
||||
def __init__(self, key, value):
|
||||
self.key = key
|
||||
@ -62,12 +70,19 @@ class TableSeparatorRow:
|
||||
def __init__(self, orig=None):
|
||||
self.orig = orig
|
||||
|
||||
def get_raw(self):
|
||||
return get_raw_contents(self.orig)
|
||||
|
||||
|
||||
class TableRow:
|
||||
def __init__(self, cells, orig=None):
|
||||
self.cells = cells
|
||||
self.orig = orig
|
||||
|
||||
def get_raw(self):
|
||||
return get_raw_contents(self.orig)
|
||||
|
||||
|
||||
|
||||
class Text:
|
||||
def __init__(self, content):
|
||||
|
@ -122,6 +122,7 @@ NON_FINISHED_GROUPS = (
|
||||
dom.ListGroupNode,
|
||||
dom.ResultsDrawerNode,
|
||||
dom.PropertyDrawerNode,
|
||||
dom.GenericDrawerNode,
|
||||
)
|
||||
FREE_GROUPS = (dom.CodeBlock,)
|
||||
|
||||
@ -414,6 +415,7 @@ class Headline:
|
||||
if (
|
||||
isinstance(line, DelimiterLine)
|
||||
and line.delimiter_type == DelimiterLineType.END_BLOCK
|
||||
and line.type_data.subtype == current_node.header.type_data.subtype
|
||||
):
|
||||
|
||||
start = current_node.header.linenum
|
||||
@ -636,6 +638,13 @@ class Headline:
|
||||
assert current_node is None
|
||||
current_node = dom.ResultsDrawerNode()
|
||||
|
||||
# TODO: Allow indentation of these blocks inside others
|
||||
indentation_tree = [current_node]
|
||||
tree.append(current_node)
|
||||
elif content.strip().startswith(':') and content.strip().endswith(':'):
|
||||
assert current_node is None
|
||||
current_node = dom.GenericDrawerNode(content.strip().strip(':'))
|
||||
|
||||
# TODO: Allow indentation of these blocks inside others
|
||||
indentation_tree = [current_node]
|
||||
tree.append(current_node)
|
||||
@ -864,9 +873,24 @@ class Headline:
|
||||
yield from get_links_from_content(item.content)
|
||||
|
||||
def get_lines_between(self, start, end):
|
||||
for line in self.contents:
|
||||
# @TODO: Generalize for other line types too.
|
||||
everything = (
|
||||
[]
|
||||
# + self.keywords
|
||||
+ self.contents
|
||||
# + self.list_items
|
||||
# + self.table_rows
|
||||
# + self.properties
|
||||
# + self.structural
|
||||
+ self.delimiters
|
||||
)
|
||||
|
||||
for line in everything:
|
||||
if start <= line.linenum < end:
|
||||
yield "".join(line.get_raw())
|
||||
if 'get_raw' in dir(line):
|
||||
yield "".join(line.get_raw())
|
||||
else:
|
||||
yield line.line
|
||||
|
||||
def get_contents(self, format):
|
||||
if format == "raw":
|
||||
|
@ -7,6 +7,7 @@ from .org_rw import (
|
||||
Italic,
|
||||
Line,
|
||||
ListItem,
|
||||
TableRow,
|
||||
RawLine,
|
||||
Strike,
|
||||
Text,
|
||||
@ -50,6 +51,8 @@ def get_raw_contents(doc) -> str:
|
||||
return doc.get_raw()
|
||||
if isinstance(doc, ListItem):
|
||||
return dump_contents(doc)[1]
|
||||
if isinstance(doc, TableRow):
|
||||
return dump_contents(doc)[1]
|
||||
print("Unhandled type: " + str(doc))
|
||||
raise NotImplementedError("Unhandled type: " + str(doc))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user