emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* "org-link-set-parameters" get parent properties
@ 2019-01-31 10:36 Tarjei Bærland
  2019-01-31 14:12 ` John Kitchin
  0 siblings, 1 reply; 2+ messages in thread
From: Tarjei Bærland @ 2019-01-31 10:36 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi!

I have a custom function for exporting image links in org-mode (I have my
html exported to the parent folder of my .org files, and I just want to
keep one copy of the image files).

How can I get the "attr_html" of the link for a custom
org-set-link-parameters function? As far as I can tell, the :export wants a
function taking (path desc backend), and I do not know how to extract the
parent of the link from this.

Thanks in advance!

Regards,
Tarjei

[-- Attachment #2: Type: text/html, Size: 612 bytes --]

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

* Re: "org-link-set-parameters" get parent properties
  2019-01-31 10:36 "org-link-set-parameters" get parent properties Tarjei Bærland
@ 2019-01-31 14:12 ` John Kitchin
  0 siblings, 0 replies; 2+ messages in thread
From: John Kitchin @ 2019-01-31 14:12 UTC (permalink / raw)
  To: Tarjei Bærland; +Cc: org-mode-email

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

One way is through a filter. In the filter function you get an info
argument that contains the information you want. I hacked this together and
it does add a tooltip to the link, but it is not elegant or obvious, and it
does not do any checking for the type of link, whether an attr exists, etc.

The gist is that it looks like you can get the parent from the parse-tree
info, and get the attr_html info from that (which is a list of strings).
Then you have to modify the "data" in the filter function which is the
html. It is easy here to just replace the <a with <a attr_html, but a more
complex transformation might require something more clever.

Maybe this is a start to get where you want.

the cite link is an org-ref link, but I think this should work on any kind
of link.


#+attr_html: title="I am a tooltip"
cite:schuett-2018-schnet


* build
:noexport:
#+BEGIN_SRC emacs-lisp
(defun ox-html-link-filter (data _backend info)
  (let ((link (car (org-element-map (plist-get info :parse-tree) 'link
     'identity))))
    (replace-regexp-in-string "<a " (concat "<a "
    (s-join " " (org-element-property
:attr_html
(org-element-property :parent link)))
    " ")
      data)))

(add-to-list 'org-export-filter-link-functions 'ox-html-link-filter)
(browse-url (org-html-export-to-html nil nil nil t))
#+END_SRC



John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Thu, Jan 31, 2019 at 5:36 AM Tarjei Bærland <tarjeibaerland@gmail.com>
wrote:

> Hi!
>
> I have a custom function for exporting image links in org-mode (I have my
> html exported to the parent folder of my .org files, and I just want to
> keep one copy of the image files).
>
> How can I get the "attr_html" of the link for a custom
> org-set-link-parameters function? As far as I can tell, the :export wants a
> function taking (path desc backend), and I do not know how to extract the
> parent of the link from this.
>
> Thanks in advance!
>
> Regards,
> Tarjei
>

[-- Attachment #2: Type: text/html, Size: 3649 bytes --]

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

end of thread, other threads:[~2019-01-31 14:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-31 10:36 "org-link-set-parameters" get parent properties Tarjei Bærland
2019-01-31 14:12 ` John Kitchin

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