Browse Source

ox-html: Add id attribute to example-block on html export

* lisp/ox-html.el (org-html-example-block): Add "id" attribute according
  to name.

This allows you to hyperlink to the block.
John Kitchin 9 years ago
parent
commit
2ce1fc2c0d
1 changed files with 11 additions and 4 deletions
  1. 11 4
      lisp/ox-html.el

+ 11 - 4
lisp/ox-html.el

@@ -2374,10 +2374,17 @@ contextual information."
   "Transcode a EXAMPLE-BLOCK element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
-  (if (org-export-read-attribute :attr_html example-block :textarea)
-      (org-html--textarea-block example-block)
-    (format "<pre class=\"example\">\n%s</pre>"
-	    (org-html-format-code example-block info))))
+  (let ((attributes (org-export-read-attribute :attr_html example-block)))
+    (if (plist-get attributes :textarea)
+	(org-html--textarea-block example-block)
+      (format "<pre class=\"example\"%s>\n%s</pre>"
+	      (let* ((name (org-element-property :name example-block))
+		     (a (org-html--make-attribute-string
+			 (if (or (not name) (plist-member attributes :id))
+			     attributes
+			   (plist-put attributes :id name)))))
+		(if (org-string-nw-p a) (concat " " a) ""))
+	      (org-html-format-code example-block info)))))
 
 ;;;; Export Snippet