What is bidirectional text?
Today we watched a presentation 1—————————————————————————————► by Elika Etemad (الیکا اعتماد) on 2—————————————► ◄——————————3 4► the bidi algorithm. 5—————————————————►
What is bidirectional text?
ال ۱۳۹۱ مان ایران نرفتم.
◄——————————————3 2——► ◄1
As soon as you expect to have any RTL, you must deal with bidi.
Text is stored in logical order, not visual order.
by Elika Etemad (الیکا اعتماد) on bidi.
1 2 3 5 4 6 7
Visual order depends on line-breaking.
by Elika Etemad (الیکا اعتماد) on bidi.
1 2 3 5 4 6 7
by Elika Etemad (الیکا 1 2 3 4 اعتماد) on bidi. 5 6 7
All Unicode characters are either
Note: Numbers are special. We'll pretend they're L for now.
Surrounded neutrals take surrounding directionality.
L N N N L ⟱ L L L L L
L N N N R ⟱ L ? ? ? R
.This is my sentence
این جمله است.
Each paragraph has a base direction.
dir
attribute.
Use the base direction for initial/final/conflicted neutrals.
L ⇒ evens | R ⇒ odds |
Fox پرید over Dog. LLLNRRRRNLLLLNLLLN LLLLRRRRLLLLLLLLLL 000011110000000000
abc DEF ghij
000 111 0000
رروباه از رو Dog پرید. NRRRRNLLLNRRNRRNRRRRRR RRRRRRLLLRRRRRRRRRRRRR 1111112221111111111111
ABC def GHIJ
111 222 1111
For each level run:
abc DEF ghij 000 111 0000
abc FED ghij 000 000 0000
ABC def GHIJ 111 222 1111
ABC fed GHIJ 111 111 1111
JIHG def CBA 0000 000 000
The fox پرید over the lazy dog. 1—————► ◄——2 3————————————————► ——————————————————————————————►
The fox پرید over the تنبل dog. 1—————► ◄——2 3——————► ◄——2 1——► ——————————————————————————————►
الیکا ”...“ نوشت. ◄———3 2—► ◄———1 ◄———————————————
Fox پرید over Dog. 1—► ◄——2 3———————► —————————————————►
الیکا ”Fox پرید over Dog“ نوشت.
◄———5 4——————► ◄——3 2———► ◄———1
الیکا ”Fox پرید over Dog“ نوشت. ◄———3 2———————————————► ◄———1 ◄———5 2—► ◄——3 4——————► ◄———1
Embeddings are markup that creates a "paragraph" within a paragraph.
الیکا ”Fox پرید over Dog!“ نوشت. ◄—1—► ◄——————2—————————► ◄—1—► 11111 222 3333 222222222 11111 ZYXWV stu OPQR nmlkjihgf EDCBA
ABCDE »fghijklmn OPQR stu« VWXYZ ◄—1—► ◄——————2—————————► ◄—1—► 11111 222222222 3333 222 11111
ABCDE fghijklmn RQPO stu VWXYZ
11111 222222222 2222 222 11111
ABCDE uts OPQR nmlkjihgf VWXYZ
11111 111 1111 111111111 11111
ZYXWV stu OPQR nmlkjihgf EDCBA
00000 000 0000 000000000 00000
End of Part I
dir
attributedir="ltr"
| dir="rtl"
<p>
, <div>
, <html>
)
<a>
, <span>
, <em>
)
dir
attributeltr
Directionality affects:
direction
and unicode-bidi
properties
<html dir=rtl>
<blockquote dir=rtl>...</blockquote>
<div dir=rtl>...</div>
<p>... <q dir=rtl>...</q> ...</p>
Most problems in bidi are due to either
L N N N L ⟱ L L L L L
strong right-to-left (R), e.g. العربية, עִבְרִית
strong right-to-left (R), e.g. العربية, עִבְרִית
strong right-to-left (R), e.g. العربية‎, עִבְרִית
<p dir=ltr> ... <span dir=rtl>ABC</span> <span dir=rtl>DEF</span> ...
FED CBA not CBA FED !
Short story: embeddings suck.
title — author: AUTHOR — TITLE:
No heuristic is always right! It's just a heuristic.
End of Part II
e.g. <bdi dir=rtl>العربية</bdi>, <bdi dir=rtl>עִבְרִית</bdi>
dir=auto
provides browser-side first-strong auto-detection
<pre>
and <textarea>
are special
:dir(rtl) { ... CSS for rtl elements ... } :dir(ltr) { ... CSS for ltr elements ... }
dir
attribute
dir=auto
resolution
text-align: start | end | match-parent