-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from daisy/add/dir
Add base direction pages for epub and html
- Loading branch information
Showing
7 changed files
with
477 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Text Direction</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="Guidelines for using the dir attribute in the EPUB package document"> | ||
<script> | ||
var page_info = { | ||
'category': ['EPUB'], | ||
'appliesTo': ['EPUB3','EPUB2'] | ||
}; | ||
</script> | ||
<script src="/js/init.js"></script> | ||
</head> | ||
<body> | ||
<main> | ||
<section id="summary"> | ||
<h3>Summary</h3> | ||
|
||
<p>Set the base direction for metadata in the package document to ensure that it is rendered correctly.</p> | ||
</section> | ||
|
||
<section id="tech"> | ||
<h3>Techniques</h3> | ||
|
||
<ul> | ||
<li>Set the <code>dir</code> attribute on the <code>package</code> element [[WCAG-1.3.2]]</li> | ||
<li>Set the <code>dir</code> attribute on <code>meta</code> elements whenever the base direction changes [[WCAG-1.3.2]]</li> | ||
</ul> | ||
</section> | ||
|
||
<section id="ex"> | ||
<h3>Examples</h3> | ||
|
||
<figure id="ex-01"> | ||
<figcaption> | ||
<div class="label">Example 1 — Declaring the default base direction</div> | ||
</figcaption> | ||
<pre id="ex-01-src" class="prettyprint linenums"><code><package … xml:lang="he" dir="rtl"> | ||
… | ||
</package></code></pre> | ||
</figure> | ||
|
||
<figure id="ex-02"> | ||
<figcaption> | ||
<div class="label">Example 2 — Overriding the default base direction</div> | ||
</figcaption> | ||
<pre id="ex-02-src" class="prettyprint linenums"><code><package … xml:lang="ar" dir="rtl"> | ||
<metadata> | ||
… | ||
<dc:subject dir="ltr">POETRY / Middle Eastern</dc:subject> | ||
… | ||
</metadata> | ||
… | ||
</package></code></pre> | ||
</figure> | ||
</section> | ||
|
||
<section id="faq"> | ||
<h3>Frequently Asked Questions</h3> | ||
|
||
<dl> | ||
<dt id="faq-001">Can I set the language of the text instead?</dt> | ||
<dd> | ||
<p>No. The language declaration does not affect the display directionality. <a | ||
href="lang.html">Setting the language</a> is important for text-to-speech rendering.</p> | ||
</dd> | ||
|
||
<dt>Why do I need to declare a default left-to-right base direction in EPUB 3 but not HTML?</dt> | ||
<dd> | ||
<p>HTML defaults to left-to-right in the absence of a <code>dir</code> attribute.</p> | ||
|
||
<p>EPUB 3 did not define the default directionality for package document metadata prior to EPUB | ||
3.3, or require support for both left-to-right and right-to-left text ranges, so reading | ||
systems often only support a single direction regardless of what is authored. Adding the | ||
<code>dir</code> attribute to set the default text direction, and to indicate changes on | ||
individual metadata elements <a href="#faq-002">may help with rendering</a> in | ||
these older reading systems, but is not guaranteed. Regardless, it is recommended to set | ||
the attribute going forward to ensure the correct base direction is applied.</p> | ||
|
||
<p>If a base direction is not specified, reading systems are expected to default to using the | ||
Unicode Bidi Algorithm to determine it. As there was initially no default base direction, | ||
one could not be added when the requirements for the attribute were improved. Too many | ||
publications were authored assuming their local base direction would be applied.</p> | ||
</dd> | ||
|
||
<dt id="faq-002">Why is the attribute labelled "under-implemented" in EPUB 3.3?</dt> | ||
<dd> | ||
<p>Most reading systems only support display of a single default text directionality, which | ||
leads to text in another direction being incorrectly displayed to users. Features like this | ||
typically have to be removed from W3C standards, but it is hoped the support situation will | ||
improve moving forward because of the attribute's importance for internationalization.</p> | ||
|
||
<p>W3C allowed existing EPUB features that did not meet the minimum support threshold to be | ||
retained provided they offered essential functionality and were marked "under-implemented". | ||
The label will be removed in the future when support increases.</p> | ||
</dd> | ||
</dl> | ||
</section> | ||
|
||
<section id="desc"> | ||
<h3>Explanation</h3> | ||
|
||
<p>It is important to set the base direction for text in the package document to help ensure that it is | ||
displayed properly by reading systems and read properly by assistive technologies.</p> | ||
|
||
<div class="note" role="note" aria-labelledby="html-dir"> | ||
<p id="html-dir" class="label">Note</p> | ||
<p>The <code>dir</code> attribute only affects text content in the <code>metadata</code> section; | ||
it does not affect how EPUB content documents are rendered. For information about setting the | ||
base direction in EPUB content documents, refer to the Knowledge Base's <a | ||
href="../html/dir.html">HTML Text Direction</a> page.</p> | ||
</div> | ||
|
||
<p>There are three ways to set the base direction in the package document:</p> | ||
|
||
<dl> | ||
<dt>Globally</dt> | ||
<dd> | ||
<p>To set the base direction for all text content, set a <code>dir</code> attribute | ||
on the root <code>package</code> element.</p> | ||
|
||
<pre id="desc-01-src" class="prettyprint linenums"><code><package … xml:lang="he" dir="rtl"></code></pre> | ||
|
||
<div class="note" role="note" aria-labelledby="epub2-support"> | ||
<p id="epub2-support" class="label">Note</p> | ||
<p>EPUB 2 does not support the <code>dir</code> attribute in the package document, | ||
so this technique does not apply.</p> | ||
</div> | ||
</dd> | ||
|
||
<dt>Per-element</dt> | ||
<dd> | ||
<p>To override the default base direction on the <code>package</code> element, add a | ||
<code>dir</code> attribute to each metadata element with a different base direction.</p> | ||
|
||
<pre id="desc-02-src" class="prettyprint linenums"><code><dc:creator … xml:lang="ar" dir="rtl">…</dc:creator></code></pre> | ||
|
||
<div class="note" role="note" aria-labelledby="epub2-support"> | ||
<p class="label">Note</p> | ||
<p>EPUB 2 does not support the <code>dir</code> attribute in the package document, | ||
so this technique does not apply.</p> | ||
</div> | ||
</dd> | ||
|
||
<dt>Inline</dt> | ||
<dd> | ||
<p id="unicode-ctrl">It is not possible to identify inline changes in the base direction in the | ||
package document. Although using markup to set the base direction is preferred, in these | ||
cases you can use Unicode control characters to identify the changes. For an | ||
introduction to the control characters and how to use them, refer to the W3C article <a | ||
href="https://www.w3.org/International/questions/qa-bidi-unicode-controls">How to use | ||
Unicode controls for bidi text</a>.</p> | ||
</dd> | ||
</dl> | ||
</section> | ||
|
||
<section id="refs"> | ||
<h3>Related Links</h3> | ||
|
||
<ul> | ||
<li>EPUB 3 — <a href="https://www.w3.org/TR/epub-33/#attrdef-dir">The <code>dir</code> attribute</a></li> | ||
<li>W3C — <a href="https://www.w3.org/International/articles/inline-bidi-markup/uba-basics">Unicode Bidirectional Algorithm basics</a></li> | ||
</ul> | ||
</section> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Text Direction</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="Guidelines for using the dir attribute in HTML"> | ||
<script> | ||
var page_info = { | ||
'category': ['HTML'], | ||
'appliesTo': ['EPUB3','EPUB2','Audiobooks*'] | ||
}; | ||
</script> | ||
<script src="/js/init.js"></script> | ||
</head> | ||
<body> | ||
<main> | ||
<section id="summary"> | ||
<h3>Summary</h3> | ||
|
||
<p>Set the base direction for right-to-left text to ensure that it is rendered correctly.</p> | ||
</section> | ||
|
||
<section id="tech"> | ||
<h3>Techniques</h3> | ||
|
||
<ul> | ||
<li>Set the <code>dir</code> attribute on the <code>html</code> element [[WCAG-1.3.2]]</li> | ||
<li>Set the <code>dir</code> attribute whenever the default direction changes [[WCAG-1.3.2]]</li> | ||
</ul> | ||
</section> | ||
|
||
<section id="ex"> | ||
<h3>Examples</h3> | ||
|
||
<figure id="ex-01"> | ||
<figcaption> | ||
<div class="label">Example 1 — Declaring the default base direction</div> | ||
</figcaption> | ||
<pre id="ex-01-src" class="prettyprint linenums"><code><html xmlns="http://www.w3.org/1999/xhtml" | ||
xml:lang="he" | ||
lang="he" | ||
dir="rtl"></code></pre> | ||
</figure> | ||
</section> | ||
|
||
<section id="faq"> | ||
<h3>Frequently Asked Questions</h3> | ||
|
||
<dl> | ||
<dt id="faq-001">Do I need to declare the <code>dir</code> attribute for left-to-right documents?</dt> | ||
<dd> | ||
<p>No. HTML defaults to left-to-right directionality for text, so it is not necessary to set | ||
the <code>dir</code> attribute for left-to-right documents. Only left-to-right text | ||
embedded in a right-to-left document needs to be specified.</p> | ||
</dd> | ||
|
||
<dt id="faq-002">Can I just set the language of the text?</dt> | ||
<dd> | ||
<p>No. The language declaration does not affect the display directionality. <a | ||
href="lang.html">Setting the language</a> is important for text-to-speech rendering.</p> | ||
</dd> | ||
|
||
<dt id="faq-003">Can I use CSS to set the direction instead?</dt> | ||
<dd> | ||
<p>No. CSS is not always available or respected in reading systems. Both the HTML and CSS | ||
specifications recommend using markup to set the text direction.</p> | ||
<p>Refer to <a href="https://www.w3.org/International/questions/qa-bidi-css-markup">CSS vs. | ||
markup for bidi support</a> for more information.</p> | ||
</dd> | ||
|
||
<dt id="faq-004">What if I have forms that accept text input?</dt> | ||
<dd> | ||
<p>Set the <code>dir</code> attribute to <code>auto</code> on forms and inputs to allow the | ||
reading system to determine the text direction at run-time.</p> | ||
</dd> | ||
|
||
<dt id="faq-005">When do I use the <code>bdi</code> and <code>bdo</code> elements?</dt> | ||
<dd> | ||
<p>It is not common to need these elements in publications.</p> | ||
|
||
<p>The <code>bdi</code> element is used to insert user-generated text into a document. As you | ||
cannot be sure the directionality of the text, it allows the reading system to examine the | ||
content and adjust the base direction as needed.</p> | ||
|
||
<p>The <code>bdo</code> element is used to override the base directionality of the text. It can | ||
be used, for example, to force right-to-left text to render in left-to-right form.</p> | ||
</dd> | ||
</dl> | ||
</section> | ||
|
||
<section id="desc"> | ||
<h3>Explanation</h3> | ||
|
||
<p>It is important to set the base text direction for right-to-left text in HTML and SVG documents | ||
to ensure that it is displayed properly by reading systems and read properly by assistive | ||
technologies.</p> | ||
|
||
<p>The way that right-to-left text is encoded in the markup and stored in memory is not the same as | ||
how it is displayed or read. If the correct base direction is not specified, the contents of a | ||
page may be read out of order. This is particularly problematic when left-to-right text is embedded | ||
in a right-to-left document. Weakly typed characters such as numbers and punctuation may be | ||
rendered in the wrong place, for example, or list entries could be placed out of order.</p> | ||
|
||
<p>To indicate that a document's base direction is right-to-left, simply add a <code>dir</code> | ||
attribute to the root <code>html</code> or <code>svg</code> element:</p> | ||
|
||
<pre id="desc-ex-01" class="prettyprint linenums"><code><html … dir="rtl"> | ||
|
||
<svg … dir="rtl"></code></pre> | ||
|
||
<p>If text with a left-to-right base direction is embedded in a right-to-left document, add a | ||
<code>dir</code> attribute to its enclosing element. For example, if the document contained a quote | ||
with a left-to-right base direction, you would add the <code>dir</code> attribute to the enclosing | ||
<code>blockquote</code>:</p> | ||
|
||
<pre id="desc-ex-02" class="prettyprint linenums"><code><blockquote dir="ltr"> | ||
<p>It was the best of times, it was the worst of times, …</p> | ||
</blockquote></code></pre> | ||
|
||
<p>If the base direction changes within a run of text, add a <code>span</code> element with a | ||
<code>dir</code> attribute:</p> | ||
|
||
<pre id="desc-ex-03" class="prettyprint linenums"><code><p> | ||
<!-- right-to-left text --> | ||
<span dir="ltr">Accessible EPUB 3</span> | ||
<!-- right-to-left text --> | ||
</p></code></pre> | ||
</section> | ||
|
||
<section id="refs"> | ||
<h3>Related Links</h3> | ||
|
||
<ul> | ||
<li>W3C — <a href="https://www.w3.org/International/questions/qa-html-dir">Structural markup and right-to-left text in HTML</a></li> | ||
<li>W3C — <a href="https://www.w3.org/International/articles/inline-bidi-markup/">Inline markup and bidirectional text in HTML</a></li> | ||
<li>W3C — <a href="https://www.w3.org/International/articles/inline-bidi-markup/uba-basics">Unicode Bidirectional Algorithm basics</a></li> | ||
<li>W3C — <a href="https://www.w3.org/International/tutorials/bidi-xhtml/">Creating HTML Pages in Arabic, Hebrew and Other Right-to-left Scripts (tutorial)</a></li> | ||
</ul> | ||
</section> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.