Implement Headline.add_tag()/.create_headline_at_end().

This commit is contained in:
Sergio Martínez Portela 2023-10-07 13:14:13 +02:00
parent f11ecd05d6
commit 2749a5caad
1 changed files with 38 additions and 1 deletions

View File

@ -680,6 +680,9 @@ class Headline:
else:
return list(self.shallow_tags) + self.parent.tags
def add_tag(self, tag: str):
self.shallow_tags.append(tag)
def get_property(self, name: str, default=None):
for prop in self.properties:
if prop.key == name:
@ -872,6 +875,35 @@ class Headline:
return results
def create_headline_at_end(self) -> Headline:
headline = Headline(
start_line=1,
depth=self.depth + 1,
orig=None,
properties=[],
keywords=[],
priority_start=None,
priority=None,
title_start=None,
title="",
state="",
tags_start=None,
tags=[],
contents=[],
children=[],
structural=[],
delimiters=[],
list_items=[],
table_rows=[],
parent=self,
is_todo=False,
is_done=False,
spacing=" ",
)
self.children.append(headline)
return headline
RawLine = collections.namedtuple("RawLine", ("linenum", "line"))
Keyword = collections.namedtuple(
@ -1884,7 +1916,12 @@ class OrgDoc:
if headline.state:
state = headline.state + " "
yield "*" * headline.depth + headline.spacing + state + token_list_to_raw(headline.title.contents) + tags
raw_title = token_list_to_raw(headline.title.contents)
tags_padding = ""
if not raw_title.endswith(" ") and tags:
tags_padding = " "
yield "*" * headline.depth + headline.spacing + state + raw_title + tags_padding + tags
planning = headline.get_planning_line()
if planning is not None: