1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-30 08:08:26 +00:00

org-odt.el: Render links to outline headings as section nos

* lisp/org-lparse.el (org-do-lparse): Make effective setting
of `org-export-headline-levels' available to the ODT exporter.
Also remove some stale comments.

* lisp/org-odt.el (org-odt-format-link): Add support for
generating cross-references to chapter numbers.
(org-odt-format-org-link): Resolve links to outline headings
as section numbers.  This special case resolution kicks in
only if the Org link has no description and the target outline
is not listified i.e., it is at a level within
`org-export-headline-levels'.

Fix for the following request:
http://lists.gnu.org/archive/html/emacs-orgmode/2012-02/msg01035.html

The above change is in conformity with the way links to
headlines will be treated in new ODT exporter that will be
built on top of Nicolas' org-element/org-export
infrastructure.
This commit is contained in:
Jambunathan K 2012-03-20 13:32:23 +05:30
parent c983bc2400
commit 4120d6fcf7
2 changed files with 25 additions and 44 deletions

View File

@ -809,6 +809,8 @@ version."
(setq umax-toc (if (integerp org-export-with-toc)
(min org-export-with-toc umax)
umax))
(setq org-lparse-opt-plist
(plist-put org-lparse-opt-plist :headline-levels umax))
(when (and org-export-with-toc (not body-only))
(setq lines (org-lparse-prepare-toc
@ -845,48 +847,6 @@ version."
(org-lparse-end-environment 'fixedwidth))
(throw 'nextline nil))
;; Notes: The baseline version of org-html.el (git commit
;; 3d802e), while encountering a *line-long* protected text,
;; does one of the following two things based on the state
;; of the export buffer.
;; 1. If a paragraph element has just been opened and
;; contains only whitespace as content, insert the
;; protected text as part of the previous paragraph.
;; 2. If the paragraph element has already been opened and
;; contains some valid content insert the protected text
;; as part of the current paragraph.
;; I think --->
;; Scenario 1 mentioned above kicks in when a block of
;; protected text has to be inserted en bloc. For example,
;; this happens, when inserting an source or example block
;; or preformatted content enclosed in #+backend,
;; #+begin_backend ... #+end_backend)
;; Scenario 2 mentioned above kicks in when the protected
;; text is part of a running sentence. For example this
;; happens in the case of an *multiline* LaTeX equation that
;; needs to be inserted verbatim.
;; org-html.el in the master branch seems to do some
;; jugglery by moving paragraphs around. Inorder to make
;; these changes backend-agnostic introduce a new text
;; property org-native-text and impose the added semantics
;; that these protected blocks appear outside of a
;; conventional paragraph element.
;;
;; Extra Note: Check whether org-example and org-native-text
;; are entirely equivalent.
;; Fixes bug reported by Christian Moe concerning verbatim
;; LaTeX fragments.
;; on git commit 533ba3f90250a1f25f494c390d639ea6274f235c
;; http://repo.or.cz/w/org-mode/org-jambu.git/shortlog/refs/heads/staging
;; See http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01379.html
;; Native Text
(when (and (get-text-property 0 'org-native-text line)
;; Make sure it is the entire line that is protected

View File

@ -1253,10 +1253,13 @@ styles congruent with the ODF-1.2 specification."
(defun org-odt-format-link (desc href &optional attr)
(cond
((and (= (string-to-char href) ?#) (not org-odt-suppress-xref))
(setq href (concat org-export-odt-bookmark-prefix (substring href 1)))
(setq href (substring href 1))
(let ((xref-format "text"))
(when (numberp desc)
(setq desc (format "%d" desc) xref-format "number"))
(when (listp desc)
(setq desc (mapconcat 'identity desc ".") xref-format "chapter"))
(setq href (concat org-export-odt-bookmark-prefix href))
(org-odt-format-tags
'("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:bookmark-ref>")
@ -1623,7 +1626,8 @@ ATTR is a string of other attributes of the a element."
(not fragment)))
(type (if (equal type-1 "id") "file" type-1))
(filename path)
(thefile path))
(thefile path)
sec-frag sec-nos)
(cond
;; check for inlined images
((and (member type '("file"))
@ -1639,6 +1643,7 @@ ATTR is a string of other attributes of the a element."
(org-odt-is-formula-link-p filename)
(or (not descp)))
(org-odt-format-inline-formula thefile))
;; code references
((string= type "coderef")
(let* ((ref fragment)
(lineno-or-ref (cdr (assoc ref org-export-code-refs)))
@ -1661,6 +1666,22 @@ ATTR is a string of other attributes of the a element."
(or desc "%s"))
lineno-or-ref))
(org-odt-format-link (org-xml-format-desc desc) href)))))
;; links to headlines
((and (string= type "")
(or (not thefile) (string= thefile ""))
(setq sec-frag fragment)
(org-find-text-property-in-string 'org-no-description fragment)
(or (string-match "\\`sec\\(\\(-[0-9]+\\)+\\)" sec-frag)
(and (setq sec-frag
(loop for alias in org-export-target-aliases do
(when (member fragment (cdr alias))
(return (car alias)))))
(string-match "\\`sec\\(\\(-[0-9]+\\)+\\)" sec-frag)))
(setq sec-nos (org-split-string (match-string 1 sec-frag) "-"))
(<= (length sec-nos) (plist-get org-lparse-opt-plist
:headline-levels)))
(let ((org-odt-suppress-xref nil))
(org-odt-format-link sec-nos (concat "#" sec-frag) attr)))
(t
(when (string= type "file")
(setq thefile