Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dir=auto on Bidi code elements #3935

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

jason-fox
Copy link
Member

Description

For RTL renderings only, add dir="auto" to monospace elements, effectively encoding a <bdi> within the <span> to ensure that the browser will look at the first strongly typed character in the element and work out from that what the base direction of the element should be.

Motivation and Context

When reading an HTML document in an RTL language such as Arabic or Hebrew, code blocks (typically written in Latin script) are read LTR. This makes the rendered HTML document inherently bidirectional. HTML browsers usually make a good attempt at rendering bidirectional text correctly by splitting characters into three types, LTR, RTL and neutral. The problem is that when a monospace code block begins with a neutral character (like punctuation or a number) the directionality of the character is inherited from the parent element.

Take the following <filepath> for example:

<section>
      <title>Styling DITA elements</title>
      <p xml:lang="he" dir="rtl">
           החל מחלקות שירות עקביות של Bootstrap על פני DITA על ידי תיקון 
          <filepath>/Customization/xsl/utility-classes.xsl</filepath>
      </p>
</section>

It currently renders in HTML (without a dir attribute) as:

<p class="p" lang="he" dir="rtl">
  החל מחלקות שירות עקביות של Bootstrap על פני DITA על ידי תיקון 
  <span class="ph filepath">/Customization/xsl/utility-classes.xsl</span>
</p>

Which causes the first neutral character in the <filepath> - the leading / to be incorrectly rendered RTL at the end of the line:

Screenshot 2022-06-07 at 09 33 12

With dir="auto", it should read the code block as all LTR latin text and render as

Screenshot 2022-06-07 at 09 32 47

<p class="p" lang="he" dir="rtl">
  החל מחלקות שירות עקביות של Bootstrap על פני DITA על ידי תיקון 
  <span class="ph filepath" dir="auto">/Customization/xsl/utility-classes.xsl</span>
</p>

Which causes the browser to consider the first strong character it finds and then render the whole <span> correctly as left-to- right with the leading slash at the beginning. Note that had the <span> started with RTL text it would have rendered correctly as well, since dir="auto" is only a processing instruction not a forced direction like dir="ltr"

How Has This Been Tested?

Local testing, creating documents with a default.language=ar

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)

Documentation and Compatibility

  • What documentation changes are needed for this feature?

None

@jason-fox
Copy link
Member Author

jason-fox commented Jun 7, 2022

Of course, this is only really an issue when the default.language is set to an RTL language like he, ar etc. If only a small snippet is effected, the author can already add dir="rtl" and dir="auto" on each individual element throughout:

<section>
      <title>Styling DITA elements</title>
      <p xml:lang="he" dir="rtl">
           החל מחלקות שירות עקביות של Bootstrap על פני DITA על ידי תיקון 
          <filepath dir="auto">/Customization/xsl/utility-classes.xsl</filepath>
      </p>
</section>

But this removes the chore of adding dir="auto" on elements which are defined in the DITA spec as part of the programming domain and as such are semantically defined as code and therefore would rendered LTR in Arabic, Hebrew, Farsi etc. anyway.

@jason-fox jason-fox force-pushed the feature/bidi branch 3 times, most recently from 21faebd to 4c50519 Compare August 5, 2022 12:03
jason-fox and others added 2 commits August 5, 2022 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant