Support updating of elements's ID.

This commit is contained in:
Sergio Martínez Portela 2021-04-03 00:59:00 +02:00
parent fe454bd85e
commit 2d7e7f23ed
2 changed files with 37 additions and 0 deletions

View File

@ -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)

View File

@ -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())