[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel b634f05fe5 218/273: gptel: Tweak markdown to org con
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel b634f05fe5 218/273: gptel: Tweak markdown to org conversion |
Date: |
Wed, 1 May 2024 10:02:29 -0400 (EDT) |
branch: elpa/gptel
commit b634f05fe50712f98b1e49a8bc0a3316e228a850
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel: Tweak markdown to org conversion
gptel.el (gptel--convert-markdown->org,
gptel--stream-convert-markdown->org): Handle the case of Markdown
bullet lists that begin with a "*", which the Gemini LLMs produce
often. Address #238.
---
gptel.el | 62 +++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/gptel.el b/gptel.el
index cbd5094edd..5f573caeb4 100644
--- a/gptel.el
+++ b/gptel.el
@@ -1298,23 +1298,28 @@ elements."
(delete-char 1))
((looking-back "\\(?:[[:word:]]\\|\s\\)\\*\\{2\\}"
(max (- (point) 3) (point-min)))
- (backward-delete-char 1))))
+ (delete-char -1))))
("*"
- (if (save-match-data
- (and (looking-back "\\(?:[[:space:]]\\|\s\\)\\(?:_\\|\\*\\)"
- (max (- (point) 2) (point-min)))
- (not (looking-at "[[:space:]]\\|\s"))))
- ;; Possible beginning of italics
- (and
- (save-excursion
- (when (and (re-search-forward (regexp-quote (match-string 0))
nil t)
- (looking-at "[[:space]]\\|\s")
- (not (looking-back
"\\(?:[[:space]]\\|\s\\)\\(?:_\\|\\*\\)"
- (max (- (point) 2)
(point-min)))))
- (backward-delete-char 1)
- (insert "/") t))
- (progn (backward-delete-char 1)
- (insert "/")))))))
+ (cond
+ ((save-match-data
+ (and (looking-back "\\(?:[[:space:]]\\|\s\\)\\(?:_\\|\\*\\)"
+ (max (- (point) 2) (point-min)))
+ (not (looking-at "[[:space:]]\\|\s"))))
+ ;; Possible beginning of emphasis
+ (and
+ (save-excursion
+ (when (and (re-search-forward (regexp-quote (match-string 0))
+ (line-end-position) t)
+ (looking-at "[[:space]]\\|\s")
+ (not (looking-back
"\\(?:[[:space]]\\|\s\\)\\(?:_\\|\\*\\)"
+ (max (- (point) 2) (point-min)))))
+ (delete-char -1) (insert "/") t))
+ (progn (delete-char -1) (insert "/"))))
+ ((save-excursion
+ (ignore-errors (backward-char 2))
+ (looking-at "\\(?:$\\|\\`\\)\n\\*[[:space:]]"))
+ ;; Bullet point, replace with hyphen
+ (delete-char -1) (insert "-"))))))
(buffer-string)))
(defun gptel--stream-convert-markdown->org ()
@@ -1363,18 +1368,21 @@ text stream."
(delete-char 1))
((looking-back "\\(?:[[:word:]]\\|\s\\)\\*\\{2\\}"
(max (- (point) 3) (point-min)))
- (backward-delete-char 1))))
+ (delete-char -1))))
((and "*" (guard (not in-src-block)))
- (when (save-match-data
- (save-excursion
- (backward-char 2)
- (or
- (looking-at
-
"[^[:space:][:punct:]\n]\\(?:_\\|\\*\\)\\(?:[[:space:][:punct:]]\\|$\\)")
- (looking-at
-
"\\(?:[[:space:][:punct:]]\\)\\(?:_\\|\\*\\)\\([^[:space:][:punct:]]\\|$\\)"))))
- (backward-delete-char 1)
- (insert "/"))))))
+ (save-match-data
+ (save-excursion
+ (ignore-errors (backward-char 2))
+ (cond
+ ((or (looking-at
+
"[^[:space:][:punct:]\n]\\(?:_\\|\\*\\)\\(?:[[:space:][:punct:]]\\|$\\)")
+ (looking-at
+
"\\(?:[[:space:][:punct:]]\\)\\(?:_\\|\\*\\)\\([^[:space:][:punct:]]\\|$\\)"))
+ ;; Emphasis, replace with slashes
+ (forward-char 2) (delete-char -1) (insert "/"))
+ ((looking-at "\\(?:$\\|\\`\\)\n\\*[[:space:]]")
+ ;; Bullet point, replace with hyphen
+ (forward-char 2) (delete-char -1) (insert "-")))))))))
(if noop-p
(buffer-substring (point) start-pt)
(prog1 (buffer-substring (point) (point-max))
- [nongnu] elpa/gptel 5c3b26aeec 138/273: gptel-curl: Tweak Curl arguments for windows, (continued)
- [nongnu] elpa/gptel 5c3b26aeec 138/273: gptel-curl: Tweak Curl arguments for windows, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 15404f639d 139/273: README: Update instructions for Azure (#147), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel ddd69cbbcf 147/273: gptel-curl: Replace Curl timeout with speed-time, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 60cb406567 162/273: gptel: Improve documentation of gptel-send, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 8ec233d79c 174/273: gptel: Name gptel buffer according to backend, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 235134a176 186/273: Bit of feedback when copying reponse to kill ring, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 50fb34ab7c 187/273: Fix compilation warnings, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 10f57605ce 195/273: gptel: Improve Org stream conversion, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 6a385ffc2f 199/273: README: Add FAQ entry for OpenAI quota error (#93), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 199595b0c8 216/273: gptel: Handle status HTTP 100, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b634f05fe5 218/273: gptel: Tweak markdown to org conversion,
ELPA Syncer <=
- [nongnu] elpa/gptel 2487ada4d6 217/273: gptel-anthropic: Handle missing response chunks (trial), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e18ceb1f84 226/273: gptel: Improve logging, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b2985392f4 270/273: gptel: Linting for NonGNU ELPA, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel f0b18c5f8b 113/273: gptel-transient: Exit gptel-system-prompt after selection (#96), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 42d53b25e5 041/273: gptel: Handle insufficient quota and other errors, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 18222818dc 070/273: gptel: Add gptel-request, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 36051b15d5 068/273: gptel: Unify error descriptions, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 20af9a8b99 095/273: gptel: curl proxy support (#69), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel c29e1cd673 079/273: gptel-transient: Minor formatting changes., ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e0a7898645 108/273: gptel: Add pre-response-hook, ELPA Syncer, 2024/05/01