Re: Rework of Bidi inline article

See below


On Wed, Feb 29, 2012 at 2:57 PM, Richard Ishida <ishida@w3.org> wrote:

> Hi Aharon,
>
> The HTML5 algorithm was always, and is still, the one that's problematic,
> in that it's not crystal clear to me exactly what you are proposing, and
> I'd like to be sure I get that clear in my mind before proceeding. The the
> logic of the cascading 'otherwise's is too vague (apart from the problem
> that it really helps to be a programmer to understand the whole cascade).


I don't think it's vague, but I do agree that it is only likely to make
sense to a programmer. So, before I go on to the rest of your questions,
here is a re-wording of the HTML5 algorithm that you may like better:

To summarize, in HTML5, to make sure that a phrase that contains (or may
contain) any opposite-direction characters will be displayed correctly, do
the following:
1. Wrap the phrase in a <bdi> element if one of the following cases applies:
- The phrase is not tightly wrapped in an element.
- The phrase is already tightly wrapped in an element, but the existing
element has inline display (e.g. an <a> or <span> element), and is not
<bdi>.
- The phrase is already tightly wrapped in an element, but the existing
element has non-inline display (e.g. a <p> or <div> element), and setting
its direction will change its alignment, and a potential alignment change
happens to be undesirable.
2. If you know the direction of the phrase, set the dir attribute on the
element around the phrase to that direction (either "ltr" or "rtl"). This
can be omitted if the element is not <bdi> and would inherit that
directionality anyway.
3. If you don't know the direction of the phrase, set the dir attribute on
the element around the phrase to "auto". This can be omitted if the element
is <bdi>, since "auto" is supposed to be its default dir value.


In step 1, I have chosen not to limit the second case to when the phrase's
direction is known. I have chosen not to limit it because <cite
dir="auto">foo</cite> is not significantly shorter than
<cite><bdi>foo</bdi></cite>, and has no other advantages. If you prefer to
limit it, the wording of that case could be thus:

- The phrase is already tightly wrapped in an element, but the existing
element has inline display (e.g. an <a> or <span> element), is not <bdi>,
and you know the phrase's direction. (That's because setting the element's
dir attribute to "ltr" or "rtl" in the next step will not directionally
isolate it from what follows it inline unless the element is <bdi>.)


>
>
> On 08/02/2012 13:15, Aharon (Vladimir) Lanin wrote:
>
>> Putting it all together in HTML5:
>>
>> To summarize, in HTML5, to make sure that a phrase that contains any
>> opposite-direction characters is displayed correctly, do the following:
>>
>> 1. If the phrase is already tightly wrapped in an element that has
>> non-inline display (e.g. a <p> or <div> element), and setting this
>> element's alignment to the "start" of the phrase's direction happens to
>> be desirable, set the existing element's dir attribute. If you do not
>> know the phrase's direction, set the dir attribute to "auto". If the
>> phrase is known to have the same direction as the context, it is not
>> necessary to set it.
>> 2. Otherwise,
>>
>
> Is this 'if the phrase is tightly wrapped in an inline element, and...' or
> 'if the  phrase is either not tightly wrapped in an element or the phrase
> is tightly wrapped in an inline element, and...' or 'if setting this
> element's alignment to the "start" of the phrase's direction happens to be
> UNdesirable, and... ', or all of the above.?


All of the above, i.e.:
if the phrase is not already tightly wrapped in an element, or if it is
tightly wrapped in an inline element, or if it is tightly wrapped in a
non-inline element, but setting this
element's alignment to the "start" of the phrase's direction happens to be
undesirable.


>
> > if you know the phrase's overall direction (or have a
>
>> better way of determining it than the method used by dir="auto"), wrap
>> the phrase in <bdi dir="ltr"> or <bdi dir="rtl">, as appropriate. Since
>> the phrase contains some opposite-direction characters, do this even
>> when the phrase's overall direction is the same as the context.
>> 3. (Optional) Otherwise,
>>
>
>
> Presumably this is 'if you don't know the phrase's overall direction
> and...'?


Yes, combined with the condition above, obviously.


>
>
>
>  if the phrase is already tightly wrapped by an
>> element with inline display, add dir="auto" to the element.
>> 4. Otherwise,
>>
>
> So this must be, if you don't know the phrase's direction and the phrase
> is not tightly wrapped...


When none of the other cases applied. Work it out :-)


>
>
>  wrap the phrase in <bdi>. Without an explicit dir value,
>> dir="auto" is implied.
>>
>>
>
> This is what I understood:
>
> 1. If you know the phrase's direction, or can work it out for injected
> text, then
>        a. if the phrase is already tightly wrapped by a block element, and
> there will be no adverse alignment effects, set dir on the block element to
> dir=ltr or dir=rtl.
>

You may prefer "an element with non-inline display" to "block element". In
the presence of style, the two are not the same, and HTML5 does away with
the concept of block elements.


>
>        b. in any other case, wrap the phrase in <bdi dir="ltr"> or <bdi
> dir="rtl">, as appropriate (if already wrapped by a span element, replace
> the span with this)
>

I would say "you may" before "replace the span with this".


>
>
> 2. If you don't know the phrase's direction, ie. the text will be injected
> at run time, then
>        a. if the phrase is already tightly wrapped by an element, add
> dir="auto" to the element.
>

This is wrong. If the phrase is already tightly wrapped by a
non-inline-display element, and you do not want to affect the alignment,
you should not set the dir attribute on the element.

And if the phrase is already tightly wrapped in an inline-display element,
I am not sure that it really is better to set dir=auto on the existing
element than to wrap the phrase in a <bdi>. In my phrasing above, I went
the <bdi> way.


>        b. wrap the phrase in bdi. Without an explicit dir value,
> dir="auto" is implied.
>
>
> This would lead to the following conversions, if you DO know the direction:
>
> <p>The-phrase</p> =>
> <p dir=rtl/ltr>The-phrase</p>
>
> <p>The-phrase</p> (where you want the same alignment as for context) =>
> <p><bdi dir=rtl/ltr>The-phrase</bdi></**p>
>
> <p>Static-text <cite>The-phrase</cite>... =>
> <p>Static-text <cite><bdi dir=rtl/ltr>The-phrase</bdi></**cite>
>

> <p>Static-text The-phrase... =>
> <p>Static text <bdi dir=rtl/ltr>The-phrase</bdi>..**.
>
>
>
> And to the following conversions, if you DON'T know the direction:
>
> <p>The-phrase</p> =>
> <p dir=auto>The-phrase</p>
>

As I mentioned above, this is bad if you do not want to affect the
paragraph's alignment.


>
> <p>Static-text <cite>The-phrase</cite>... =>
> <p>Static-text <cite dir=auto>The-phrase</cite>
>

As I mentioned above, I don't see a big reason to prefer this over
<p>Static-text <cite><bdi>The-phrase</bdi></cite>
But it's up to you.


> <p>Static-text The-phrase... =>
> <p>Static text <bdi>The-phrase</bdi>...
>
>
> Is that what you mean?
>
>
>
> You then said:
>
> > Actually, I am think of getting rid of step 3 in the HTML5 version (the
> > one marked Optional). <cite dir="auto">foo</cite> is not significantly
> > shorter than
> > <cite><bdi>foo</bdi></cite>, and has no other advantages.
>
>
> That would then mean that dir=auto is only recommended for use on block
> elements. Is that what you meant?


Basically, but it's not that it is "not recommend" on inline elements. It's
that for the sake of the shortest, clearest algorithm, we can prefer to
wrap it in <bdi> there.


>
>
> RI
>
>

Received on Wednesday, 14 March 2012 16:12:27 UTC