summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-02-15 18:08:03 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2013-02-15 18:08:03 +0100
commit78a652716e996297a8b6004274946c8d99c8bf4a (patch)
tree286121616ac93b57781af69a529a8516e69356b1
parent5a1d46b99034345aabd8b1f4852806339f2726c2 (diff)
downloadorg-mode-78a652716e996297a8b6004274946c8d99c8bf4a.tar.gz
ox: Whitespaces are not significant when matching a fuzzy link
* lisp/ox.el (org-export-resolve-fuzzy-link): Whitespaces are not significant when matching a fuzzy link. * lisp/org-element.el (org-element-link-parser): Do not remove newlines characters in paths anymore, since this is not required. * testing/lisp/test-org-element.el: Update tests. * testing/lisp/test-ox.el: Add test.
-rw-r--r--lisp/org-element.el6
-rw-r--r--lisp/ox.el26
-rw-r--r--testing/lisp/test-org-element.el8
-rw-r--r--testing/lisp/test-ox.el54
4 files changed, 49 insertions, 45 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index f17273c..c701de0 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -3007,11 +3007,7 @@ Assume point is at the beginning of the link."
raw-link (org-translate-link
(org-link-expand-abbrev
(org-match-string-no-properties 1)))
- ;; Remove newline characters due to filling. Headlines,
- ;; targets, radio targets and name affiliated keywords
- ;; cannot contain any.
- link (org-link-unescape
- (replace-regexp-in-string "\n[ \t]*" " " raw-link)))
+ link (org-link-unescape raw-link))
;; Determine TYPE of link and set PATH accordingly.
(cond
;; File type.
diff --git a/lisp/ox.el b/lisp/ox.el
index a3b43cd..93e3f55 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3658,9 +3658,14 @@ Return value can be an object, an element, or nil:
- Otherwise, return nil.
-Assume LINK type is \"fuzzy\"."
- (let* ((path (org-element-property :path link))
- (match-title-p (eq (aref path 0) ?*)))
+Assume LINK type is \"fuzzy\". White spaces are not
+significant."
+ (let* ((raw-path (org-element-property :path link))
+ (match-title-p (eq (aref raw-path 0) ?*))
+ ;; Split PATH at white spaces so matches are space
+ ;; insensitive.
+ (path (org-split-string
+ (if match-title-p (substring raw-path 1) raw-path))))
(cond
;; First try to find a matching "<<path>>" unless user specified
;; he was looking for an headline (path starts with a *
@@ -3670,7 +3675,8 @@ Assume LINK type is \"fuzzy\"."
(lambda (blob)
(and (or (eq (org-element-type blob) 'target)
(equal (org-element-property :key blob) "TARGET"))
- (equal (org-element-property :value blob) path)
+ (equal (org-split-string (org-element-property :value blob))
+ path)
blob))
info t)))
;; Then try to find an element with a matching "#+NAME: path"
@@ -3679,7 +3685,8 @@ Assume LINK type is \"fuzzy\"."
(org-element-map (plist-get info :parse-tree)
org-element-all-elements
(lambda (el)
- (when (string= (org-element-property :name el) path) el))
+ (let ((name (org-element-property :name el)))
+ (when (and name (equal (org-split-string name) path)) el)))
info 'first-match)))
;; Last case: link either points to an headline or to
;; nothingness. Try to find the source, with priority given to
@@ -3693,9 +3700,9 @@ Assume LINK type is \"fuzzy\"."
(lambda (name data)
(org-element-map data 'headline
(lambda (headline)
- (when (string=
- (org-element-property :raw-value headline)
- name)
+ (when (equal (org-split-string
+ (org-element-property :raw-value headline))
+ name)
headline))
info 'first-match)))))
;; Search among headlines sharing an ancestor with link, from
@@ -3709,7 +3716,8 @@ Assume LINK type is \"fuzzy\"."
(org-export-get-genealogy link)) nil)
;; No match with a common ancestor: try full parse-tree.
(funcall find-headline
- (if match-title-p (substring path 1) path)
+ (if (not match-title-p) path
+ (cons (substring (car path) 1) (cdr path)))
(plist-get info :parse-tree))))))))
(defun org-export-resolve-id-link (link info)
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 0f2f93f..902198a 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1288,13 +1288,7 @@ e^{i\\pi}+1=0
(org-element-map
(org-element-parse-buffer) 'link
(lambda (link) (org-element-property :type link))
- nil t nil t)))))
- ;; Corner case: links with filled path.
- (should
- (equal "a b"
- (org-test-with-temp-text "* a b\n[[a\nb]]"
- (progn (forward-line 1)
- (org-element-property :path (org-element-context)))))))
+ nil t nil t))))))
;;;; Macro
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index ad40493..acd9a77 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -1205,10 +1205,10 @@ Paragraph[fn:1]"
"Paragraph.\n#+TARGET: Test\n[[Test]]"
(should-not
(org-element-map
- tree 'link
- (lambda (link)
- (org-export-get-ordinal
- (org-export-resolve-fuzzy-link link info) info)) info)))
+ tree 'link
+ (lambda (link)
+ (org-export-get-ordinal
+ (org-export-resolve-fuzzy-link link info) info)) info)))
;; 2. Link to an headline should return headline's number.
(org-test-with-parsed-data
"Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
@@ -1216,10 +1216,10 @@ Paragraph[fn:1]"
;; Note: Headline's number is in fact a list of numbers.
(equal '(2)
(org-element-map
- tree 'link
- (lambda (link)
- (org-export-get-ordinal
- (org-export-resolve-fuzzy-link link info) info)) info t))))
+ tree 'link
+ (lambda (link)
+ (org-export-get-ordinal
+ (org-export-resolve-fuzzy-link link info) info)) info t))))
;; 3. Link to a target in an item should return item's number.
(org-test-with-parsed-data
"- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
@@ -1227,10 +1227,10 @@ Paragraph[fn:1]"
;; Note: Item's number is in fact a list of numbers.
(equal '(1 2)
(org-element-map
- tree 'link
- (lambda (link)
- (org-export-get-ordinal
- (org-export-resolve-fuzzy-link link info) info)) info t))))
+ tree 'link
+ (lambda (link)
+ (org-export-get-ordinal
+ (org-export-resolve-fuzzy-link link info) info)) info t))))
;; 4. Link to a target in a footnote should return footnote's
;; number.
(org-test-with-parsed-data "
@@ -1238,10 +1238,10 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(should
(equal '(2 3)
(org-element-map
- tree 'link
- (lambda (link)
- (org-export-get-ordinal
- (org-export-resolve-fuzzy-link link info) info)) info))))
+ tree 'link
+ (lambda (link)
+ (org-export-get-ordinal
+ (org-export-resolve-fuzzy-link link info) info)) info))))
;; 5. Link to a named element should return sequence number of that
;; element.
(org-test-with-parsed-data
@@ -1249,10 +1249,10 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(should
(= 2
(org-element-map
- tree 'link
- (lambda (link)
- (org-export-get-ordinal
- (org-export-resolve-fuzzy-link link info) info)) info t))))
+ tree 'link
+ (lambda (link)
+ (org-export-get-ordinal
+ (org-export-resolve-fuzzy-link link info) info)) info t))))
;; 6. Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
(org-test-with-parsed-data
@@ -1260,10 +1260,16 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(should
(equal '(2)
(org-element-map
- tree 'link
- (lambda (link)
- (org-export-get-ordinal
- (org-export-resolve-fuzzy-link link info) info)) info t)))))
+ tree 'link
+ (lambda (link)
+ (org-export-get-ordinal
+ (org-export-resolve-fuzzy-link link info) info)) info t))))
+ ;; 7. Space are not significant when matching a fuzzy link.
+ (should
+ (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
+ (org-element-map tree 'link
+ (lambda (link) (org-export-resolve-fuzzy-link link info))
+ info t))))
(ert-deftest test-org-export/resolve-coderef ()
"Test `org-export-resolve-coderef' specifications."