forked from mirrors/org-mode
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.
This commit is contained in:
parent
5a1d46b990
commit
78a652716e
|
@ -3007,11 +3007,7 @@ Assume point is at the beginning of the link."
|
||||||
raw-link (org-translate-link
|
raw-link (org-translate-link
|
||||||
(org-link-expand-abbrev
|
(org-link-expand-abbrev
|
||||||
(org-match-string-no-properties 1)))
|
(org-match-string-no-properties 1)))
|
||||||
;; Remove newline characters due to filling. Headlines,
|
link (org-link-unescape raw-link))
|
||||||
;; targets, radio targets and name affiliated keywords
|
|
||||||
;; cannot contain any.
|
|
||||||
link (org-link-unescape
|
|
||||||
(replace-regexp-in-string "\n[ \t]*" " " raw-link)))
|
|
||||||
;; Determine TYPE of link and set PATH accordingly.
|
;; Determine TYPE of link and set PATH accordingly.
|
||||||
(cond
|
(cond
|
||||||
;; File type.
|
;; File type.
|
||||||
|
|
26
lisp/ox.el
26
lisp/ox.el
|
@ -3658,9 +3658,14 @@ Return value can be an object, an element, or nil:
|
||||||
|
|
||||||
- Otherwise, return nil.
|
- Otherwise, return nil.
|
||||||
|
|
||||||
Assume LINK type is \"fuzzy\"."
|
Assume LINK type is \"fuzzy\". White spaces are not
|
||||||
(let* ((path (org-element-property :path link))
|
significant."
|
||||||
(match-title-p (eq (aref path 0) ?*)))
|
(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
|
(cond
|
||||||
;; First try to find a matching "<<path>>" unless user specified
|
;; First try to find a matching "<<path>>" unless user specified
|
||||||
;; he was looking for an headline (path starts with a *
|
;; he was looking for an headline (path starts with a *
|
||||||
|
@ -3670,7 +3675,8 @@ Assume LINK type is \"fuzzy\"."
|
||||||
(lambda (blob)
|
(lambda (blob)
|
||||||
(and (or (eq (org-element-type blob) 'target)
|
(and (or (eq (org-element-type blob) 'target)
|
||||||
(equal (org-element-property :key 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))
|
blob))
|
||||||
info t)))
|
info t)))
|
||||||
;; Then try to find an element with a matching "#+NAME: path"
|
;; 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-map (plist-get info :parse-tree)
|
||||||
org-element-all-elements
|
org-element-all-elements
|
||||||
(lambda (el)
|
(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)))
|
info 'first-match)))
|
||||||
;; Last case: link either points to an headline or to
|
;; Last case: link either points to an headline or to
|
||||||
;; nothingness. Try to find the source, with priority given to
|
;; nothingness. Try to find the source, with priority given to
|
||||||
|
@ -3693,9 +3700,9 @@ Assume LINK type is \"fuzzy\"."
|
||||||
(lambda (name data)
|
(lambda (name data)
|
||||||
(org-element-map data 'headline
|
(org-element-map data 'headline
|
||||||
(lambda (headline)
|
(lambda (headline)
|
||||||
(when (string=
|
(when (equal (org-split-string
|
||||||
(org-element-property :raw-value headline)
|
(org-element-property :raw-value headline))
|
||||||
name)
|
name)
|
||||||
headline))
|
headline))
|
||||||
info 'first-match)))))
|
info 'first-match)))))
|
||||||
;; Search among headlines sharing an ancestor with link, from
|
;; Search among headlines sharing an ancestor with link, from
|
||||||
|
@ -3709,7 +3716,8 @@ Assume LINK type is \"fuzzy\"."
|
||||||
(org-export-get-genealogy link)) nil)
|
(org-export-get-genealogy link)) nil)
|
||||||
;; No match with a common ancestor: try full parse-tree.
|
;; No match with a common ancestor: try full parse-tree.
|
||||||
(funcall find-headline
|
(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))))))))
|
(plist-get info :parse-tree))))))))
|
||||||
|
|
||||||
(defun org-export-resolve-id-link (link info)
|
(defun org-export-resolve-id-link (link info)
|
||||||
|
|
|
@ -1288,13 +1288,7 @@ e^{i\\pi}+1=0
|
||||||
(org-element-map
|
(org-element-map
|
||||||
(org-element-parse-buffer) 'link
|
(org-element-parse-buffer) 'link
|
||||||
(lambda (link) (org-element-property :type link))
|
(lambda (link) (org-element-property :type link))
|
||||||
nil t nil t)))))
|
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)))))))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; Macro
|
;;;; Macro
|
||||||
|
|
|
@ -1205,10 +1205,10 @@ Paragraph[fn:1]"
|
||||||
"Paragraph.\n#+TARGET: Test\n[[Test]]"
|
"Paragraph.\n#+TARGET: Test\n[[Test]]"
|
||||||
(should-not
|
(should-not
|
||||||
(org-element-map
|
(org-element-map
|
||||||
tree 'link
|
tree 'link
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
(org-export-resolve-fuzzy-link link info) info)) info)))
|
(org-export-resolve-fuzzy-link link info) info)) info)))
|
||||||
;; 2. Link to an headline should return headline's number.
|
;; 2. Link to an headline should return headline's number.
|
||||||
(org-test-with-parsed-data
|
(org-test-with-parsed-data
|
||||||
"Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
|
"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.
|
;; Note: Headline's number is in fact a list of numbers.
|
||||||
(equal '(2)
|
(equal '(2)
|
||||||
(org-element-map
|
(org-element-map
|
||||||
tree 'link
|
tree 'link
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
(org-export-resolve-fuzzy-link link info) info)) info t))))
|
(org-export-resolve-fuzzy-link link info) info)) info t))))
|
||||||
;; 3. Link to a target in an item should return item's number.
|
;; 3. Link to a target in an item should return item's number.
|
||||||
(org-test-with-parsed-data
|
(org-test-with-parsed-data
|
||||||
"- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
|
"- 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.
|
;; Note: Item's number is in fact a list of numbers.
|
||||||
(equal '(1 2)
|
(equal '(1 2)
|
||||||
(org-element-map
|
(org-element-map
|
||||||
tree 'link
|
tree 'link
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
(org-export-resolve-fuzzy-link link info) info)) info t))))
|
(org-export-resolve-fuzzy-link link info) info)) info t))))
|
||||||
;; 4. Link to a target in a footnote should return footnote's
|
;; 4. Link to a target in a footnote should return footnote's
|
||||||
;; number.
|
;; number.
|
||||||
(org-test-with-parsed-data "
|
(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
|
(should
|
||||||
(equal '(2 3)
|
(equal '(2 3)
|
||||||
(org-element-map
|
(org-element-map
|
||||||
tree 'link
|
tree 'link
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
(org-export-resolve-fuzzy-link link info) info)) info))))
|
(org-export-resolve-fuzzy-link link info) info)) info))))
|
||||||
;; 5. Link to a named element should return sequence number of that
|
;; 5. Link to a named element should return sequence number of that
|
||||||
;; element.
|
;; element.
|
||||||
(org-test-with-parsed-data
|
(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
|
(should
|
||||||
(= 2
|
(= 2
|
||||||
(org-element-map
|
(org-element-map
|
||||||
tree 'link
|
tree 'link
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
(org-export-resolve-fuzzy-link link info) info)) info t))))
|
(org-export-resolve-fuzzy-link link info) info)) info t))))
|
||||||
;; 6. Link to a target not within an item, a table, a footnote
|
;; 6. Link to a target not within an item, a table, a footnote
|
||||||
;; reference or definition should return section number.
|
;; reference or definition should return section number.
|
||||||
(org-test-with-parsed-data
|
(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
|
(should
|
||||||
(equal '(2)
|
(equal '(2)
|
||||||
(org-element-map
|
(org-element-map
|
||||||
tree 'link
|
tree 'link
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
(org-export-resolve-fuzzy-link link info) info)) info t)))))
|
(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 ()
|
(ert-deftest test-org-export/resolve-coderef ()
|
||||||
"Test `org-export-resolve-coderef' specifications."
|
"Test `org-export-resolve-coderef' specifications."
|
||||||
|
|
Loading…
Reference in a new issue