Browse Source

ox-html: Fix linking to deep level headlines

* lisp/ox-html.el (org-html-headline): Make sure even listified
  headlines have proper anchors so internal links can refer to them.
  Small refactoring.

Thanks to Bruce Gilstrap for reporting it.
http://permalink.gmane.org/gmane.emacs.orgmode/90835
Nicolas Goaziou 10 years ago
parent
commit
873fe49811
1 changed files with 64 additions and 77 deletions
  1. 64 77
      lisp/ox-html.el

+ 64 - 77
lisp/ox-html.el

@@ -2275,83 +2275,70 @@ holding contextual information."
   "Transcode a HEADLINE element from Org to HTML.
 CONTENTS holds the contents of the headline.  INFO is a plist
 holding contextual information."
-  ;; Empty contents?
-  (setq contents (or contents ""))
-  (let* ((numberedp (org-export-numbered-headline-p headline info))
-	 (level (org-export-get-relative-level headline info))
-	 (text (org-export-data (org-element-property :title headline) info))
-	 (todo (and (plist-get info :with-todo-keywords)
-		    (let ((todo (org-element-property :todo-keyword headline)))
-		      (and todo (org-export-data todo info)))))
-	 (todo-type (and todo (org-element-property :todo-type headline)))
-	 (tags (and (plist-get info :with-tags)
-		    (org-export-get-tags headline info)))
-	 (priority (and (plist-get info :with-priority)
-			(org-element-property :priority headline)))
-	 (section-number (and (org-export-numbered-headline-p headline info)
-			      (mapconcat 'number-to-string
-					 (org-export-get-headline-number
-					  headline info) ".")))
-	 ;; Create the headline text.
-	 (full-text (org-html-format-headline--wrap headline info)))
-    (cond
-     ;; Case 1: This is a footnote section: ignore it.
-     ((org-element-property :footnote-section-p headline) nil)
-     ;; Case 2. This is a deep sub-tree: export it as a list item.
-     ;;         Also export as items headlines for which no section
-     ;;         format has been found.
-     ((org-export-low-level-p headline info)
-      ;; Build the real contents of the sub-tree.
-      (let* ((type (if numberedp 'ordered 'unordered))
-	     (itemized-body (org-html-format-list-item
-			     contents type nil info nil full-text)))
-	(concat
-	 (and (org-export-first-sibling-p headline info)
-	      (org-html-begin-plain-list type))
-	 itemized-body
-	 (and (org-export-last-sibling-p headline info)
-	      (org-html-end-plain-list type)))))
-     ;; Case 3. Standard headline.  Export it as a section.
-     (t
-      (let* ((section-number (mapconcat 'number-to-string
-					(org-export-get-headline-number
-					 headline info) "-"))
-	     (ids (remove 'nil
-			  (list (org-element-property :CUSTOM_ID headline)
-				(concat "sec-" section-number)
-				(org-element-property :ID headline))))
-	     (preferred-id (car ids))
-	     (extra-ids (cdr ids))
-	     (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
-	     (level1 (+ level (1- org-html-toplevel-hlevel)))
-	     (first-content (car (org-element-contents headline))))
-	(format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
-		(org-html--container headline info)
-		(format "outline-container-%s"
-			(or (org-element-property :CUSTOM_ID headline)
-			    (concat "sec-" section-number)))
-		(concat (format "outline-%d" level1) (and extra-class " ")
-			extra-class)
-		(format "\n<h%d id=\"%s\">%s%s</h%d>\n"
-			level1
-			preferred-id
-			(mapconcat
-			 (lambda (x)
-			   (let ((id (org-export-solidify-link-text
-				      (if (org-uuidgen-p x) (concat "ID-" x)
-					x))))
-			     (org-html--anchor id)))
-			 extra-ids "")
-			full-text
-			level1)
-		;; When there is no section, pretend there is an empty
-		;; one to get the correct <div class="outline- ...>
-		;; which is needed by `org-info.js'.
-		(if (not (eq (org-element-type first-content) 'section))
-		    (concat (org-html-section first-content "" info)
-			    contents)
-		  contents)
-		(org-html--container headline info)))))))
+  (unless (org-element-property :footnote-section-p headline)
+    (let* ((contents (or contents ""))
+	   (numberedp (org-export-numbered-headline-p headline info))
+	   (level (org-export-get-relative-level headline info))
+	   (text (org-export-data (org-element-property :title headline) info))
+	   (todo (and (plist-get info :with-todo-keywords)
+		      (let ((todo (org-element-property :todo-keyword headline)))
+			(and todo (org-export-data todo info)))))
+	   (todo-type (and todo (org-element-property :todo-type headline)))
+	   (tags (and (plist-get info :with-tags)
+		      (org-export-get-tags headline info)))
+	   (priority (and (plist-get info :with-priority)
+			  (org-element-property :priority headline)))
+	   (section-number (mapconcat #'number-to-string
+				      (org-export-get-headline-number
+				       headline info) "-"))
+	   (ids (delq 'nil
+		      (list (org-element-property :CUSTOM_ID headline)
+			    (concat "sec-" section-number)
+			    (org-element-property :ID headline))))
+	   (preferred-id (car ids))
+	   (extra-ids (mapconcat
+		       (lambda (id)
+			 (org-html--anchor
+			  (org-export-solidify-link-text
+			   (if (org-uuidgen-p id) (concat "ID-" id) id))))
+		       (cdr ids) ""))
+	   ;; Create the headline text.
+	   (full-text (org-html-format-headline--wrap headline info)))
+      (if (org-export-low-level-p headline info)
+	  ;; This is a deep sub-tree: export it as a list item.
+	  (let* ((type (if numberedp 'ordered 'unordered))
+		 (itemized-body
+		  (org-html-format-list-item
+		   contents type nil info nil
+		   (concat (org-html--anchor preferred-id) extra-ids
+			   full-text))))
+	    (concat
+	     (and (org-export-first-sibling-p headline info)
+		  (org-html-begin-plain-list type))
+	     itemized-body
+	     (and (org-export-last-sibling-p headline info)
+		  (org-html-end-plain-list type))))
+	;; Standard headline.  Export it as a section.
+	(let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
+	      (level1 (+ level (1- org-html-toplevel-hlevel)))
+	      (first-content (car (org-element-contents headline))))
+	  (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
+		  (org-html--container headline info)
+		  (format "outline-container-%s"
+			  (or (org-element-property :CUSTOM_ID headline)
+			      (concat "sec-" section-number)))
+		  (concat (format "outline-%d" level1) (and extra-class " ")
+			  extra-class)
+		  (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
+			  level1 preferred-id extra-ids full-text level1)
+		  ;; When there is no section, pretend there is an
+		  ;; empty one to get the correct <div class="outline-
+		  ;; ...> which is needed by `org-info.js'.
+		  (if (not (eq (org-element-type first-content) 'section))
+		      (concat (org-html-section first-content "" info)
+			      contents)
+		    contents)
+		  (org-html--container headline info)))))))
 
 (defun org-html--container (headline info)
   (or (org-element-property :HTML_CONTAINER headline)