mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Do not normalize absolute filenames for creating links in OrgNode
This commit is contained in:
parent
07b98d35f1
commit
11917c6ddd
2 changed files with 10 additions and 7 deletions
|
@ -41,8 +41,13 @@ from os.path import relpath
|
|||
indent_regex = re.compile(r'^\s*')
|
||||
|
||||
def normalize_filename(filename):
|
||||
file_relative_to_home = f'~/{relpath(filename, start=Path.home())}'
|
||||
escaped_filename = f'{file_relative_to_home}'.replace("[","\[").replace("]","\]")
|
||||
"Normalize and escape filename for rendering"
|
||||
if not Path(filename).is_absolute():
|
||||
# Normalize relative filename to be relative to current directory
|
||||
normalized_filename = f'~/{relpath(filename, start=Path.home())}'
|
||||
else:
|
||||
normalized_filename = filename
|
||||
escaped_filename = f'{normalized_filename}'.replace("[","\[").replace("]","\]")
|
||||
return escaped_filename
|
||||
|
||||
def makelist(filename):
|
||||
|
|
|
@ -81,18 +81,17 @@ Body Line 1
|
|||
Body Line 2
|
||||
'''
|
||||
orgfile = create_file(tmp_path, entry)
|
||||
normalized_orgfile = f'~/{relpath(orgfile, start=Path.home())}'
|
||||
|
||||
# Act
|
||||
entries = orgnode.makelist(orgfile)
|
||||
|
||||
# Assert
|
||||
# SOURCE link rendered with Heading
|
||||
assert f':SOURCE: [[file:{normalized_orgfile}::*{entries[0].Heading()}]]' in f'{entries[0]}'
|
||||
assert f':SOURCE: [[file:{orgfile}::*{entries[0].Heading()}]]' in f'{entries[0]}'
|
||||
# ID link rendered with ID
|
||||
assert f':ID: id:123-456-789-4234-1231' in f'{entries[0]}'
|
||||
# LINE link rendered with line number
|
||||
assert f':LINE: file:{normalized_orgfile}::2' in f'{entries[0]}'
|
||||
assert f':LINE: file:{orgfile}::2' in f'{entries[0]}'
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
@ -115,8 +114,7 @@ Body Line 1'''
|
|||
# parsed heading from entry
|
||||
assert entries[0].Heading() == "Heading[1]"
|
||||
# ensure SOURCE link has square brackets in filename, heading escaped in rendered entries
|
||||
normalized_orgfile = f'~/{relpath(orgfile, start=Path.home())}'
|
||||
escaped_orgfile = f'{normalized_orgfile}'.replace("[1]", "\\[1\\]")
|
||||
escaped_orgfile = f'{orgfile}'.replace("[1]", "\\[1\\]")
|
||||
assert f':SOURCE: [[file:{escaped_orgfile}::*Heading\[1\]' in f'{entries[0]}'
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue