GithubHelp home page GithubHelp logo

isabella232 / rtlcss-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prestashop/rtlcss-php

0.0 0.0 0.0 79 KB

RtlCss is a PHP library for converting LTR CSS to RTL.

License: MIT License

PHP 100.00%

rtlcss-php's Introduction

RtlCss

RtlCss is a library for converting Left-To-Right (LTR) Cascading Style Sheets(CSS) to Right-To-Left (RTL).

Usage

Installation using composer

Add the library to your composer.json

{
    "require": {
        "prestashop/rtlcss-php": "*"
    }
}

Flipping

$parser = new Sabberworm\CSS\Parser($css);
$tree = $parser->parse()
$rtlcss = new PrestaShop\RtlCss\RtlCss($tree);
$rtlcss->flip();
echo $tree->render();

For parsing options and rendering, refer to PrestaShop/PHP-CSS-Parser.

Output sample

.div {
    direction: ltr;
    left: 10px;
    border: 10px 5px 0px 2px;
    float: left;
}

Becomes:

.div {
    direction: rtl;
    right: 10px;
    border: 10px 2px 0px 5px;
    float: right;
}

Options

You can prefix your CSS with comments starting with /*rtl:*/ for special handling.

Do not flip values

Prepend with /*rtl:ignore*/, or wrap within /*rtl:begin:ignore*/ and /*rtl:end:ignore*/.

.div {
    /*rtl:ignore*/
    float: left;
    left: 10px;
}
.div {
    direction: ltr;
    /*rtl:begin:ignore*/
    float: left;
    left: 10px;
    /*rtl:end:ignore*/
}

Becomes:

.div {
    float: left;
    right: 10px;
}
.div {
    direction: rtl;
    float: left;
    left: 10px;
}

Remove CSS

Prepend with /*rtl:remove*/, wrap within /*rtl:begin:remove*/ and /*rtl:end:remove*/.

.div {
    /*rtl:remove*/
    float: left;
    left: 10px;
}
.div {
    direction: ltr;
    /*rtl:begin:remove*/
    float: left;
    left: 10px;
    /*rtl:end:remove*/
}

Becomes:

.div {
    right: 10px;
}
.div {
    direction: rtl;
}

Additional CSS

Write the CSS in a content starting with /*rtl:raw:.

.div {
    /*rtl:raw:
        text-align: left;
    */
    float: left;
}

Becomes:

.div {
    text-align: left;
    float: right;
}

Limitation

Currently the comments must always precede a statement, they will not work if they are not followed by anything.

Valid:

.div {
    /*rtl:raw:
        text-align: left;
    */
    float: left;
}

Invalid:

.div {
    float: left;
    /*rtl:raw:
        text-align: left;
    */
}

CSS support

A lot of common CSS rules are supported, however a few complex ones are not. To get a grasp of what is supported and what isn't, please refer to the test cases. Unsupported scenarios are marked to be skipped.

About this tool

This tool is very heavily inspired by MohammadYounes/rtlcss, even though at this stage it does not include all of its features. See this library as a partial port of the latter.

Credits

License

Licensed under the MIT License.

rtlcss-php's People

Contributors

eternoendless avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.