emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Moe <mail@christianmoe.com>
To: "François Pinard" <pinard@iro.umontreal.ca>
Cc: emacs-orgmode@gnu.org
Subject: Re: ATTR_HTML for a clickable image, howto?
Date: Fri, 06 Apr 2012 10:52:41 +0200	[thread overview]
Message-ID: <4F7EAED9.2040804@christianmoe.com> (raw)
In-Reply-To: <86vclekyqo.fsf@iro.umontreal.ca>

Hi,

On 4/5/12 5:02 PM, François Pinard wrote:
> I understand what you mean by saying it does not make sense with the
> current mechanics.  Yet, from a user perspective, it surely makes sense
> hoping that Org offers a way for adding attributes to either part of a
> link, as links are kind of indivisible (so far that I know).

On reflection, there might be a case for making the exporter smart 
enough not to place #+ATTR_HTML attributes such as ALT, WIDTH and 
HEIGHT (or even ALIGN, though see below) in the <A> element, where 
they have no place, but instead pass them through to the clickable 
image, where they obviously belong.

>> I suggest you fix your css instead.
>
> My knowledge of CSS is rudimentary.  I'm not aware that CSS (the version
> widely available, not the incoming one) has enough matching capabilities
> to spot wrong HTML, remove attributes on some elements and add them on
> other elements.  Is that really possible?  Should I dive and study CSS
> more?  Without matching, CSS would not help much, as the correction is
> needed in three dozen cases at most, and not blindly for all images.

No, CSS doesn't move attributes around.

But the ALIGN attribute has long been deprecated in favor of CSS.

All the CSS needed to right-align all images that are children of a 
link anchor is:

    a img {float: right;}

(There are other, more complex ways to control horizontal alignment in 
CSS.)

To set this on a per-document basis in Org, use:

    #+STYLE: <style>a img {float: right;}</style>

If you need more fine-grained control, you could use e.g.:

    a.rightaligned img {float: right;}

where "rightaligned" is an arbitrary name, you could call the class 
"alignright" or "right" or "rt" or whatever.

Then you could set the "rightaligned" class on all links you want 
right-aligned:

    #+ATTR_HTML: class="rightaligned"
    [[./targetimage.png][./linkimage.png]]

Note that it's still the <A> element that gets the class. In this 
case, the CSS applies to all <IMG> child elements of <A 
CLASS="rightaligned"> elements.

For this particular purpose, though, that CSS may be overkill; looks 
to me like you get the same visual result by just styling <A> directly.

So here's the whole CSS for right-aligning any block element on which 
you can set the CLASS to "rightaligned" with ATTR_HTML:

    .rightaligned {float: right;}

> I could ponder using XSL or something else to post-process the HTML
> generated by Org, so circumventing the limitation.  This would be adding
> an unwelcome layer of complexity.  I like to perceive Org as a tool
> which much simplify my life! :-).

Any problem you can solve with a single line of simple CSS, you can 
probably solve with a deprecated tag, several lines of complicated 
XSL, and a postprocessing hook in Org to issue a shell command to an 
XSLT processor... But why would you?

If you like Org for its simplicity, you will love CSS.


Yours,
Christian

  reply	other threads:[~2012-04-06  8:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-01 21:27 ATTR_HTML for a clickable image, howto? François Pinard
2012-04-02  8:14 ` Bastien
2012-04-02 10:34   ` Christian Moe
2012-04-02 15:06     ` Bastien
2012-04-02 21:30       ` Samuel Wales
2012-04-03  5:42         ` Bastien
2012-04-05 23:34           ` Samuel Wales
2012-04-05 15:02   ` François Pinard
2012-04-06  8:52     ` Christian Moe [this message]
2012-04-06  9:29       ` Christian Moe
2012-04-06 18:41       ` Samuel Wales
2012-04-06 18:45         ` Samuel Wales
2012-04-07 13:15         ` Christian Moe
2012-04-10 23:53           ` Samuel Wales
2012-04-11  8:11             ` Christian Moe
2012-05-12  0:43               ` Samuel Wales
2012-05-20  1:00               ` Macros [was: Re: ATTR_HTML for a clickable image, howto?] François Pinard
2012-05-20  8:02                 ` Nicolas Goaziou
2012-05-20  8:34                   ` Yagnesh Raghava Yakkala
2012-05-20 10:24                     ` Nicolas Goaziou
2012-05-22 23:23                 ` Bastien
2012-07-05 14:40                 ` Bastien
2012-07-05 15:09                   ` Nicolas Goaziou
2012-07-05 15:51                     ` Sebastien Vauban
2012-07-05 20:44                       ` Nicolas Goaziou
2012-08-05  9:19                     ` Bastien
2012-05-20  0:39           ` ATTR_HTML for a clickable image, howto? François Pinard
2012-04-06  9:02     ` Bastien

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=4F7EAED9.2040804@christianmoe.com \
    --to=mail@christianmoe.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=pinard@iro.umontreal.ca \
    /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).