emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH 1/3] add id attribute to example-block on html export.


From: John Kitchin
Subject: [O] [PATCH 1/3] add id attribute to example-block on html export.
Date: Mon, 28 Mar 2016 15:06:50 -0400

This allows you to hyperlink to the block.
---
 lisp/ox-html.el | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index d07cdcc..92de209 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2370,14 +2370,23 @@ contextual information."
 
 ;;;; Example Block
 
-(defun org-html-example-block (example-block _contents info)
+(defun org-html-example-block (example-block contents info)
   "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)))
+      (when (org-element-property :name example-block)
+       (setq attributes (plist-put
+                         attributes :id
+                         (org-element-property :name example-block))))
+      (setq attributes (org-html--make-attribute-string attributes))
+      (when (not (equal attributes ""))
+       (setq attributes (concat " " attributes)))
+      (format "<pre class=\"example\"%s>\n%s</pre>"
+             attributes
+             (org-html-format-code example-block info)))))
 
 ;;;; Export Snippet
 
-- 
2.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]