mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Fix OrgNode render of entries with property drawers and empty body
- Issue
- Indent regex was previously catching escape sequences like newlines
- This was resulting in entries with only escape sequences in body to
be prepended to property drawers etc during rendering
- Fix
- Update indent regex to only look for spaces in each line
- Only render body when body contains non-escape characters
- Create test to prevent this regression from silently resurfacing
This commit is contained in:
@@ -38,7 +38,7 @@ import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os.path import relpath
|
from os.path import relpath
|
||||||
|
|
||||||
indent_regex = re.compile(r'^\s*')
|
indent_regex = re.compile(r'^ *')
|
||||||
|
|
||||||
def normalize_filename(filename):
|
def normalize_filename(filename):
|
||||||
"Normalize and escape filename for rendering"
|
"Normalize and escape filename for rendering"
|
||||||
@@ -455,6 +455,8 @@ class Orgnode(object):
|
|||||||
n = n + indent + f":{key}: {value}\n"
|
n = n + indent + f":{key}: {value}\n"
|
||||||
n = n + indent + ":END:\n"
|
n = n + indent + ":END:\n"
|
||||||
|
|
||||||
n = n + self._body
|
# Output Body
|
||||||
|
if self.hasBody:
|
||||||
|
n = n + self._body
|
||||||
|
|
||||||
return n
|
return n
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# Standard Packages
|
# Standard Packages
|
||||||
import datetime
|
import datetime
|
||||||
from os.path import relpath
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from src.processor.org_mode import orgnode
|
from src.processor.org_mode import orgnode
|
||||||
@@ -89,6 +87,34 @@ Body Line 2'''
|
|||||||
assert entries[0].logbook == [(datetime.datetime(1984,4,1,9,0,0), datetime.datetime(1984,4,1,12,0,0))]
|
assert entries[0].logbook == [(datetime.datetime(1984,4,1,9,0,0), datetime.datetime(1984,4,1,12,0,0))]
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------------------------------
|
||||||
|
def test_render_entry_with_property_drawer_and_empty_body(tmp_path):
|
||||||
|
"Render heading entry with property drawer"
|
||||||
|
# Arrange
|
||||||
|
entry_to_render = f'''
|
||||||
|
*** [#A] Heading1 :tag1:
|
||||||
|
:PROPERTIES:
|
||||||
|
:ID: 111-111-111-1111-1111
|
||||||
|
:END:
|
||||||
|
\t\r \n
|
||||||
|
'''
|
||||||
|
orgfile = create_file(tmp_path, entry_to_render)
|
||||||
|
|
||||||
|
expected_entry = f'''*** [#A] Heading1 :tag1:
|
||||||
|
:PROPERTIES:
|
||||||
|
:LINE: file:{orgfile}::2
|
||||||
|
:ID: id:111-111-111-1111-1111
|
||||||
|
:SOURCE: [[file:{orgfile}::*Heading1]]
|
||||||
|
:END:
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Act
|
||||||
|
parsed_entries = orgnode.makelist(orgfile)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert f'{parsed_entries[0]}' == expected_entry
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_all_links_to_entry_rendered(tmp_path):
|
def test_all_links_to_entry_rendered(tmp_path):
|
||||||
"Ensure all links to entry rendered in property drawer from entry"
|
"Ensure all links to entry rendered in property drawer from entry"
|
||||||
|
|||||||
Reference in New Issue
Block a user