Compare commits
5 Commits
24dc516d64
...
3b90723250
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3b90723250 | ||
![]() |
506a17dc5c | ||
![]() |
0bdb29a278 | ||
![]() |
8b4e12ea2e | ||
![]() |
dbac8b2d6e |
@ -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,18 @@ 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:
|
||||
if "get_raw" in dir(line):
|
||||
yield "".join(line.get_raw())
|
||||
else:
|
||||
yield line.line
|
||||
|
||||
def get_contents(self, format):
|
||||
if format == "raw":
|
||||
|
@ -9,6 +9,7 @@ from .org_rw import (
|
||||
ListItem,
|
||||
RawLine,
|
||||
Strike,
|
||||
TableRow,
|
||||
Text,
|
||||
Underlined,
|
||||
Verbatim,
|
||||
@ -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