mirror of https://codeberg.org/cage/tinmop/
- [modules] rewrite-message-urls, quoting regexp before replacing.
Also refactored some repeated code in a function.
This commit is contained in:
parent
3b0e8fed96
commit
3513f54fee
|
@ -51,15 +51,18 @@ So the whole list is like: '((\"foo\" \"bar\") (\"old\" \"new\") ...)")
|
||||||
(return-from inner t)))))
|
(return-from inner t)))))
|
||||||
results))
|
results))
|
||||||
|
|
||||||
|
(defun replace-mapping (mapping text)
|
||||||
|
(cl-ppcre:regex-replace-all (cl-ppcre:quote-meta-chars (car mapping))
|
||||||
|
text
|
||||||
|
(cdr mapping)))
|
||||||
|
|
||||||
(defun rewriting-link-message-hook-fn (message-window)
|
(defun rewriting-link-message-hook-fn (message-window)
|
||||||
(with-accessors ((source-text message-window:source-text)) message-window
|
(with-accessors ((source-text message-window:source-text)) message-window
|
||||||
(let* ((all-links (text-utils:collect-links source-text))
|
(let* ((all-links (text-utils:collect-links source-text))
|
||||||
(links-mapping (rewriting-link-messages-links-rules all-links)))
|
(links-mapping (rewriting-link-messages-links-rules all-links)))
|
||||||
(loop for mapping in links-mapping do
|
(loop for mapping in links-mapping do
|
||||||
(setf source-text
|
(setf source-text
|
||||||
(cl-ppcre:regex-replace-all (car mapping)
|
(replace-mapping mapping source-text))))))
|
||||||
source-text
|
|
||||||
(cdr mapping)))))))
|
|
||||||
|
|
||||||
(defun rewriting-link-links-window-hook-fn (all-links)
|
(defun rewriting-link-links-window-hook-fn (all-links)
|
||||||
(let ((links-mapping (rewriting-link-messages-links-rules all-links))
|
(let ((links-mapping (rewriting-link-messages-links-rules all-links))
|
||||||
|
@ -67,9 +70,7 @@ So the whole list is like: '((\"foo\" \"bar\") (\"old\" \"new\") ...)")
|
||||||
(loop for link in all-links do
|
(loop for link in all-links do
|
||||||
(let* ((mapping (find-if (lambda (a) (string= link (car a))) links-mapping))
|
(let* ((mapping (find-if (lambda (a) (string= link (car a))) links-mapping))
|
||||||
(mapped (if mapping
|
(mapped (if mapping
|
||||||
(cl-ppcre:regex-replace-all (car mapping)
|
(replace-mapping mapping link)
|
||||||
link
|
|
||||||
(cdr mapping))
|
|
||||||
link)))
|
link)))
|
||||||
(push mapped results)))
|
(push mapped results)))
|
||||||
(reverse results)))
|
(reverse results)))
|
||||||
|
|
Loading…
Reference in New Issue