From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Links & images with different attributes in the same paragraph
Date: Sat, 11 Nov 2023 22:54:37 +0700 [thread overview]
Message-ID: <uio840$qde$1@ciao.gmane.io> (raw)
Hi,
I raised this topic earlier. It seems, there is a rather generic
workaround that may help.
Sometimes it is necessary to assign specific export attributes to some
links in a paragraph while others should get another set of them. Inline
images should have different alt text.
--- 8< ---
Text with <<anchor>> in a paragraph.
Any link types are supported including
[[wrap::href "anchor"][internal]] ones.
Attributes may be added selectively:
<wrap::href "https://microsoft.com/" :attr_html ":class external \
:title Link that does not increase target page rank \
:noreferrer 1" :attr_html ":nofollow 1 :noopener 1">
Images in the same paragraph may have different =alt= attribute:
raster
[[wrap::attr_html ":alt PNG Unicorn"
:href
"https://orgmode.org/worg/images/orgmode/org-mode-unicorn-original-logo.png"]]
and vector
[[wrap::attr_html ":alt SVG Unicorn"
:href "https://orgmode.org/resources/img/org-mode-unicorn.svg"]]
images.
--- >8 ---
is exported as
--- 8< ---
<p>
Text with <a id="org0424ec3"></a> in a paragraph.
</p>
<p>
Any link types are supported including
<a href="#org0424ec3">internal</a> ones.
Attributes may be added selectively:
<a href="https://microsoft.com/" class="external" title="Link that does
not increase target page rank" noreferrer="1" nofollow="1"
noopener="1">https://microsoft.com/</a>
</p>
<p>
Images in the same paragraph may have different <code>alt</code> attribute:
raster
<img
src="https://orgmode.org/worg/images/orgmode/org-mode-unicorn-original-logo.png"
alt="PNG Unicorn" />
and vector
<img src="https://orgmode.org/resources/img/org-mode-unicorn.svg"
alt="SVG Unicorn" class="org-svg" />
images.
</p>
--- >8 ---
and it requires not so much code:
# #+header: :eval never-export
#+begin_src elisp :exports results :results silent
(defun nm/org-link-wrap-path-to-props (path)
(read (concat "(" path ")")))
(defun nm/org-link-wrap-copy-props (props link)
(while props
(let ((name (pop props))
(value (pop props))
(case-fold-search t))
(org-element-put-property
link
name
;; `org-element--collect-affiliated-keywords'
(if (string-match-p "\\`:attr_" (symbol-name name))
(append (org-element-property name link) (list value))
value)))))
(defun nm/org-link-wrap-export
(path description backend info)
(let* ((props-all (nm/org-link-wrap-path-to-props path))
(href (plist-get props-all :href))
;; `org-plist-delete' removes other duplicated keys as well.
(props (map-delete props-all :href))
;; Taken from `org-link-open-from-string'.
(link (with-temp-buffer
(let ((org-inhibit-startup nil))
(insert "[[" (org-link-escape href) "]]")
(org-mode)
(goto-char (point-min))
(org-element-link-parser)))))
(nm/org-link-wrap-copy-props props link)
(when description
(org-element-set-contents link description))
(org-no-properties
(org-export-data-with-backend link backend info))))
(defun nm/org-link-wrap-follow (path arg)
(let* ((props (nm/org-link-wrap-path-to-props path))
(href (plist-get props :href)))
(org-link-open-from-string
(concat "[[" (org-link-escape href) "]]")
arg)))
(org-link-set-parameters
"wrap"
:follow #'nm/org-link-wrap-follow
:export #'nm/org-link-wrap-export)
#+end_src
An example of earlier discussion:
https://list.orgmode.org/t8q71r$mgv$1@ciao.gmane.io/
Max Nikulin. [BUG] manual: confusing example of adding attributes to a
link (affiliated keywords). Mon, 20 Jun 2022 23:25:29 +0700
reply other threads:[~2023-11-11 15:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='uio840$qde$1@ciao.gmane.io' \
--to=manikulin@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).