emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* PATCH: Extract HTML attributes from link if present
@ 2018-12-08 16:12 Jens Lechtenboerger
  2018-12-08 20:22 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Jens Lechtenboerger @ 2018-12-08 16:12 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 572 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html.el-Export-attributes-specified-with-attr_htm.patch --]
[-- Type: text/x-diff, Size: 2403 bytes --]

From 3ac50ac3a3c8951d59a1d30b047ae0407731b789 Mon Sep 17 00:00:00 2001
From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: PATCH: Extract HTML attributes from link if present
  2018-12-08 16:12 PATCH: Extract HTML attributes from link if present Jens Lechtenboerger
@ 2018-12-08 20:22 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2018-12-08 20:22 UTC (permalink / raw)
  To: Jens Lechtenboerger; +Cc: emacs-orgmode

Hello,

Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:

> 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.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-08 20:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-08 16:12 PATCH: Extract HTML attributes from link if present Jens Lechtenboerger
2018-12-08 20:22 ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).