ox-odt: Links to headlines are more consistent with other back-ends

* lisp/ox-odt.el (org-odt-link): Fuzzy links to an headline with
  a description always use that description, even if the description
  is the same as the headline title.

Reported by Georg Lehner.
This commit is contained in:
Nicolas Goaziou 2013-06-25 09:05:46 +02:00
parent b4f90c687d
commit 41a0f2fa9e

View file

@ -2785,63 +2785,58 @@ INFO is a plist holding contextual information. See
;; Links pointing to a headline: Find destination and build ;; Links pointing to a headline: Find destination and build
;; appropriate referencing command. ;; appropriate referencing command.
((member type '("custom-id" "fuzzy" "id")) ((member type '("custom-id" "fuzzy" "id"))
(let* ((destination (if (string= type "fuzzy") (let ((destination (if (string= type "fuzzy")
(org-export-resolve-fuzzy-link link info) (org-export-resolve-fuzzy-link link info)
(org-export-resolve-id-link link info)))) (org-export-resolve-id-link link info))))
(or (case (org-element-type destination)
;; Case 1: Fuzzy link points nowhere. ;; Case 1: Fuzzy link points nowhere.
(when (null (org-element-type destination)) ('nil
(format "<text:span text:style-name=\"%s\">%s</text:span>" (format "<text:span text:style-name=\"%s\">%s</text:span>"
"Emphasis" (or desc (org-export-data "Emphasis"
(org-element-property (or desc
:raw-link link) info)))) (org-export-data (org-element-property :raw-link link)
;; Case 2: Fuzzy link points to an invisible target. Strip it. info))))
(when (eq (org-element-type destination) 'keyword) "") ;; Case 2: Fuzzy link points to a headline.
;; Case 3: LINK points to a headline. (headline
(when (eq (org-element-type destination) 'headline) ;; If there's a description, create a hyperlink.
;; Case 3.1: LINK has a custom description that is ;; Otherwise, try to provide a meaningful description.
;; different from headline's title. Create a hyperlink. (if (not desc) (org-odt-link--infer-description destination info)
(when (and desc (let* ((headline-no
(let ((link-desc (org-element-contents link))) (org-export-get-headline-number destination info))
(not (string= (org-element-interpret-data link-desc) (label
(org-element-property :raw-value (format "sec-%s"
destination))))) (mapconcat 'number-to-string headline-no "-"))))
(let* ((headline-no (org-export-get-headline-number (format
destination info)) "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
(label (format "sec-%s" (mapconcat 'number-to-string label desc))))
headline-no "-")))) ;; Case 3: Fuzzy link points to a target.
(format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>" (target
label desc)))) ;; If there's a description, create a hyperlink.
;; Case 4: LINK points to an Inline image, Math formula or a Table. ;; Otherwise, try to provide a meaningful description.
(let ((label-reference (ignore-errors (org-odt-format-label (if (not desc) (org-odt-link--infer-description destination info)
destination info 'reference))))
(when label-reference
(cond
;; Case 4.1: LINK has no description. Create a
;; cross-reference showing entity's sequence number.
((not desc) label-reference)
;; Case 4.2: LINK has description. Insert a hyperlink
;; with user-provided description.
(t (let* ((caption-from (case (org-element-type destination)
(link (org-export-get-parent-element
destination))
(t destination)))
;; Get label and caption.
(label (org-element-property :name caption-from)))
(format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
(org-export-solidify-link-text label) desc))))))
;; Case 5: Fuzzy link points to a TARGET.
(when (eq (org-element-type destination) 'target)
;; Case 5.1: LINK has description. Create a hyperlink.
(when desc
(let ((label (org-element-property :value destination))) (let ((label (org-element-property :value destination)))
(format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>" (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
(org-export-solidify-link-text label) desc)))) (org-export-solidify-link-text label)
;; LINK has no description. It points to either a HEADLINE or desc))))
;; an ELEMENT with a #+NAME: LABEL attached to it. LINK to ;; Case 4: Fuzzy link points to some element (e.g., an
;; DESTINATION, but make a best effort to provide ;; inline image, a math formula or a table).
;; a *meaningful* description. (otherwise
(org-odt-link--infer-description destination info)))) (let ((label-reference
(ignore-errors (org-odt-format-label
destination info 'reference))))
(cond ((not label-reference)
(org-odt-link--infer-description destination info))
;; LINK has no description. Create
;; a cross-reference showing entity's sequence
;; number.
((not desc) label-reference)
;; LINK has description. Insert a hyperlink with
;; user-provided description.
(t
(let ((label (org-element-property :name destination)))
(format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
(org-export-solidify-link-text label)
desc)))))))))
;; Coderef: replace link with the reference name or the ;; Coderef: replace link with the reference name or the
;; equivalent line number. ;; equivalent line number.
((string= type "coderef") ((string= type "coderef")