Use title, when present, as root ancestor of entries instead of file path

This commit is contained in:
Debanjum Singh Solanky 2023-11-17 14:47:06 -08:00
parent ddb07def0d
commit 55785d50c3
3 changed files with 20 additions and 12 deletions

View file

@ -110,7 +110,7 @@ class OrgToEntries(TextToEntries):
compiled = heading
if state.verbose > 2:
logger.debug(f"Title: {parsed_entry.heading}")
logger.debug(f"Title: {heading}")
if parsed_entry.tags:
tags_str = " ".join(parsed_entry.tags)

View file

@ -80,7 +80,7 @@ def makelist(file, filename):
} # populated from #+SEQ_TODO line
level = ""
heading = ""
ancestor_headings = [f"{filename}"]
ancestor_headings = []
bodytext = ""
introtext = ""
tags = list() # set of all tags in headline
@ -257,6 +257,9 @@ def makelist(file, filename):
n.priority = priority_search.group(1)
n.heading = priority_search.group(2)
# Prefix filepath/title to ancestors
n.ancestors = [file_title] + n.ancestors
# Set SOURCE property to a file+heading based org-mode link to the entry
if n.level == 0:
n.properties["LINE"] = f"file:{normalize_filename(filename)}::0"
@ -295,15 +298,20 @@ class Orgnode(object):
self._logbook = list() # List of clock-in, clock-out tuples representing logbook entries
self._ancestor_headings = ancestor_headings.copy()
# Look for priority in headline and transfer to prty field
@property
def ancestors(self):
def ancestors(self) -> List[str]:
"""
Return the Heading text of the node without the TODO tag
Return the ancestor headings of the node
"""
return self._ancestor_headings
@ancestors.setter
def ancestors(self, new_ancestors):
"""
Update the ancestor headings of the node
"""
self._ancestor_headings = new_ancestors
@property
def heading(self):
"""

View file

@ -262,7 +262,7 @@ Body Line 1"""
assert entries[0].closed == ""
assert entries[0].scheduled == ""
assert entries[0].deadline == ""
assert entries[0].ancestors == []
assert entries[0].ancestors == ["test"]
# ----------------------------------------------------------------------------------------------------
@ -287,7 +287,7 @@ Body Line 1
assert entries[0].closed == ""
assert entries[0].scheduled == ""
assert entries[0].deadline == ""
assert entries[0].ancestors == []
assert entries[0].ancestors == ["title1 title2"]
# ----------------------------------------------------------------------------------------------------
@ -308,10 +308,10 @@ entry body
assert len(entries) == 2
assert entries[0].heading == "Title"
assert entries[0].body == "intro body\n"
assert entries[0].ancestors == []
assert entries[0].ancestors == ["Title"]
assert entries[1].heading == "Entry Heading"
assert entries[1].body == "entry body\n\n"
assert entries[1].ancestors == [f"{orgfile}"]
assert entries[1].ancestors == ["Title"]
# ----------------------------------------------------------------------------------------------------
@ -332,10 +332,10 @@ entry body
assert len(entries) == 2
assert entries[0].heading == "Title1 Title2"
assert entries[0].body == "intro body\n"
assert entries[0].ancestors == []
assert entries[0].ancestors == ["Title1 Title2"]
assert entries[1].heading == "Entry Heading"
assert entries[1].body == "entry body\n\n"
assert entries[1].ancestors == [f"{orgfile}"]
assert entries[0].ancestors == ["Title1 Title2"]
# ----------------------------------------------------------------------------------------------------