Skip to content

Commit fcdbe07

Browse files
committed
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 (*).
1 parent e1050ef commit fcdbe07

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

gptel-org.el

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ elements."
578578
(save-excursion
579579
(when (and (re-search-forward (regexp-quote (match-string 0))
580580
(line-end-position) t)
581-
(looking-at "[[:space]]\\|\s")
581+
(looking-at "[[:space:][:punct:]]\\|\s")
582582
(not (looking-back "\\(?:[[:space]]\\|\s\\)\\(?:_\\|\\*\\)"
583583
(max (- (point) 2) (point-min)))))
584584
(delete-char -1) (insert "/") t))
@@ -710,12 +710,14 @@ cleaning up after."
710710
(save-match-data
711711
(save-excursion
712712
(ignore-errors (backward-char 2))
713-
(cond ; At bob, underscore/asterisk followed by word
714-
((or (and (bobp) (looking-at "\\(?:_\\|\\*\\)\\([^[:space:][:punct:]]\\|$\\)"))
715-
(looking-at ; word followed by underscore/asterisk
716-
"[^[:space:]\n]\\(?:_\\|\\*\\)\\(?:[[:space:]]\\|$\\)")
717-
(looking-at ; underscore/asterisk followed by word
718-
"\\(?:[[:space:]]\\)\\(?:_\\|\\*\\)\\([^[:space:]]\\|$\\)"))
713+
(cond
714+
((and ; At bob, underscore/asterisk followed by word
715+
(or (and (bobp) (looking-at "\\(?:_\\|\\*\\)\\([^[:space:][:punct:]]\\|$\\)"))
716+
(looking-at ; word followed by underscore/asterisk
717+
"[^[:space:]\n]\\(?:_\\|\\*\\)\\(?:[[:space:][:punct:]]\\|$\\)")
718+
(looking-at ; underscore/asterisk followed by word
719+
"\\(?:[[:space:]]\\)\\(?:_\\|\\*\\)\\([^[:space:]]\\|$\\)"))
720+
(not (looking-at "[[:punct:]]\\(?:_\\|\\*\\)[[:punct:]]")))
719721
;; Emphasis, replace with slashes
720722
(forward-char (if (bobp) 1 2)) (delete-char -1) (insert "/"))
721723
((or (and (bobp) (looking-at "\\*[[:space:]]"))

0 commit comments

Comments
 (0)