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

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

[elpa] externals/ellama b1467d15e0 1/7: Add function to convert org synt


From: ELPA Syncer
Subject: [elpa] externals/ellama b1467d15e0 1/7: Add function to convert org syntax to markdown
Date: Fri, 29 Nov 2024 18:58:09 -0500 (EST)

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

    Add function to convert org syntax to markdown
    
    Added a new function `ellama-convert-org-to-md` that translates text
    from org syntax to markdown syntax using Emacs Org Export
    functionality. This function creates a temporary buffer, inserts the
    provided org text, exports it to markdown, and returns the resulting
    markdown string.
---
 ellama.el | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/ellama.el b/ellama.el
index 5bd5d8ecd2..a42faa5df8 100644
--- a/ellama.el
+++ b/ellama.el
@@ -1545,6 +1545,22 @@ Extract profession from this message. Be short and 
concise."
            :transform (lambda (_ _)
                         "Provide short final answer based on final 
solution.")))))
 
+(declare-function org-export-to-buffer "ox")
+
+(defun ellama-convert-org-to-md (text)
+  "Translate TEXT from org syntax to markdown syntax."
+  (require 'ox)
+  (require 'ox-md)
+  (let ((buf (make-temp-name "ellama-")))
+    (with-temp-buffer
+      (insert "#+OPTIONS: toc:nil\n" text)
+      (org-export-to-buffer 'md buf
+       nil nil t t nil (lambda () (text-mode))))
+    (with-current-buffer buf
+      (prog1
+         (string-trim (buffer-substring-no-properties (point-min) (point-max)))
+       (kill-buffer)))))
+
 (defun ellama-chat-done (text &optional on-done)
   "Chat done.
 Will call `ellama-chat-done-callback' and ON-DONE on TEXT."



reply via email to

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