emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ellama 1d2f7476f9 1/3: Convert org quote content to avo


From: ELPA Syncer
Subject: [elpa] externals/ellama 1d2f7476f9 1/3: Convert org quote content to avoid rendering issues
Date: Wed, 26 Jun 2024 03:59:56 -0400 (EDT)

branch: externals/ellama
commit 1d2f7476f9a3881971d4a9e9e6056e3e8ad4f627
Author: Sergey Kostyaev <sskostyaev@gmail.com>
Commit: Sergey Kostyaev <sskostyaev@gmail.com>

    Convert org quote content to avoid rendering issues
---
 ellama.el            | 12 +++++++++---
 tests/test-ellama.el | 12 ++++++------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/ellama.el b/ellama.el
index 58920215d1..5ebb547a3b 100644
--- a/ellama.el
+++ b/ellama.el
@@ -944,13 +944,18 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
       (fill-region (point-min) (point-max) nil t t))
     (buffer-substring-no-properties (point-min) (point-max))))
 
+(defun ellama--org-quote (content)
+  "Return transformed CONTENT for org quotes."
+  (replace-regexp-in-string "^*" " *" content))
+
 (cl-defmethod ellama-context-element-format
   ((element ellama-context-element-webpage-quote) (mode (eql 'org-mode)))
   "Format the context ELEMENT for the major MODE."
   (ignore mode)
   (with-slots (name url content) element
     (if ellama-show-quotes
-       (format "[[%s][%s]]:\n#+BEGIN_QUOTE\n%s\n#+END_QUOTE\n" url name 
content)
+       (format "[[%s][%s]]:\n#+BEGIN_QUOTE\n%s\n#+END_QUOTE\n"
+               url name (ellama--org-quote content))
       (format "[[%s][%s]]" url name))))
 
 ;; Info node quote context elements
@@ -989,7 +994,7 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
                         (not ellama--current-session))
                    (ellama--translate-string name)
                  name)
-               content)
+               (ellama--org-quote content))
       (format "[[%s][%s]]"
              (replace-regexp-in-string
               "(\\(.?*\\)) \\(.*\\)" "info:\\1#\\2" name)
@@ -1027,7 +1032,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
   (ignore mode)
   (with-slots (path content) element
     (if ellama-show-quotes
-       (format "[[%s][%s]]:\n#+BEGIN_QUOTE\n%s\n#+END_QUOTE\n" path path 
content)
+       (format "[[%s][%s]]:\n#+BEGIN_QUOTE\n%s\n#+END_QUOTE\n"
+               path path (ellama--org-quote content))
       (format "[[%s][%s]]" path path))))
 
 
diff --git a/tests/test-ellama.el b/tests/test-ellama.el
index 3b10950c81..2d1fc4fad8 100644
--- a/tests/test-ellama.el
+++ b/tests/test-ellama.el
@@ -108,13 +108,13 @@
     (should (equal "[[https://example.com/][test name]]" 
(ellama-context-element-format element 'org-mode)))))
 
 (ert-deftest test-ellama-context-element-format-webpage-quote-enabled-org-mode 
()
-  (let ((element (ellama-context-element-webpage-quote :name "test name" :url 
"https://example.com/"; :content "1\n\n2"))
+  (let ((element (ellama-context-element-webpage-quote :name "test name" :url 
"https://example.com/"; :content "1\n\n* 2"))
        (ellama-show-quotes t))
     (should (equal "[[https://example.com/][test name]]:
 #+BEGIN_QUOTE
 1
 
-2
+ * 2
 #+END_QUOTE
 "
                   (ellama-context-element-format element 'org-mode)))))
@@ -136,9 +136,9 @@
     (should (equal "[[(emacs)Top][(emacs)Top]]" (ellama-context-element-format 
element 'org-mode)))))
 
 (ert-deftest 
test-ellama-context-element-format-info-node-quote-enabled-org-mode ()
-  (let ((element (ellama-context-element-info-node-quote :name "(emacs)Top" 
:content "1\n\n2"))
+  (let ((element (ellama-context-element-info-node-quote :name "(emacs)Top" 
:content "1\n\n* 2"))
        (ellama-show-quotes t))
-    (should (equal 
"[[(emacs)Top][(emacs)Top]]:\n#+BEGIN_QUOTE\n1\n\n2\n#+END_QUOTE\n"
+    (should (equal "[[(emacs)Top][(emacs)Top]]:\n#+BEGIN_QUOTE\n1\n\n * 
2\n#+END_QUOTE\n"
                   (ellama-context-element-format element 'org-mode)))))
 
 (ert-deftest test-ellama-context-element-format-file-quote-disabled-markdown ()
@@ -163,13 +163,13 @@
     (should (equal "[[/tmp/test.txt][/tmp/test.txt]]" 
(ellama-context-element-format element 'org-mode)))))
 
 (ert-deftest test-ellama-context-element-format-file-quote-enabled-org-mode ()
-  (let ((element (ellama-context-element-file-quote :path "/tmp/test.txt" 
:content "1\n\n2"))
+  (let ((element (ellama-context-element-file-quote :path "/tmp/test.txt" 
:content "1\n\n* 2"))
        (ellama-show-quotes t))
     (should (equal "[[/tmp/test.txt][/tmp/test.txt]]:
 #+BEGIN_QUOTE
 1
 
-2
+ * 2
 #+END_QUOTE
 "
                   (ellama-context-element-format element 'org-mode)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]