branch: elpa/gptel
commit fcdbe074140bf7b9c027a3478902edafe8ec76f8
Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>

    gptel-org: More fixes for conversion in punctuation (#813)
    
    * gptel-org.el (gptel--stream-convert-markdown->org): Fix handling
    of markdown asterisks next to punctuation.  Asterisks followed by
    punctuation such as in
    
     This is a *word*.
    
    should still be parsed as emphasis regions.  Make a special
    exception for an asterisk surrounded by punctuation, such as in
    "*" or (*).
---
 gptel-org.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/gptel-org.el b/gptel-org.el
index bf5aed57e6..5afb973918 100644
--- a/gptel-org.el
+++ b/gptel-org.el
@@ -578,7 +578,7 @@ elements."
             (save-excursion
               (when (and (re-search-forward (regexp-quote (match-string 0))
                                             (line-end-position) t)
-                         (looking-at "[[:space]]\\|\s")
+                         (looking-at "[[:space:][:punct:]]\\|\s")
                          (not (looking-back 
"\\(?:[[:space]]\\|\s\\)\\(?:_\\|\\*\\)"
                                             (max (- (point) 2) (point-min)))))
                 (delete-char -1) (insert "/") t))
@@ -710,12 +710,14 @@ cleaning up after."
                    (save-match-data
                      (save-excursion
                        (ignore-errors (backward-char 2))
-                       (cond      ; At bob, underscore/asterisk followed by 
word
-                        ((or (and (bobp) (looking-at 
"\\(?:_\\|\\*\\)\\([^[:space:][:punct:]]\\|$\\)"))
-                             (looking-at ; word followed by underscore/asterisk
-                              
"[^[:space:]\n]\\(?:_\\|\\*\\)\\(?:[[:space:]]\\|$\\)")
-                             (looking-at ; underscore/asterisk followed by word
-                              
"\\(?:[[:space:]]\\)\\(?:_\\|\\*\\)\\([^[:space:]]\\|$\\)"))
+                       (cond
+                        ((and     ; At bob, underscore/asterisk followed by 
word
+                          (or (and (bobp) (looking-at 
"\\(?:_\\|\\*\\)\\([^[:space:][:punct:]]\\|$\\)"))
+                              (looking-at ; word followed by 
underscore/asterisk
+                               
"[^[:space:]\n]\\(?:_\\|\\*\\)\\(?:[[:space:][:punct:]]\\|$\\)")
+                              (looking-at ; underscore/asterisk followed by 
word
+                               
"\\(?:[[:space:]]\\)\\(?:_\\|\\*\\)\\([^[:space:]]\\|$\\)"))
+                          (not (looking-at 
"[[:punct:]]\\(?:_\\|\\*\\)[[:punct:]]")))
                          ;; Emphasis, replace with slashes
                          (forward-char (if (bobp) 1 2)) (delete-char -1) 
(insert "/"))
                         ((or (and (bobp) (looking-at "\\*[[:space:]]"))

Reply via email to