>From b6debf17314973b1feb5e7da0d7cc788d4920f50 Mon Sep 17 00:00:00 2001 From: Rasmus
Date: Sun, 21 Sep 2014 16:17:55 +0200 Subject: [PATCH] ox: Support unnumbered headlines via property. * ox.el (org-export--collect-headline-numbering): Return nil if unnumbered headline. (org-export-get-headline-id): New defun that returns a unique ID to a headline. (org-export-numbered-headline-p): Also tests for unnumbered headline. * ox-odt.el (org-odt-headline, org-odt-link, org-odt-link--infer-description) ox-md.el (org-md-headline, org-md-link), ox-latex.el (org-latex-headline, org.latex-link), ox-html.el (org-html-headline, org-html-link), ox-ascii.el (org-ascii-link): Support ununbered headlines. --- lisp/org.el | 2 +- lisp/ox-ascii.el | 7 +++++-- lisp/ox-html.el | 22 ++++----------------- lisp/ox-latex.el | 20 +++---------------- lisp/ox-md.el | 25 ++++++++++++------------ lisp/ox-odt.el | 25 ++++++++++++------------ lisp/ox.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++--------- 7 files changed, 88 insertions(+), 72 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 4ffe1e8..7565b14 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -15337,7 +15337,7 @@ but in some other way.") "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY" "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE" "EXPORT_OPTIONS" "EXPORT_TEXT" "EXPORT_FILE_NAME" - "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE" + "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE" "UNNUMBERED" "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE" "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS") "Some properties that are used by Org-mode for various purposes. diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el index 6f2b43a..5e8d479 100644 --- a/lisp/ox-ascii.el +++ b/lisp/ox-ascii.el @@ -1530,9 +1530,12 @@ INFO is a plist holding contextual information." (let ((number (org-export-get-ordinal destination info nil 'org-ascii--has-caption-p))) - (when number + (if number (if (atom number) (number-to-string number) - (mapconcat 'number-to-string number ".")))))))) + (mapconcat 'number-to-string number ".")) + ;; unnumbered headline + (when (eq 'headline (org-element-type destination)) + (format "[%s]" (org-export-data (org-element-property :title destination) info))))))))) (t (if (not (org-string-nw-p desc)) (format "[%s]" raw-link) (concat (format "[%s]" desc) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 1d424cc..2dfcd21 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2321,7 +2321,7 @@ holding contextual information." (unless (org-element-property :footnote-section-p headline) (let* ((numberedp (org-export-numbered-headline-p headline info)) (numbers (org-export-get-headline-number headline info)) - (section-number (mapconcat #'number-to-string numbers "-")) + (section-number (and numbers (mapconcat #'number-to-string numbers "-"))) (level (+ (org-export-get-relative-level headline info) (1- (plist-get info :html-toplevel-hlevel)))) (todo (and (plist-get info :with-todo-keywords) @@ -2338,9 +2338,9 @@ holding contextual information." (contents (or contents "")) (ids (delq nil (list (org-element-property :CUSTOM_ID headline) - (concat "sec-" section-number) + (and section-number (concat "sec-" section-number)) (org-element-property :ID headline)))) - (preferred-id (car ids)) + (preferred-id (org-export-get-headline-id headline info)) (extra-ids (mapconcat (lambda (id) (org-html--anchor @@ -2807,21 +2807,7 @@ INFO is a plist holding contextual information. See (org-element-property :raw-link link) info)))) ;; Link points to a headline. (headline - (let ((href - ;; What href to use? - (cond - ;; Case 1: Headline is linked via it's CUSTOM_ID - ;; property. Use CUSTOM_ID. - ((string= type "custom-id") - (org-element-property :CUSTOM_ID destination)) - ;; Case 2: Headline is linked via it's ID property - ;; or through other means. Use the default href. - ((member type '("id" "fuzzy")) - (format "sec-%s" - (mapconcat 'number-to-string - (org-export-get-headline-number - destination info) "-"))) - (t (error "Shouldn't reach here")))) + (let ((href (org-export-get-headline-id destination info)) ;; What description to use? (desc ;; Case 1: Headline is numbered and LINK has no diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 218c69f..8e08213 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1476,15 +1476,7 @@ holding contextual information." todo todo-type priority text tags info)) ;; Associate \label to the headline for internal links. (headline-label - (let ((custom-label - (and (plist-get info :latex-custom-id-labels) - (org-element-property :CUSTOM_ID headline)))) - (if custom-label (format "\\label{%s}\n" custom-label) - (format "\\label{sec-%s}\n" - (mapconcat - #'number-to-string - (org-export-get-headline-number headline info) - "-"))))) + (format "\\label{%s}\n" (org-export-get-headline-id headline info))) (pre-blanks (make-string (org-element-property :pre-blank headline) 10))) (if (or (not section-fmt) (org-export-low-level-p headline info)) @@ -1974,14 +1966,8 @@ INFO is a plist holding contextual information. See (let* ((custom-label (and (plist-get info :latex-custom-id-labels) (org-element-property :CUSTOM_ID destination))) - (label - (or - custom-label - (format "sec-%s" - (mapconcat - #'number-to-string - (org-export-get-headline-number destination info) - "-"))))) + (label (or custom-label + (org-export-get-headline-id destination info)))) (if (and (not desc) (org-export-numbered-headline-p destination info)) (format "\\ref{%s}" label) diff --git a/lisp/ox-md.el b/lisp/ox-md.el index 695fb61..9e7984d 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -202,12 +202,7 @@ a communication channel." (and char (format "[#%c] " char))))) (anchor (when (plist-get info :with-toc) - (org-html--anchor - (or (org-element-property :CUSTOM_ID headline) - (concat "sec-" - (mapconcat 'number-to-string - (org-export-get-headline-number - headline info) "-"))) + (org-html--anchor (org-export-get-headline-id headline info) nil nil info))) ;; Headline text without tags. (heading (concat todo priority title)) @@ -330,10 +325,12 @@ a communication channel." (and contents (concat contents " ")) (format "(%s)" (format (org-export-translate "See section %s" :html info) - (mapconcat 'number-to-string - (org-export-get-headline-number - destination info) - "."))))))) + (if (org-export-numbered-headline-p destination info) + (mapconcat 'number-to-string + (org-export-get-headline-number + destination info) + ".") + (org-export-get-alt-title headline info)))))))) ((org-export-inline-image-p link org-html-inline-image-rules) (let ((path (let ((raw-path (org-element-property :path link))) (if (not (file-name-absolute-p raw-path)) raw-path @@ -354,9 +351,13 @@ a communication channel." (if (org-string-nw-p contents) contents (when destination (let ((number (org-export-get-ordinal destination info))) - (when number + (if number (if (atom number) (number-to-string number) - (mapconcat 'number-to-string number ".")))))))) + (mapconcat 'number-to-string number ".")) + ;; unnumbered headline + (and (eq 'headline (org-element-type destination)) + ;; BUG: shouldn't headlines have a form like [ref](name) in md + (org-export-data (org-export-get-alt-title destination info) info)))))))) ;; Link type is handled by a special function. ((let ((protocol (nth 2 (assoc type org-link-protocols)))) (and (functionp protocol) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 96a3b83..372d157 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -1122,7 +1122,7 @@ See `org-odt--build-date-styles' for implementation details." (setq text (concat ;; Section number. - (when section-number (concat section-number ". ")) + (and section-number (concat section-number ". ")) ;; Todo. (when todo (let ((style (if (member todo org-done-keywords) @@ -1816,9 +1816,7 @@ holding contextual information." ;; Get level relative to current parsed data. (level (org-export-get-relative-level headline info)) ;; Get canonical label for the headline. - (id (concat "sec-" (mapconcat 'number-to-string - (org-export-get-headline-number - headline info) "-"))) + (id (org-export-get-headline-id headline info)) ;; Get user-specified labels for the headline. (extra-ids (list (org-element-property :CUSTOM_ID headline) (org-element-property :ID headline))) @@ -1870,9 +1868,13 @@ holding contextual information." (t (concat (format - "\n