浏览代码

ox-html: Handle external fuzzy links

* lisp/ox-html.el (org-html-link): Resolve external links with search
  options like [[file.org::#custom-id]] or
  [[file.org::*headline-search]].

In particular, this allows to resolve completely links produced by
index generation during publishing.
Nicolas Goaziou 12 年之前
父节点
当前提交
3e95e859cd
共有 1 个文件被更改,包括 31 次插入12 次删除
  1. 31 12
      lisp/ox-html.el

+ 31 - 12
lisp/ox-html.el

@@ -2164,18 +2164,37 @@ INFO is a plist holding contextual information.  See
 	 (raw-path (org-element-property :path link))
 	 ;; Ensure DESC really exists, or set it to nil.
 	 (desc (and (not (string= desc "")) desc))
-	 (path (cond
-		((member type '("http" "https" "ftp" "mailto"))
-		 (concat type ":" raw-path))
-		((string= type "file")
-		 ;; Treat links to ".org" files as ".html", if needed.
-		 (setq raw-path (funcall --link-org-files-as-html-maybe
-					 raw-path info))
-		 ;; If file path is absolute, prepend it with protocol
-		 ;; component - "file://".
-		 (if (not (file-name-absolute-p raw-path)) raw-path
-		   (concat "file://" (expand-file-name raw-path))))
-		(t raw-path)))
+	 (path
+	  (cond
+	   ((member type '("http" "https" "ftp" "mailto"))
+	    (concat type ":" raw-path))
+	   ((string= type "file")
+	    ;; Treat links to ".org" files as ".html", if needed.
+	    (setq raw-path
+		  (funcall --link-org-files-as-html-maybe raw-path info))
+	    ;; If file path is absolute, prepend it with protocol
+	    ;; component - "file://".
+	    (when (file-name-absolute-p raw-path)
+	      (setq raw-path
+		    (concat "file://" (expand-file-name raw-path))))
+	    ;; Add search option, if any.  A search option can be
+	    ;; relative to a custom-id or a headline title.  Any other
+	    ;; option is ignored.
+	    (let ((option (org-element-property :search-option link)))
+	      (cond ((not option) raw-path)
+		    ((eq (aref option 0) ?#) (concat raw-path option))
+		    ;; External fuzzy link: try to resolve it if path
+		    ;; belongs to current project, if any.
+		    ((eq (aref option 0) ?*)
+		     (concat
+		      raw-path
+		      (let ((numbers
+			     (org-publish-resolve-external-fuzzy-link
+			      (org-element-property :path link) option)))
+			(and numbers (concat "#sec-"
+					     (mapconcat 'number-to-string
+							numbers "-")))))))))
+	   (t raw-path)))
 	 attributes protocol)
     ;; Extract attributes from parent's paragraph.
     (and (setq attributes