diff --git a/kagi.el b/kagi.el
index 8956d48..a92985f 100644
--- a/kagi.el
+++ b/kagi.el
@@ -75,19 +75,41 @@ The token can be generated inside your account at https://kagi.com/settings?p=ap
(string-join curl-flags " ")
kagi-api-fastgpt-url)))
+(defun kagi--html-bold-to-face (string)
+ "Convert HTML tags inside STRING to faces.
+
+Fun fact: initial version of this function was generated by
+FastGPT with the following prompt:
+
+ write an Emacs Lisp function that accepts a string with html
+ bold tags, and returns a string with bold face text properties
+ applied for the tags content atd the tags removed"
+ (with-temp-buffer
+ (insert string)
+ (goto-char (point-min))
+ (while (re-search-forward "\\([^<]*\\)" nil t)
+ (replace-match (propertize (match-string 1) 'font-lock-face 'bold) t nil))
+ (buffer-string)))
+
(defun kagi--format-output (output)
- ;; Replace Bold tags
- (replace-regexp-in-string "" "\e[0m"
- (replace-regexp-in-string "" "\e[1m" output)))
+ (kagi--html-bold-to-face output))
+
+
+(defun kagi--format-reference-index (i)
+ (propertize (format "[%d]" i) 'font-lock-face 'bold))
(defun kagi--format-references (references)
- (string-join (seq-map-indexed (lambda (ref i)
- (let ((title (gethash "title" ref))
- (snippet (gethash "snippet" ref))
- (url (gethash "url" ref)))
- (format "\e[1m[%d]\e[0m %s\n%s\n%s" (1+ i) title (kagi--format-output snippet) url)))
- references)
- "\n\n"))
+ (string-join
+ (seq-map-indexed (lambda (ref i)
+ (let ((title (gethash "title" ref))
+ (snippet (gethash "snippet" ref))
+ (url (gethash "url" ref)))
+ (format "%s %s\n%s\n%s"
+ (kagi--format-reference-index (1+ i))
+ title
+ (kagi--html-bold-to-face snippet) url)))
+ references)
+ "\n\n"))
(defun kagi--call-fastgpt (prompt)
(let ((command (kagi--build-curl-command prompt)))