branch: externals/gnosis
commit e084821657e19a267c3e9b2bf586ba212e0f0e6d
Author: Thanos Apollo <[email protected]>
Commit: Thanos Apollo <[email protected]>

    utils: Add replace-string-with-link.
---
 gnosis-utils.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gnosis-utils.el b/gnosis-utils.el
index cde68de7db..fdf875e77d 100644
--- a/gnosis-utils.el
+++ b/gnosis-utils.el
@@ -61,5 +61,14 @@ Optionally, use custom DEFAULT-FACE."
            nil t))))
     (buffer-string)))
 
+(defun gnosis-utils-replace-string-with-link (text string node-id)
+  "Replace STRING in TEXT with org-link to NODE-ID.
+Returns (MODIFIED-P . NEW-TEXT)."
+  (let ((new-text (replace-regexp-in-string
+                   (regexp-quote string)
+                   (format "[[id:%s][%s]]" node-id string)
+                   text t t)))
+    (cons (not (string= text new-text)) new-text)))
+
 (provide 'gnosis-utils)
 ;;; gnosis-utils.el ends here

Reply via email to