Quellcode durchsuchen

ox-html: Add html attributes to special blocks

* lisp/ox-html.el (org-html-special-block): enables #+attr_html and puts
  an id in when the special block is named.
John Kitchin vor 9 Jahren
Ursprung
Commit
d5b9c74430
1 geänderte Dateien mit 16 neuen und 14 gelöschten Zeilen
  1. 16 14
      lisp/ox-html.el

+ 16 - 14
lisp/ox-html.el

@@ -3208,22 +3208,24 @@ contextual information."
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
   (let* ((block-type (org-element-property :type special-block))
-	 (contents (or contents ""))
-	 (html5-fancy (and (org-html--html5-fancy-p info)
-			   (member block-type org-html-html5-elements)))
-	 (attributes (org-export-read-attribute :attr_html special-block)))
+         (html5-fancy (and (org-html--html5-fancy-p info)
+                           (member block-type org-html-html5-elements)))
+         (attributes (org-export-read-attribute :attr_html special-block)))
     (unless html5-fancy
       (let ((class (plist-get attributes :class)))
-	(setq attributes (plist-put attributes :class
-				    (if class (concat class " " block-type)
-				      block-type)))))
-    (setq attributes (org-html--make-attribute-string attributes))
-    (when (not (equal attributes ""))
-      (setq attributes (concat " " attributes)))
-    (if html5-fancy
-	(format "<%s%s>\n%s</%s>" block-type attributes
-		contents block-type)
-      (format "<div%s>\n%s\n</div>" attributes contents))))
+        (setq attributes (plist-put attributes :class
+                                    (if class (concat class " " block-type)
+                                      block-type)))))
+    (let* ((contents (or contents ""))
+	   (name (org-element-property :name special-block))
+	   (a (org-html--make-attribute-string
+	       (if (or (not name) (plist-member attributes :id))
+		   attributes
+		 (plist-put attributes :id name))))
+	   (str (if (org-string-nw-p a) (concat " " a) "")))
+      (if html5-fancy
+	  (format "<%s%s>\n%s</%s>" block-type str contents block-type)
+	(format "<div%s>\n%s\n</div>" str contents)))))
 
 ;;;; Src Block