[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 7dcb1af 11/41: Improve org-link-plain-re
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 7dcb1af 11/41: Improve org-link-plain-re |
Date: |
Sun, 16 May 2021 04:57:16 -0400 (EDT) |
branch: externals/org
commit 7dcb1afb6926cf51e78a7edc37e36ed91c683cac
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Bastien <bzg@gnu.org>
Improve org-link-plain-re
* lisp/ol.el (org-link-make-regexps): Allow URLs with up to two
levels of nested brackets.
* lisp/org.el (org-link-plain-re): Update docstring.
* testing/lisp/test-ol.el: Add tests for the plain link regular
expression.
(org-link-plain-re): Update docstring. Now,
Now, URLs like [1] can be matched. The new regexp is based on [2].
The docstring of `org-link-plain-re' explicitly mentions that the
regexp must contain groups for the link type and the path.
[1] https://doi.org/10.1016/0160-791x(79)90023-x
[2] https://daringfireball.net/2010/07/improved_regex_for_matching_urls
---
lisp/ol.el | 41 +++++++++++++-----
testing/lisp/test-ol.el | 110 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+), 10 deletions(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index e6ba6e4..9d86241 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -512,7 +512,10 @@ links more efficient."
"Matches link with angular brackets, spaces are allowed.")
(defvar org-link-plain-re nil
- "Matches plain link, without spaces.")
+ "Matches plain link, without spaces.
+Group 1 must contain the link type (i.e. https).
+Group 2 must contain the link path (i.e. //example.com).
+Used by `org-element-link-parser'.")
(defvar org-link-bracket-re nil
"Matches a link in double brackets.")
@@ -800,15 +803,33 @@ This should be called after the variable
`org-link-parameters' has changed."
(format "<%s:\\([^>\n]*\\(?:\n[ \t]*[^> \t\n][^>\n]*\\)*\\)>"
types-re)
org-link-plain-re
- (concat
- "\\<" types-re ":"
- "\\([^][ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:]
\t\n]\\|/\\)\\)\\)")
- ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
- org-link-bracket-re
- (rx (seq "[["
- ;; URI part: match group 1.
- (group
- (one-or-more
+ (let* ((non-space-bracket "[^][ \t\n()<>]")
+ (parenthesis
+ `(seq "("
+ (0+ (or (regex ,non-space-bracket)
+ (seq "("
+ (0+ (regex ,non-space-bracket))
+ ")")))
+ ")")))
+ ;; Heuristics for an URL link inspired by
+ ;;
https://daringfireball.net/2010/07/improved_regex_for_matching_urls
+ (rx-to-string
+ `(seq word-start
+ ;; Link type: match group 1.
+ (regexp ,types-re)
+ ":"
+ ;; Link path: match group 2.
+ (group
+ (1+ (or (regex ,non-space-bracket)
+ ,parenthesis))
+ (or (regexp "[^[:punct:] \t\n]")
+ ?/
+ ,parenthesis)))))
+ org-link-bracket-re
+ (rx (seq "[["
+ ;; URI part: match group 1.
+ (group
+ (one-or-more
(or (not (any "[]\\"))
(and "\\" (zero-or-more "\\\\") (any "[]"))
(and (one-or-more "\\") (not (any "[]"))))))
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index 5b7dc51..ddcc570 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -491,5 +491,115 @@
(org-previous-link))
(buffer-substring (point) (line-end-position))))))
+
+;;; Link regexps
+
+
+(defmacro test-ol-parse-link-in-text (text)
+ "Return list of :type and :path of link parsed in TEXT.
+\"<point>\" string must be at the beginning of the link to be parsed."
+ (declare (indent 1))
+ `(org-test-with-temp-text ,text
+ (list (org-element-property :type (org-element-link-parser))
+ (org-element-property :path (org-element-link-parser)))))
+
+(ert-deftest test-ol/plain-link-re ()
+ "Test `org-link-plain-re'."
+ (should
+ (equal
+ '("https" "//example.com")
+ (test-ol-parse-link-in-text
+ "(<point>https://example.com)")))
+ (should
+ (equal
+ '("https" "//example.com/qwe()")
+ (test-ol-parse-link-in-text
+ "(Some text <point>https://example.com/qwe())")))
+ (should
+ (equal
+ '("https" "//doi.org/10.1016/0160-791x(79)90023-x")
+ (test-ol-parse-link-in-text
+ "<point>https://doi.org/10.1016/0160-791x(79)90023-x")))
+ (should
+ (equal
+ '("file" "aa")
+ (test-ol-parse-link-in-text
+ "The <point>file:aa link")))
+ (should
+ (equal
+ '("file" "a(b)c")
+ (test-ol-parse-link-in-text
+ "The <point>file:a(b)c link")))
+ (should
+ (equal
+ '("file" "a()")
+ (test-ol-parse-link-in-text
+ "The <point>file:a() link")))
+ (should
+ (equal
+ '("file" "aa((a))")
+ (test-ol-parse-link-in-text
+ "The <point>file:aa((a)) link")))
+ (should
+ (equal
+ '("file" "aa(())")
+ (test-ol-parse-link-in-text
+ "The <point>file:aa(()) link")))
+ (should
+ (equal
+ '("file" "/a")
+ (test-ol-parse-link-in-text
+ "The <point>file:/a link")))
+ (should
+ (equal
+ '("file" "/a/")
+ (test-ol-parse-link-in-text
+ "The <point>file:/a/ link")))
+ (should
+ (equal
+ '("http" "//")
+ (test-ol-parse-link-in-text
+ "The <point>http:// link")))
+ (should
+ (equal
+ '("file" "ab")
+ (test-ol-parse-link-in-text
+ "The (some <point>file:ab) link")))
+ (should
+ (equal
+ '("file" "aa")
+ (test-ol-parse-link-in-text
+ "The <point>file:aa) link")))
+ (should
+ (equal
+ '("file" "aa")
+ (test-ol-parse-link-in-text
+ "The <point>file:aa( link")))
+ (should
+ (equal
+ '("http" "//foo.com/more_(than)_one_(parens)")
+ (test-ol-parse-link-in-text
+ "The <point>http://foo.com/more_(than)_one_(parens) link")))
+ (should
+ (equal
+ '("http" "//foo.com/blah_(wikipedia)#cite-1")
+ (test-ol-parse-link-in-text
+ "The <point>http://foo.com/blah_(wikipedia)#cite-1 link")))
+ (should
+ (equal
+ '("http" "//foo.com/blah_(wikipedia)_blah#cite-1")
+ (test-ol-parse-link-in-text
+ "The <point>http://foo.com/blah_(wikipedia)_blah#cite-1 link")))
+ (should
+ (equal
+ '("http" "//foo.com/unicode_(✪)_in_parens")
+ (test-ol-parse-link-in-text
+ "The <point>http://foo.com/unicode_(✪)_in_parens link")))
+ (should
+ (equal
+ '("http" "//foo.com/(something)?after=parens")
+ (test-ol-parse-link-in-text
+ "The <point>http://foo.com/(something)?after=parens link"))))
+
(provide 'test-ol)
;;; test-ol.el ends here
- [elpa] externals/org updated (e444181 -> 70d98b5), ELPA Syncer, 2021/05/16
- [elpa] externals/org dcb6013 02/41: agenda: Fix org-duration-to-minutes error (take 2), ELPA Syncer, 2021/05/16
- [elpa] externals/org 0e39bf8 03/41: Throw user errors when trying to drag inline tasks, ELPA Syncer, 2021/05/16
- [elpa] externals/org 3581f37 04/41: CONTRIBUTE: Small enhancements, ELPA Syncer, 2021/05/16
- [elpa] externals/org fa3c9c8 05/41: lisp/org-id.el: Small enhancements, ELPA Syncer, 2021/05/16
- [elpa] externals/org 90a9ee1 08/41: lisp/org-agenda.el: Fix bug in `org-agenda-highlight-todo', ELPA Syncer, 2021/05/16
- [elpa] externals/org f318cd6 14/41: Fix test-org-element/cache "Preserve local structures when re-parenting.", ELPA Syncer, 2021/05/16
- [elpa] externals/org f00ad09 10/41: org-refile.el: Fix the case of emtpy buffer name, ELPA Syncer, 2021/05/16
- [elpa] externals/org 7dcb1af 11/41: Improve org-link-plain-re,
ELPA Syncer <=
- [elpa] externals/org bfda3cc 13/41: lisp/org.el: Don't let RET indent in source code blocks, ELPA Syncer, 2021/05/16
- [elpa] externals/org 24473b5 15/41: lisp/org.el: Use "[BUG]" instead of "Bug:" for bug reports, ELPA Syncer, 2021/05/16
- [elpa] externals/org 8531bb6 09/41: lisp/org.el: Minor aesthetic clean-up, ELPA Syncer, 2021/05/16
- [elpa] externals/org 88fbe21 01/41: Add Luc Pellissier as maintainer for two ob-* files, ELPA Syncer, 2021/05/16
- [elpa] externals/org dd88356 06/41: lisp/org-inlinetask.el: Silent the byte-compiler, ELPA Syncer, 2021/05/16
- [elpa] externals/org 5a0f6c9 07/41: lisp/ox-md.el: Mark some arguments as unused, ELPA Syncer, 2021/05/16
- [elpa] externals/org 99d873b 12/41: lisp/org.el: Fix indenting of planning line, ELPA Syncer, 2021/05/16
- [elpa] externals/org 3f59ea9 20/41: Add a test for known bug in org-element-cache, ELPA Syncer, 2021/05/16
- [elpa] externals/org b183315 21/41: Set org-adapt-indentation explicitly in some tests, ELPA Syncer, 2021/05/16
- [elpa] externals/org 33027f9 17/41: New command `org-refile-reverse' bound to C-c C-M-w, ELPA Syncer, 2021/05/16