Ensure markdown entries in khoj.el results separated by empty line

- Update khoj.el test to reflect updated rendering logic
- Move ledger render function before image rendered to group functions
  with similar logic closer
This commit is contained in:
Debanjum Singh Solanky 2023-01-26 19:04:46 -03:00
parent 85ae46f429
commit 2e13e15625
2 changed files with 17 additions and 17 deletions

View file

@ -177,7 +177,7 @@ Use `which-key` if available, else display simple message in echo area"
;; Extract markdown entry from each item in json response
(cdr (assoc 'entry json-response-item))
;; Format markdown entry as a string
(format "%s")
(format "%s\n\n")
;; Standardize results to 2nd level heading for consistent rendering
(replace-regexp-in-string "^\#+" "##"))))
;; Render entries into markdown formatted string with query set as as top level heading
@ -204,6 +204,18 @@ Use `which-key` if available, else display simple message in echo area"
;; remove leading (, ) or SPC from extracted entries string
(replace-regexp-in-string "^[\(\) ]" ""))))
(defun khoj--extract-entries-as-ledger (json-response query)
"Convert JSON-RESPONSE, QUERY from API to ledger entries."
(thread-last json-response
;; extract and render entries from API response
(mapcar (lambda (args) (format "%s\n\n" (cdr (assoc 'entry args)))))
;; Set query as heading in rendered results buffer
(format ";; %s\n\n%s\n" query)
;; remove leading (, ) or SPC from extracted entries string
(replace-regexp-in-string "^[\(\) ]" "")
;; remove trailing (, ) or SPC from extracted entries string
(replace-regexp-in-string "[\(\) ]$" "")))
(defun khoj--extract-entries-as-images (json-response query)
"Convert JSON-RESPONSE, QUERY from API to html with images."
(let ((image-results-buffer-html-format-str "<html>\n<body>\n<h1>%s</h1>%s\n\n</body>\n</html>")
@ -232,18 +244,6 @@ Use `which-key` if available, else display simple message in echo area"
;; remove trailing (, ) or SPC from extracted entries string
(replace-regexp-in-string "[\(\) ]$" ""))))
(defun khoj--extract-entries-as-ledger (json-response query)
"Convert JSON-RESPONSE, QUERY from API to ledger entries."
(thread-last json-response
;; extract and render entries from API response
(mapcar (lambda (args) (format "%s\n\n" (cdr (assoc 'entry args)))))
;; Set query as heading in rendered results buffer
(format ";; %s\n\n%s\n" query)
;; remove leading (, ) or SPC from extracted entries string
(replace-regexp-in-string "^[\(\) ]" "")
;; remove trailing (, ) or SPC from extracted entries string
(replace-regexp-in-string "[\(\) ]$" "")))
(defun khoj--buffer-name-to-content-type (buffer-name)
"Infer content type based on BUFFER-NAME."
(let ((enabled-content-types (khoj--get-enabled-content-types))

View file

@ -44,7 +44,7 @@
(json-read-from-string
"[\
{\
\"entry\": \"## Upgrade\\n\\n Penance to Immortality\\n\",\
\"entry\": \"## Upgrade\\n\\n Penance to Immortality\",\
\"score\": \"0.376\",\
\"additional\": {\
\"file\": \"/home/ravan/upgrade.md\",\
@ -52,7 +52,7 @@
}\
},\
{\
\"entry\": \"## Act\\n\\n Rule everything\\n\",\
\"entry\": \"## Act\\n\\n Rule everything\",\
\"score\": \"0.153\",\
\"additional\": {\
\"file\": \"/home/ravan/act.md\",\
@ -67,10 +67,10 @@
# Become God\n\
## Upgrade\n\
\n\
Penance to Immortality\n\
Penance to Immortality\n\n\
## Act\n\
\n\
Rule everything\n"))))
Rule everything\n\n"))))
(ert-deftest khoj-tests--extract-entries-as-org ()