Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#108) Elide and escape title before custom transformation #109

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions curl-integration-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
(sleep-for timeout)
(should (equal (buffer-string) expected-outcome)))))

(ert-deftest org-cliplink-long-title-with-custom-transformer--http ()
(let ((url "http://127.0.0.1:8001/long-title.html")
(expected-outcome "[[http://127.0.0.1:8001/long-title.html][long title]]")
(timeout 1)
(custom-org-cliplink
(lambda ()
(org-cliplink-insert-transformed-title
(org-cliplink-clipboard-content)
(lambda (url title)
(org-cliplink-org-mode-link-transformer
url
(replace-regexp-in-string "\\(very \\)+\\([[:alpha:][:space:]]+\\)" "\\2" title)))))))
(with-temp-buffer
(kill-new url)
(funcall custom-org-cliplink)
(sleep-for timeout)
(should (equal (buffer-string) expected-outcome)))))

(ert-deftest org-cliplink-escape-title--http ()
(let ((url "http://127.0.0.1:8001/html4-escaping.html")
(expected-outcome "[[http://127.0.0.1:8001/html4-escaping.html][&{Hello} '{World} α  ]]")
Expand Down
19 changes: 11 additions & 8 deletions org-cliplink.el
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@ Used when the current transport implementation is set to

(defun org-cliplink-org-mode-link-transformer (url title)
(if title
(format "[[%s][%s]]" url title)
(format "[[%s][%s]]" url (org-cliplink-elide-string
(org-cliplink-escape-html4
title)
org-cliplink-max-length))
(format "[[%s]]" url)))

(defun org-cliplink-insert-org-mode-link-callback (url title)
Expand All @@ -468,12 +471,9 @@ Used when the current transport implementation is set to
(org-cliplink-uncompress-gziped-text (cdr response))
(cdr response)))
(decoded-content (decode-coding-string content (quote utf-8))))
(org-cliplink-elide-string
(org-cliplink-escape-html4
(org-cliplink-straight-string
(org-cliplink-extract-title-from-html
decoded-content)))
org-cliplink-max-length)))
(org-cliplink-straight-string
(org-cliplink-extract-title-from-html
decoded-content))))

(defun org-cliplink-read-secrets ()
(when (file-exists-p org-cliplink-secrets-path)
Expand Down Expand Up @@ -525,7 +525,10 @@ the required text to the current buffer."
(let ((response-buffer (url-retrieve-synchronously url t)))
(when response-buffer
(with-current-buffer response-buffer
(org-cliplink-extract-and-prepare-title-from-current-buffer))))))
(org-cliplink-elide-string
(org-cliplink-escape-html4
(org-cliplink-extract-and-prepare-title-from-current-buffer))
org-cliplink-max-length))))))

;;;###autoload
(defun org-cliplink ()
Expand Down
5 changes: 5 additions & 0 deletions test-data/site/long-title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>very very very very very very very very very very very very very very very very very long title</title>
</head>
</html>
24 changes: 24 additions & 0 deletions url-el-integration-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@
(sleep-for timeout)
(should (equal (buffer-string) expected-outcome)))))

(ert-deftest org-cliplink-long-title-with-custom-transformer--http ()
(let ((url "http://127.0.0.1:8001/long-title.html")
(expected-outcome "[[http://127.0.0.1:8001/long-title.html][long title]]")
(timeout 1)
(custom-org-cliplink
(lambda ()
(org-cliplink-insert-transformed-title
(org-cliplink-clipboard-content)
(lambda (url title)
(org-cliplink-org-mode-link-transformer
url
(replace-regexp-in-string "\\(very \\)+\\([[:alpha:][:space:]]+\\)" "\\2" title)))))))
(with-temp-buffer
(kill-new url)
(funcall custom-org-cliplink)
(sleep-for timeout)
(should (equal (buffer-string) expected-outcome)))))

(ert-deftest org-cliplink-retrieve-long-title-synchronously--http ()
(let ((url "http://127.0.0.1:8001/long-title.html")
(expected-outcome "very very very very very very very very very very very very very very very ve..."))
(should (equal (org-cliplink-retrieve-title-synchronously url)
expected-outcome))))

(ert-deftest org-cliplink-simple-title--http ()
(let ((url "http://127.0.0.1:8001/http.html")
(expected-outcome "[[http://127.0.0.1:8001/http.html][Hello World]]")
Expand Down