Compare commits

..

No commits in common. "790ef57598858bd8a504116e4e2a30bf9edf4ec2" and "d67bae645b111c6b5f60a111b10240490bd82568" have entirely different histories.

3 changed files with 15 additions and 105 deletions

View File

@ -457,20 +457,17 @@ class Headline:
current_node = sublist current_node = sublist
indentation_tree.append(current_node) indentation_tree.append(current_node)
while len(indentation_tree) > 0: while len(indentation_tree) > 0 and (
list_children = [ (len(indentation_tree[-1].children) > 0)
and len(
[
c c
for c in indentation_tree[-1].children for c in indentation_tree[-1].children
if isinstance(c, dom.ListItem) if isinstance(c, dom.ListItem)
] ][-1].orig.indentation
)
if ((len(list_children) > 0) > len(line.indentation)
and (len(list_children[-1].orig.indentation) ):
<= len(line.indentation))):
# No more breaking out of lists, it's indentation
# is less than ours
break
rem = indentation_tree.pop(-1) rem = indentation_tree.pop(-1)
if len(indentation_tree) == 0: if len(indentation_tree) == 0:
indentation_tree.append(rem) indentation_tree.append(rem)
@ -488,15 +485,9 @@ class Headline:
tree.append(current_node) tree.append(current_node)
# TODO: Allow indentation of this element inside others # TODO: Allow indentation of this element inside others
indentation_tree = [current_node] indentation_tree = [current_node]
elif not isinstance(current_node, dom.TableNode): if not isinstance(current_node, dom.TableNode):
if isinstance(current_node, dom.ListGroupNode): if not isinstance(current_node, dom.TableNode):
# As an item inside a list logging.warning("Expected a {}, found: {} on line {}".format(dom.TableNode, current_node, line.linenum))
list_node = current_node
current_node = dom.TableNode()
list_node.append(current_node)
indentation_tree.append(current_node)
else:
logging.debug("Expected a {}, found: {} on line {}".format(dom.TableNode, current_node, line.linenum))
# This can happen. Frequently inside a LogDrawer # This can happen. Frequently inside a LogDrawer
if len(line.cells) > 0 and len(line.cells[0]) > 0 and line.cells[0][0] == '-': if len(line.cells) > 0 and len(line.cells[0]) > 0 and line.cells[0][0] == '-':
@ -1067,8 +1058,6 @@ def token_from_type(tok_type):
class TimeRange: class TimeRange:
def __init__(self, start_time: OrgTime, end_time: OrgTime): def __init__(self, start_time: OrgTime, end_time: OrgTime):
assert start_time is not None
assert end_time is not None
self.start_time = start_time self.start_time = start_time
self.end_time = end_time self.end_time = end_time

View File

@ -16,18 +16,3 @@
| Content2-1 | Content2-2 | Content2-3 | | Content2-1 | Content2-2 | Content2-3 |
Content after the table. Content after the table.
** Indented table
:PROPERTIES:
:ID: 10-table-test-id-02-indented
:CREATED: [2020-01-01 Wed 01:01]
:END:
- This table is indented inside a list item.
- Item before in list
| Header1 | Header2 | Header3 |
|------------+------------+------------|
| Content1-1 | Content1-2 | Content1-3 (last cell unclosed)
| Content2-1 | Content2-2 | Content2-3 |
- Item after in list
- This item happens after the indented table.

View File

@ -4,8 +4,7 @@ import unittest
from datetime import date from datetime import date
from datetime import datetime as DT from datetime import datetime as DT
from org_rw import MarkerToken, MarkerType, Timestamp, dumps, load, loads, dom from org_rw import MarkerToken, MarkerType, Timestamp, dumps, load, loads
import org_rw
from utils.assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE, UNDERLINED, from utils.assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE, UNDERLINED,
VERBATIM, WEB_LINK, Doc, Tokens) VERBATIM, WEB_LINK, Doc, Tokens)
@ -682,66 +681,3 @@ class TestSerde(unittest.TestCase):
self.assertEqual(first_table[0].cells[1].strip(), 'Header2') self.assertEqual(first_table[0].cells[1].strip(), 'Header2')
self.assertEqual(first_table[0].cells[2].strip(), 'Header3') self.assertEqual(first_table[0].cells[2].strip(), 'Header3')
hl = hl.children[0]
tables = hl.get_tables()
first_table = tables[0]
self.assertEqual(len(first_table), 4)
print(first_table[0])
self.assertEqual(len(first_table[0].cells), 3)
self.assertEqual(first_table[0].cells[0].strip(), 'Header1')
self.assertEqual(first_table[0].cells[1].strip(), 'Header2')
self.assertEqual(first_table[0].cells[2].strip(), 'Header3')
def test_tables_html_file_10(self):
with open(os.path.join(DIR, "10-tables.org")) as f:
doc = load(f)
hl = doc.getTopHeadlines()[0]
tree = hl.as_dom()
non_props = [
item
for item in tree
if not isinstance(item, dom.PropertyDrawerNode)
]
self.assertTrue(isinstance(non_props[0], dom.Text)
and isinstance(non_props[1], dom.TableNode)
and isinstance(non_props[2], dom.Text),
'Expected <Text><Table><Text>')
hl = hl.children[0]
tree = hl.as_dom()
non_props = [
item
for item in tree
if not (isinstance(item, dom.PropertyDrawerNode)
or isinstance(item, dom.Text))
]
print_tree(non_props)
self.assertTrue(len(non_props) == 1,
'Expected <List>, with only (1) element')
def print_tree(tree, indentation=0, headline=None):
for element in tree:
print(" " * indentation * 2, "EL:", element)
if "children" in dir(element):
if len(element.children) > 0:
print_element(element.children, indentation + 1, headline)
print()
elif "content" in dir(element):
for content in element.content:
print_element(content, indentation + 1, headline)
def print_element(element, indentation, headline):
if isinstance(element, org_rw.Link):
print(" " * indentation * 2, "Link:", element.get_raw())
elif isinstance(element, str):
print(" " * indentation * 2, "Str[" + element.replace('\n', '<NL>') + "]", type(element))
else:
print_tree(element, indentation, headline)