mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-28 01:45:07 +01:00
Merge branch 'improve-org-results-representation'
This commit is contained in:
commit
19cb25bd9e
3 changed files with 19 additions and 8 deletions
|
@ -152,7 +152,7 @@ Use `which-key` if available, else display simple message in echo area"
|
|||
(replace-regexp-in-string
|
||||
"^[\(\) ]" ""
|
||||
;; extract entries from response as single string and convert to entries
|
||||
(format "#+STARTUP: showall hidestars inlineimages\n* %s\n%s"
|
||||
(format "* %s\n%s\n#+STARTUP: showall hidestars inlineimages"
|
||||
query
|
||||
(mapcar
|
||||
(lambda (args)
|
||||
|
|
|
@ -38,6 +38,8 @@ import datetime
|
|||
from pathlib import Path
|
||||
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("]","\]")
|
||||
|
@ -370,7 +372,9 @@ class Orgnode(object):
|
|||
n = ''
|
||||
for _ in range(0, self.level):
|
||||
n = n + '*'
|
||||
n = n + ' ' + self.todo + ' '
|
||||
n = n + ' '
|
||||
if self.todo:
|
||||
n = n + self.todo + ' '
|
||||
if self.prty:
|
||||
n = n + '[#' + self.prty + '] '
|
||||
n = n + self.headline
|
||||
|
@ -382,7 +386,12 @@ class Orgnode(object):
|
|||
n = n + closecolon
|
||||
n = n + "\n"
|
||||
|
||||
# Get body indentation from first line of body
|
||||
indent = indent_regex.match(self.body).group()
|
||||
|
||||
# Output Closed Date, Scheduled Date, Deadline Date
|
||||
if self.closed or self.scheduled or self.deadline:
|
||||
n = n + indent
|
||||
if self.closed:
|
||||
n = n + f'CLOSED: [{self.closed.strftime("%Y-%m-%d %a")}] '
|
||||
if self.scheduled:
|
||||
|
@ -393,10 +402,10 @@ class Orgnode(object):
|
|||
n = n + '\n'
|
||||
|
||||
# Ouput Property Drawer
|
||||
n = n + ":PROPERTIES:\n"
|
||||
n = n + indent + ":PROPERTIES:\n"
|
||||
for key, value in self.properties.items():
|
||||
n = n + f":{key}: {value}\n"
|
||||
n = n + ":END:\n"
|
||||
n = n + indent + f":{key}: {value}\n"
|
||||
n = n + indent + ":END:\n"
|
||||
|
||||
n = n + self.body
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ def test_parse_complete_entry(tmp_path):
|
|||
"Test parsing of entry with all important fields"
|
||||
# Arrange
|
||||
entry = f'''
|
||||
*** [#A] Heading :Tag1:TAG2:tag3:
|
||||
*** DONE [#A] Heading :Tag1:TAG2:tag3:
|
||||
CLOSED: [1984-04-01 Sun 12:00] SCHEDULED: <1984-04-01 Sun 09:00> DEADLINE: <1984-04-01 Sun>
|
||||
:PROPERTIES:
|
||||
:ID: 123-456-789-4234-1231
|
||||
|
@ -56,6 +56,7 @@ Body Line 2'''
|
|||
# Assert
|
||||
assert len(entries) == 1
|
||||
assert entries[0].Heading() == "Heading"
|
||||
assert entries[0].Todo() == "DONE"
|
||||
assert entries[0].Tags() == {"Tag1", "TAG2", "tag3"}
|
||||
assert entries[0].Body() == "- Clocked Log 1\nBody Line 1\nBody Line 2"
|
||||
assert entries[0].Priority() == "A"
|
||||
|
@ -124,7 +125,7 @@ def test_parse_multiple_entries(tmp_path):
|
|||
"Test parsing of multiple entries"
|
||||
# Arrange
|
||||
content = f'''
|
||||
*** [#A] Heading1 :tag1:
|
||||
*** FAILED [#A] Heading1 :tag1:
|
||||
CLOSED: [1984-04-01 Sun 12:00] SCHEDULED: <1984-04-01 Sun 09:00> DEADLINE: <1984-04-01 Sun>
|
||||
:PROPERTIES:
|
||||
:ID: 123-456-789-4234-0001
|
||||
|
@ -135,7 +136,7 @@ CLOCK: [1984-04-01 Sun 09:00]--[1984-04-01 Sun 12:00] => 3:00
|
|||
:END:
|
||||
Body 1
|
||||
|
||||
*** [#A] Heading2 :tag2:
|
||||
*** CANCELLED [#A] Heading2 :tag2:
|
||||
CLOSED: [1984-04-02 Sun 12:00] SCHEDULED: <1984-04-02 Sun 09:00> DEADLINE: <1984-04-02 Sun>
|
||||
:PROPERTIES:
|
||||
:ID: 123-456-789-4234-0002
|
||||
|
@ -156,6 +157,7 @@ Body 2
|
|||
assert len(entries) == 2
|
||||
for index, entry in enumerate(entries):
|
||||
assert entry.Heading() == f"Heading{index+1}"
|
||||
assert entry.Todo() == "FAILED" if index == 0 else "CANCELLED"
|
||||
assert entry.Tags() == {f"tag{index+1}"}
|
||||
assert entry.Body() == f"- Clocked Log {index+1}\nBody {index+1}\n\n"
|
||||
assert entry.Priority() == "A"
|
||||
|
|
Loading…
Reference in a new issue