From fc9ce664aee4a1f2875a13b474d0003cc91781b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Tue, 1 Nov 2022 19:57:50 +0100 Subject: [PATCH] Unify drawer node classes under a common parent. --- org_rw/dom.py | 27 +++++++++++---------------- org_rw/org_rw.py | 2 +- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/org_rw/dom.py b/org_rw/dom.py index dd9c7d7..bc24272 100644 --- a/org_rw/dom.py +++ b/org_rw/dom.py @@ -1,32 +1,23 @@ -class PropertyDrawerNode: +class DrawerNode: def __init__(self): self.children = [] def append(self, child): self.children.append(child) + +class PropertyDrawerNode(DrawerNode): + def __repr__(self): return "".format(len(self.children)) -class LogbookDrawerNode: - def __init__(self): - self.children = [] - - def append(self, child): - self.children.append(child) - +class LogbookDrawerNode(DrawerNode): def __repr__(self): return "".format(len(self.children)) -class ResultsDrawerNode: - def __init__(self): - self.children = [] - - def append(self, child): - self.children.append(child) - +class ResultsDrawerNode(DrawerNode): def __repr__(self): return "".format(len(self.children)) @@ -82,12 +73,16 @@ class ListItem: class BlockNode: + def __init__(self): + self.children = [] + def append(self, child): - raise NotImplementedError() + self.children.append(child) class CodeBlock(BlockNode): def __init__(self, header, subtype): + super().__init__() self.header = header self.lines = None self.subtype = subtype diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 01cae02..c6713b9 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -378,7 +378,7 @@ class Headline: elif isinstance(line, Text): if isinstance(current_node, dom.BlockNode): current_node.append(dom.Text(line)) - elif isinstance(current_node, dom.LogbookDrawerNode): + elif isinstance(current_node, dom.DrawerNode): current_node.append(dom.Text(line)) else: if isinstance(current_node, dom.TableNode):