Skip to content

Suggestions #1

@amirhhashemi

Description

@amirhhashemi

Hi Mahdi. I hope you are doing great. I saw your comment in Virgool and it immediately got my attention.

I have a few suggestions to improve the extension.

dir attribute

The way you currently change the direction of LTR elements is that you create a CSS class with direction: rtl property and then add it to every element that should be RTL. That might not work well in all websites.

  1. Some websites have a strict CSP that prevents adding arbitrary CSS styles and it completely breaks the extension.
  2. The class you add might override an already existing class.
  3. Component libraries, Tailwindcss plugins and anything that supports RTL in addition to LTR, usually checks for the dir attribute to detect RTL elements and adjust its styles for RTL. By adding dir="rtl" you make sure that those elements look the way they are intended to.

Also W3C suggests to use the dir attribute over CSS direction propery whenever possible:

You should always use dedicated bidi markup to describe your content, where markup is available.

For HTML, the bidi markup is sufficient and no CSS bidi styling is needed. You should never apply CSS bidi styling to ordinary elements or attributes. This includes content delivered as XML using XHTML 1.x or polyglot markup.

You can of course do it in addition to the current method.

Other languages

Currently, the extension only supports Arabic but there are other RTL languages. This Regex from Lexical (the editor that is used in most Facebook products) covers a good number of them:

// https://github.com/facebook/lexical/blob/ede6500447068c86b18188597909b1b8b54da5ca/packages/lexical/src/LexicalConstants.ts#L94C5-L94C5

const RTL = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
const LTR =
  'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
  '\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
  '\uFE00-\uFE6F\uFEFD-\uFFFF';

export const RTL_REGEX = new RegExp('^[^' + LTR + ']*[' + RTL + ']');

Other elements

Currently the extension only updates the direction of p and span elements. I think it's a good idea to add these elements too:

  • blockquote
  • h1...h6

I'm busy at the time and inexperienced in writing chrome extensions, that's why I didn't make a PR myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions