mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Use filename or #+TITLE as heading for 0th level content in org files
- Set LINE, SOURCE link properties in property drawer correctly for content which falls under no heading - See Issue #83 for more details
This commit is contained in:
@@ -73,6 +73,7 @@ def makelist(filename):
|
|||||||
propdict = dict()
|
propdict = dict()
|
||||||
in_properties_drawer = False
|
in_properties_drawer = False
|
||||||
in_logbook_drawer = False
|
in_logbook_drawer = False
|
||||||
|
file_title = f'{filename}'
|
||||||
|
|
||||||
for line in f:
|
for line in f:
|
||||||
ctr += 1
|
ctr += 1
|
||||||
@@ -111,6 +112,10 @@ def makelist(filename):
|
|||||||
kwlist = re.findall(r'([A-Z]+)\(', line)
|
kwlist = re.findall(r'([A-Z]+)\(', line)
|
||||||
for kw in kwlist: todos[kw] = ""
|
for kw in kwlist: todos[kw] = ""
|
||||||
|
|
||||||
|
# Set file title to TITLE property, if it exists
|
||||||
|
if line[:8] == "#+TITLE:":
|
||||||
|
file_title = line[8:].strip()
|
||||||
|
|
||||||
# Ignore Properties Drawers Completely
|
# Ignore Properties Drawers Completely
|
||||||
if re.search(':PROPERTIES:', line):
|
if re.search(':PROPERTIES:', line):
|
||||||
in_properties_drawer=True
|
in_properties_drawer=True
|
||||||
@@ -167,7 +172,7 @@ def makelist(filename):
|
|||||||
bodytext = bodytext + line
|
bodytext = bodytext + line
|
||||||
|
|
||||||
# write out last node
|
# write out last node
|
||||||
thisNode = Orgnode(level, heading, bodytext, tags)
|
thisNode = Orgnode(level, heading or file_title, bodytext, tags)
|
||||||
thisNode.setProperties(propdict)
|
thisNode.setProperties(propdict)
|
||||||
if sched_date:
|
if sched_date:
|
||||||
thisNode.setScheduled(sched_date)
|
thisNode.setScheduled(sched_date)
|
||||||
@@ -196,6 +201,10 @@ def makelist(filename):
|
|||||||
n.setHeading(prtysrch.group(2))
|
n.setHeading(prtysrch.group(2))
|
||||||
|
|
||||||
# Set SOURCE property to a file+heading based org-mode link to the entry
|
# 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'
|
||||||
|
n.properties['SOURCE'] = f'[[file:{normalize_filename(filename)}]]'
|
||||||
|
else:
|
||||||
escaped_heading = n.Heading().replace("[","\\[").replace("]","\\]")
|
escaped_heading = n.Heading().replace("[","\\[").replace("]","\\]")
|
||||||
n.properties['SOURCE'] = f'[[file:{normalize_filename(filename)}::*{escaped_heading}]]'
|
n.properties['SOURCE'] = f'[[file:{normalize_filename(filename)}::*{escaped_heading}]]'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user