ソースを参照

Export: Make id: links work after export.

id: links to entries in other files will now work after export to
HTML, provided that the published target file is on the same relative
path.
Carsten Dominik 16 年 前
コミット
32ba462be1
3 ファイル変更61 行追加26 行削除
  1. 29 23
      doc/org.texi
  2. 8 0
      lisp/ChangeLog
  3. 24 3
      lisp/org-exp.el

+ 29 - 23
doc/org.texi

@@ -2682,23 +2682,28 @@ insert it into an Org file, and to follow the link.
 @item C-c l
 Store a link to the current location.  This is a @emph{global} command which
 can be used in any buffer to create a link.  The link will be stored for
-later insertion into an Org buffer (see below).  For Org files, if there is a
-@samp{<<target>>} at the cursor, the link points to the target.  Otherwise it
-points to the current headline, either by text, or, if @file{org-id.el} is
-loaded, by ID property.  For VM, Rmail, Wanderlust, MH-E, Gnus and BBDB
-buffers, the link will indicate the current article/entry.  For W3 and W3M
-buffers, the link goes to the current URL.  For IRC links, if you set the
-variable @code{org-irc-link-to-logs} to non-nil then @kbd{C-c l} will store a
+later insertion into an Org buffer (see below).
+
+For Org files, if there is a @samp{<<target>>} at the cursor, the link points
+to the target.  Otherwise it points to the current headline, either by text
+(unsafe), or, if @file{org-id.el} is loaded and @code{org-link-to-org-use-id}
+is set, by ID property.
+
+For VM, Rmail, Wanderlust, MH-E, Gnus and BBDB buffers, the link will
+indicate the current article/entry.  For W3 and W3M buffers, the link goes to
+the current URL.  For IRC links, if you set the variable
+@code{org-irc-link-to-logs} to non-nil then @kbd{C-c l} will store a
 @samp{file:/} style link to the relevant point in the logs for the current
 conversation. Otherwise an @samp{irc:/} style link to the user/channel/server
-under the point will be stored.  For any other files, the link will point to
-the file, with a search string (@pxref{Search options}) pointing to the
-contents of the current line.  If there is an active region, the selected
-words will form the basis of the search string.  If the automatically created
-link is not working correctly or accurately enough, you can write custom
-functions to select the search string and to do the search for particular
-file types - see @ref{Custom searches}.  The key binding @kbd{C-c l} is only
-a suggestion - see @ref{Installation}.
+under the point will be stored. 
+
+For any other files, the link will point to the file, with a search string
+(@pxref{Search options}) pointing to the contents of the current line.  If
+there is an active region, the selected words will form the basis of the
+search string.  If the automatically created link is not working correctly or
+accurately enough, you can write custom functions to select the search string
+and to do the search for particular file types - see @ref{Custom searches}.
+The key binding @kbd{C-c l} is only a suggestion - see @ref{Installation}.
 @c
 @kindex C-c C-l
 @cindex link completion
@@ -7884,14 +7889,15 @@ All lines between these markers are exported literally
 @cindex links, in HTML export
 @cindex internal links, in HTML export
 @cindex external links, in HTML export
-Internal links (@pxref{Internal links}) will continue to work in HTML.
-Automatic links created by radio targets (@pxref{Radio targets}) will also
-work in the HTML file.  Links to external files will still work if the HTML
-file is in the same directory as the Org file.  Links to other @file{.org}
-files will be translated into HTML links under the assumption that an HTML
-version also exists of the linked file.  For information related to linking
-files while publishing them to a publishing directory see @ref{Publishing
-links}.
+Internal links (@pxref{Internal links}) will continue to work in HTML.  This
+does include automatic links created by radio targets (@pxref{Radio
+targets}).  Links to external files will still work if the target file is on
+the same @i{relative} path as the published Org file.  Links to other
+@file{.org} files will be translated into HTML links under the assumption
+that an HTML version also exists of the linked file, at the same relative
+path.  @samp{id:} links can then be used to jump to specific entries across
+files.  For information related to linking files while publishing them to a
+publishing directory see @ref{Publishing links}.
 
 If you want to specify attributes for links, you can do so using a special
 @code{#+ATTR_HTML} line to define attributes that wil be added to the

+ 8 - 0
lisp/ChangeLog

@@ -1,5 +1,13 @@
 2009-01-08  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org.el (org-format-latex-options): Add new matcher for single
+	letters between dollars.
+
+	* org-exp.el (org-export-define-heading-targets): Record ID's also
+	as alternative targets.
+	(org-export-as-html): Interpret "id:" links to other files by
+	preserving the relative path.
+
 	* org-jsinfo.el (org-infojs-handle-options): Catch the case if v
 	is nil.
 

+ 24 - 3
lisp/org-exp.el

@@ -1645,16 +1645,24 @@ The new targets are added to TARGET-ALIST, which is also returned."
   (org-init-section-numbers)
   (let ((re (concat "^" org-outline-regexp
 		    "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
-	level target)
+	level target last-section-target a)
     (while (re-search-forward re nil t)
       (if (match-end 1)
-	  (push (cons (org-match-string-no-properties 1)
-		      target) target-alist)
+	  (progn
+	    (push (cons (org-match-string-no-properties 1)
+			target) target-alist)
+	    (setq a (or (assoc last-section-target org-export-target-aliases)
+			(progn
+			  (push (list last-section-target)
+				org-export-target-aliases)
+			  (car org-export-target-aliases))))
+	    (push (caar target-alist) (cdr a)))
 	(setq level (org-reduced-level
 		     (save-excursion (goto-char (point-at-bol))
 				     (org-outline-level))))
 	(setq target (org-solidify-link-text
 		      (format "sec-%s" (org-section-number level))))
+	(setq last-section-target target)
 	(push (cons target target) target-alist)
 	(add-text-properties
 	 (point-at-bol) (point-at-eol)
@@ -3264,6 +3272,7 @@ PUB-DIR is set, use this as the publishing directory."
 	 rpl path attr desc descp desc1 desc2 link
 	 snumber fnc item-tag
 	 footnotes footref-seen
+	 id-file
 	 )
 
     (let ((inhibit-read-only t))
@@ -3560,6 +3569,18 @@ lang=\"%s\" xml:lang=\"%s\">
 		     "\"" attr ">"
 		     (org-export-html-format-desc desc)
 		     "</a>")))
+	     ((and (equal type "id")
+		   (setq id-file (org-id-find-id-file path)))
+	      ;; This is an id: link to another file (if it was the same file,
+	      ;; it would have become an internal link...)
+	      (setq id-file (file-relative-name
+			     id-file (file-name-directory org-current-export-file)))
+	      (setq id-file (concat (file-name-sans-extension id-file)
+				    "." html-extension))
+	      (setq rpl (concat "<a href=\"" id-file "#" path "\""
+				attr ">"
+				(org-export-html-format-desc desc)
+				"</a>")))
 	     ((member type '("http" "https"))
 	      ;; standard URL, just check if we need to inline an image
 	      (if (and (or (eq t org-export-html-inline-images)