Compare commits

..

No commits in common. "6943ebad7c881f1ff8fc5d0a0a87b1174ea7360b" and "fdc475cb1904e13dad9855fa504f6551ca8ef9f6" have entirely different histories.

3 changed files with 5 additions and 67 deletions

View File

@ -56,7 +56,7 @@ KEYWORDS_RE = re.compile(
DRAWER_START_RE = re.compile(r"^(?P<indentation>\s*):([^:]+):(?P<end_indentation>\s*)$") DRAWER_START_RE = re.compile(r"^(?P<indentation>\s*):([^:]+):(?P<end_indentation>\s*)$")
DRAWER_END_RE = re.compile(r"^(?P<indentation>\s*):END:(?P<end_indentation>\s*)$", re.I) DRAWER_END_RE = re.compile(r"^(?P<indentation>\s*):END:(?P<end_indentation>\s*)$", re.I)
NODE_PROPERTIES_RE = re.compile( NODE_PROPERTIES_RE = re.compile(
r"^(?P<indentation>\s*):(?P<key>[^ ()+:]+)(?P<plus>\+)?:(?P<spacing>\s*)(?P<value>.+)$" r"^(?P<indentation>\s*):(?P<key>[^ +:]+)(?P<plus>\+)?:(?P<spacing>\s*)(?P<value>.+)$"
) )
RAW_LINE_RE = re.compile(r"^\s*([^\s#:*]|$)") RAW_LINE_RE = re.compile(r"^\s*([^\s#:*]|$)")
BASE_TIME_STAMP_RE = r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})( ?(?P<dow>[^ ]+))?( (?P<start_hour>\d{1,2}):(?P<start_minute>\d{1,2})(-+(?P<end_hour>\d{1,2}):(?P<end_minute>\d{1,2}))?)?(?P<repetition> (?P<rep_mark>(\+|\+\+|\.\+|-|--))(?P<rep_value>\d+)(?P<rep_unit>[hdwmy]))?" BASE_TIME_STAMP_RE = r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})( ?(?P<dow>[^ ]+))?( (?P<start_hour>\d{1,2}):(?P<start_minute>\d{1,2})(-+(?P<end_hour>\d{1,2}):(?P<end_minute>\d{1,2}))?)?(?P<repetition> (?P<rep_mark>(\+|\+\+|\.\+|-|--))(?P<rep_value>\d+)(?P<rep_unit>[hdwmy]))?"
@ -1261,9 +1261,7 @@ def parse_headline(hl, doc, parent) -> Headline:
class OrgDoc: class OrgDoc:
def __init__( def __init__(self, headlines, keywords, contents, list_items):
self, headlines, keywords, contents, list_items, structural, properties
):
self.todo_keywords = DEFAULT_TODO_KEYWORDS self.todo_keywords = DEFAULT_TODO_KEYWORDS
self.done_keywords = DEFAULT_DONE_KEYWORDS self.done_keywords = DEFAULT_DONE_KEYWORDS
@ -1277,8 +1275,6 @@ class OrgDoc:
self.keywords: List[Property] = keywords self.keywords: List[Property] = keywords
self.contents: List[RawLine] = contents self.contents: List[RawLine] = contents
self.list_items: List[ListItem] = list_items self.list_items: List[ListItem] = list_items
self.structural: List = structural
self.properties: List = properties
self._path = None self._path = None
self.headlines: List[Headline] = list( self.headlines: List[Headline] = list(
map(lambda hl: parse_headline(hl, self, self), headlines) map(lambda hl: parse_headline(hl, self, self), headlines)
@ -1296,20 +1292,6 @@ class OrgDoc:
for content in self.contents: for content in self.contents:
yield from get_links_from_content(content) yield from get_links_from_content(content)
def get_keywords(self, name: str, default=None):
for prop in self.keywords:
if prop.key == name:
return prop.value
return default
def get_property(self, name: str, default=None):
for prop in self.properties:
if prop.key == name:
return prop.value
return default
def getProperties(self): def getProperties(self):
return self.keywords return self.keywords
@ -1464,12 +1446,6 @@ class OrgDoc:
def dump(self): def dump(self):
lines = [] lines = []
for prop in self.properties:
lines.append(self.dump_property(prop))
for struct in self.structural:
lines.append(self.dump_structural(struct))
for kw in self.keywords: for kw in self.keywords:
lines.append(self.dump_kw(kw)) lines.append(self.dump_kw(kw))
@ -1493,18 +1469,9 @@ class OrgDocReader:
self.contents: List[RawLine] = [] self.contents: List[RawLine] = []
self.delimiters: List[DelimiterLine] = [] self.delimiters: List[DelimiterLine] = []
self.list_items: List[ListItem] = [] self.list_items: List[ListItem] = []
self.structural: List = []
self.properties: List = []
def finalize(self): def finalize(self):
return OrgDoc( return OrgDoc(self.headlines, self.keywords, self.contents, self.list_items)
self.headlines,
self.keywords,
self.contents,
self.list_items,
self.structural,
self.properties,
)
## Construction ## Construction
def add_headline(self, linenum: int, match: re.Match) -> int: def add_headline(self, linenum: int, match: re.Match) -> int:
@ -1595,10 +1562,6 @@ class OrgDocReader:
self.headline_hierarchy[-1]["delimiters"].append(line) self.headline_hierarchy[-1]["delimiters"].append(line)
def add_property_drawer_line(self, linenum: int, line: str, match: re.Match) -> int: def add_property_drawer_line(self, linenum: int, line: str, match: re.Match) -> int:
if len(self.headline_hierarchy) == 0:
self.current_drawer = self.properties
self.structural.append((linenum, line))
else:
self.current_drawer = self.headline_hierarchy[-1]["properties"] self.current_drawer = self.headline_hierarchy[-1]["properties"]
self.headline_hierarchy[-1]["structural"].append((linenum, line)) self.headline_hierarchy[-1]["structural"].append((linenum, line))

View File

@ -1,13 +0,0 @@
:PROPERTIES:
:ID: 515054a9-ced8-4119-a844-71726f80dedf
:END:
#+title: 07-org-roam-v2
* Subnode
:PROPERTIES:
:CREATED: [2021-08-03 Mar 22:12]
:ID: 419f4651-21c8-4166-b8d5-692c34be9f93
:END:
** Sub sub node
- This has no ID

View File

@ -488,15 +488,3 @@ class TestSerde(unittest.TestCase):
self.assertEqual(lists2[1][1].content, " Second element") self.assertEqual(lists2[1][1].content, " Second element")
self.assertEqual(lists2[1][1].counter, "2") self.assertEqual(lists2[1][1].counter, "2")
self.assertEqual(lists2[1][1].counter_sep, ")") self.assertEqual(lists2[1][1].counter_sep, ")")
def test_org_roam_07(self):
with open(os.path.join(DIR, "07-org-roam-v2.org")) as f:
orig = f.read()
doc = loads(orig)
self.assertEqual(doc.get_property("ID"), "515054a9-ced8-4119-a844-71726f80dedf")
self.assertEqual(len(doc.getTopHeadlines()), 1)
hl = doc.getTopHeadlines()[0]
self.assertEqual(hl.get_property("ID"), "419f4651-21c8-4166-b8d5-692c34be9f93")
self.assertEqual(len(hl.children), 1)