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

    Fix marker handling in block processing
    
    Addressed issues with marker initialization and insertion types to correctly
    handle block boundaries during text processing. Updated tests to include 
inline
    code translation from Markdown to Org.
---
 ellama.el            | 36 +++++++++++++++++++-----------------
 tests/test-ellama.el | 14 ++++++++++++++
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/ellama.el b/ellama.el
index 8d98ea8132..c850f1a212 100644
--- a/ellama.el
+++ b/ellama.el
@@ -628,12 +628,14 @@ Skip code blocks and math environments."
   (with-temp-buffer
     (insert (propertize text 'hard t))
     (goto-char (point-min))
-    (let (block-start
-         block-end
+    (let ((block-start (make-marker))
+         (block-end (make-marker))
          (prev-point (point-min)))
+      (set-marker-insertion-type block-start t)
+      (set-marker-insertion-type block-end t)
       ;; Process regions outside of blocks
       (while (re-search-forward "\\(#\\+BEGIN_SRC\\|\\$\\$\\|\\$\\|`\\)" nil t)
-        (setq block-start (match-beginning 0))
+        (set-marker block-start (match-beginning 0))
        (goto-char block-start)
         (let ((block-type (cond ((looking-at "#\\+BEGIN_SRC") 'src)
                                 ((looking-at "\\$\\$") 'math-display)
@@ -643,20 +645,20 @@ Skip code blocks and math environments."
           (ellama--apply-transformations prev-point block-start)
           ;; Skip over the block content
           (goto-char block-start)
-          (setq block-end
-               (cond
-                ((eq block-type 'src)
-                  (if (re-search-forward "#\\+END_SRC" nil t) (point) 
(point-max)))
-                ((eq block-type 'math-display)
-                  (if (re-search-forward "\\$\\$.+?\\$\\$" nil t) (point) 
(point-max)))
-                ((eq block-type 'math-inline)
-                  (if (re-search-forward "\\$.+?\\$" nil t) (point) 
(point-max)))
-                ((eq block-type 'code-inline)
-                 (if (re-search-forward "`\\(.+?\\)`" nil t)
-                     (progn
-                       (replace-match "~\\1~")
-                       (point))
-                   (point-max)))))
+          (set-marker block-end
+                     (cond
+                      ((eq block-type 'src)
+                       (if (re-search-forward "#\\+END_SRC" nil t) (point) 
(point-max)))
+                      ((eq block-type 'math-display)
+                       (if (re-search-forward "\\$\\$.+?\\$\\$" nil t) (point) 
(point-max)))
+                      ((eq block-type 'math-inline)
+                       (if (re-search-forward "\\$.+?\\$" nil t) (point) 
(point-max)))
+                      ((eq block-type 'code-inline)
+                       (if (re-search-forward "`\\([^`]+\\)`" nil t)
+                           (progn
+                             (replace-match "~\\1~")
+                             (point))
+                         (point-max)))))
           (when block-end
            (goto-char block-end))
          (setq prev-point (point))))
diff --git a/tests/test-ellama.el b/tests/test-ellama.el
index ddb1a04555..29ef24ff02 100644
--- a/tests/test-ellama.el
+++ b/tests/test-ellama.el
@@ -437,6 +437,20 @@ _more italic_")))
 $P_\\theta$
 /more italic/"))))
 
+(ert-deftest test-ellama-md-to-org-inline-code ()
+  (let ((result (ellama--translate-markdown-to-org-filter "```go
+package main
+```
+### Explanation:
+1. **Initialization**: We create a boolean slice `prime` of size `n+1`, where 
each
+index represents whether the number is prime (`true`) or not (`false`).")))
+    (should (string= result "#+BEGIN_SRC go
+package main
+#+END_SRC
+*** Explanation:
+1. *Initialization*: We create a boolean slice ~prime~ of size ~n+1~, where 
each
+index represents whether the number is prime (~true~) or not (~false~)."))))
+
 (defun ellama-test-max-common-prefix ()
   "Test the `ellama-max-common-prefix` function."
   (should (equal (ellama-max-common-prefix "" "") ""))

Reply via email to