diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 625d67a..16d3e49 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -290,6 +290,10 @@ class Headline: def id(self): return self.get_property("ID") + @id.setter + def id(self, value): + self.set_property("ID", value) + @property def clock(self): times = [] @@ -326,6 +330,33 @@ class Headline: return default + def set_property(self, name: str, value: str): + for prop in self.properties: + + # A matching property is found, update it + if prop.key == name: + prop.value = value + return + + # No matching property found, add it + else: + if len(self.properties) > 0: + last_prop = self.properties[-1] + last_line = last_prop.linenum + last_match = last_prop.match + else: + last_line = 0 + last_match = None + self.properties.append( + Property( + linenum=last_line, + match=last_match, + key=name, + value=value, + options=None, + ) + ) + def get_links(self): for content in self.contents: yield from get_links_from_content(content) diff --git a/org_rw/utils.py b/org_rw/utils.py index 04f0f1a..555671a 100644 --- a/org_rw/utils.py +++ b/org_rw/utils.py @@ -1,3 +1,5 @@ +import uuid + from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, Strike, Text, Underlined, Verbatim) @@ -36,3 +38,7 @@ def get_raw_contents(doc) -> str: return doc.get_raw() print("Unhandled type: " + str(doc)) raise NotImplementedError("Unhandled type: " + str(doc)) + + +def random_id() -> str: + return str(uuid.uuid4())