Browse Source

ox: Fix fuzzy link resolution before first headline

* lisp/ox.el (org-export-resolve-fuzzy-link): Fix link resolution when
  link lives before the first headline.
* testing/lisp/test-ox.el: Add test.
Nicolas Goaziou 12 years ago
parent
commit
60899b1a2f
2 changed files with 10 additions and 2 deletions
  1. 2 1
      lisp/ox.el
  2. 8 1
      testing/lisp/test-ox.el

+ 2 - 1
lisp/ox.el

@@ -4050,7 +4050,8 @@ significant."
 	     (let ((foundp (funcall find-headline path parent)))
 	       (when foundp (throw 'exit foundp))))
 	   (let ((parent-hl (org-export-get-parent-headline link)))
-	     (cons parent-hl (org-export-get-genealogy parent-hl))))
+	     (if (not parent-hl) (list (plist-get info :parse-tree))
+	       (cons parent-hl (org-export-get-genealogy parent-hl)))))
 	  ;; No destination found: return nil.
 	  (and (not match-title-p) (puthash path nil link-cache))))))))
 

+ 8 - 1
testing/lisp/test-ox.el

@@ -1642,7 +1642,14 @@ Another text. (ref:text)
   (should-not
    (org-test-with-parsed-data "[[target]]"
      (org-export-resolve-fuzzy-link
-      (org-element-map tree 'link 'identity info t) info))))
+      (org-element-map tree 'link 'identity info t) info)))
+  ;; Match fuzzy link even when before first headline.
+  (should
+   (eq 'headline
+       (org-test-with-parsed-data "[[hl]]\n* hl"
+	 (org-element-type
+	  (org-export-resolve-fuzzy-link
+	   (org-element-map tree 'link 'identity info t) info))))))
 
 (ert-deftest test-org-export/resolve-id-link ()
   "Test `org-export-resolve-id-link' specifications."