emacs-orgmode
[Top][All Lists]
Advanced

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

[O] PATCH: Extract HTML attributes from link if present


From: Jens Lechtenboerger
Subject: [O] PATCH: Extract HTML attributes from link if present
Date: Sat, 08 Dec 2018 17:12:08 +0100

Hi there,

for HTML export, attributes are added to links with what is called a
“HACK” in a comment in ox-html.el: Attribute :attr_html is read from
the parent, to be transferred to the first link.

That mechanism can used to assign attributes to the first link in
each paragraph/sentence.  For org-reveal, I would like to assign
computed classes to links in general (several per paragraph).  The
attached patch extends the current functionality to add attributes
of the link to those of the parent.

Could that please be included?

Best wishes
Jens

>From 3ac50ac3a3c8951d59a1d30b047ae0407731b789 Mon Sep 17 00:00:00 2001
From: Jens Lechtenboerger <address@hidden>
Date: Sat, 8 Dec 2018 16:44:06 +0100
Subject: [PATCH] ox-html.el: Export attributes specified with :attr_html for
 links

* lisp/ox-html.el (org-html-link): Export :attr_html from link
---
 lisp/ox-html.el | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 6a81be126..bbe38d8e2 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3045,19 +3045,25 @@ INFO is a plist holding contextual information.  See
                          "#"
                          (org-publish-resolve-external-link option path t))))))
           (t raw-path)))
-        ;; Extract attributes from parent's paragraph.  HACK: Only do
-        ;; this for the first link in parent (inner image link for
-        ;; inline images).  This is needed as long as attributes
-        ;; cannot be set on a per link basis.
         (attributes-plist
-         (let* ((parent (org-export-get-parent-element link))
-                (link (let ((container (org-export-get-parent link)))
-                        (if (and (eq (org-element-type container) 'link)
-                                 (org-html-inline-image-p link info))
-                            container
-                          link))))
-           (and (eq (org-element-map parent 'link 'identity info t) link)
-                (org-export-read-attribute :attr_html parent))))
+         (org-combine-plists
+          ;; Extract attributes from parent's paragraph.  HACK: Only do
+          ;; this for the first link in parent (inner image link for
+          ;; inline images).  This is needed as long as attributes
+          ;; cannot be set on a per link basis.
+          (let* ((parent (org-export-get-parent-element link))
+                 (link (let ((container (org-export-get-parent link)))
+                         (if (and (eq (org-element-type container) 'link)
+                                  (org-html-inline-image-p link info))
+                             container
+                           link))))
+            (and (eq (org-element-map parent 'link 'identity info t) link)
+                 (org-export-read-attribute :attr_html parent)))
+          ;; Also add attributes from link itself.  Currently, those need
+          ;; to be added programmatically before org-html-link is invoked,
+          ;; for example, by backends building upon HTML export, such as
+          ;; org-reveal.
+          (org-export-read-attribute :attr_html link)))
         (attributes
          (let ((attr (org-html--make-attribute-string attributes-plist)))
            (if (org-string-nw-p attr) (concat " " attr) ""))))
-- 
2.17.1


reply via email to

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