From fb86be8cd988b97433d2dda960d99a0c2379d441 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 17 Jun 2022 03:11:11 +0300 Subject: [PATCH] Add ID, File+Heading based Links to Org-Mode Entries - Add links to property drawer - This ensures results returned by semantic search contain these links - This allows the user to jump to entry within original file for context - The ID, file+heading based links are more robust to find relevant entry in original file than the line no based link, as edits being done by user to original files between embedding regenerations --- src/processor/org_mode/orgnode.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/processor/org_mode/orgnode.py b/src/processor/org_mode/orgnode.py index 1d0ea649..d5428e43 100644 --- a/src/processor/org_mode/orgnode.py +++ b/src/processor/org_mode/orgnode.py @@ -77,7 +77,7 @@ def makelist(filename): deadline_date = '' thisNode.setProperties(propdict) nodelist.append( thisNode ) - propdict = {'SOURCE': f'file:{filename}::{ctr}'} + propdict = {'LINE': f'file:{filename}::{ctr}'} level = hdng.group(1) heading = hdng.group(2) bodytext = "" @@ -114,7 +114,11 @@ def makelist(filename): prop_srch = re.search(r'^\s*:(.*?):\s*(.*?)\s*$', line) if prop_srch: - propdict[prop_srch.group(1)] = prop_srch.group(2) + # Set ID property to an id based org-mode link to the entry + if prop_srch.group(1) == 'ID': + propdict['ID'] = f'id:{prop_srch.group(2)}' + else: + propdict[prop_srch.group(1)] = prop_srch.group(2) continue sd_re = re.search(r'SCHEDULED:\s+<([0-9]+)\-([0-9]+)\-([0-9]+)', line) if sd_re: @@ -145,11 +149,16 @@ def makelist(filename): if todoSrch.group(1) in todos: n.setHeading( todoSrch.group(2) ) n.setTodo ( todoSrch.group(1) ) + + # extract, set priority from heading, update heading if necessary prtysrch = re.search(r'^\[\#(A|B|C)\] (.*?)$', n.Heading()) if prtysrch: n.setPriority(prtysrch.group(1)) n.setHeading(prtysrch.group(2)) + # Set SOURCE property to a file+heading based org-mode link to the entry + n.properties['SOURCE'] = f'[[file:{filename}::*{n.Heading()}]]' + return nodelist ######################