Giter Site home page Giter Site logo

dobidi / bidify-rb Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 42 KB

Add bidi support to HTML, helping to show RTL and LTR text in the correct direction regardless of the overall direction of the page.

License: GNU Lesser General Public License v3.0

Ruby 100.00%
bidi bidirectional

bidify-rb's Introduction

Bidify (Ruby)

Bidify helps to add bidirectional text support to HTML documents.

The project is in its very early stage of development, and its interface or functionality may break from one version to another. Use it with caution.

Usage

require 'bidify'

html_input = '<p>some content even in nested format</p>'
bidified_html = Bidify.bidify_html_string(html_input)
# bidified_html: '<p dir="auto">some content even in nested format</p>' 

Rules

Bidification (the dir="auto" attribute) follows these simple rules:

  • It applies to "bidifiable" tags.
  • It excludes the first immediate child element.
  • It excludes li tags.

The default bidifiable tags are div, h1, h2, h3, h4, h5, h6, p, ul, ol, and blockquote. One can modify this list using options.

As a complementary step, CSS styles should use logical properties. Here are a few examples:

/* Physical properties */
text-align: left;
padding-right: 10px;
border-left: 1px;
/* Logical properties */
text-align: start;
padding-inline-end: 10px;
border-inline-start: 1px;

Configuration

To use this gem with custom configuration, use the following syntax and pass options while creating an instance of bidifier:

options = {
  # ...
}

bidifier = Bidify::HtmlStringBidifier.new(options)

puts bidifier.apply('<div>input stringified html</div>')

Options

Available options with their default values are as follows:

  • excluding_tags: []

    Removes tags from the list of bidifiable tags. This option affects the provided tags in including_tags options.

  • including_tags: []

    Adds new tags to the list of bidifiable tags

  • greedy: false

    By default, bidification stops when it reaches an element that has dir attribute. Use true to disregard any existing dir attributes.

  • only_tags: []

    It sets the bidifiable tags to the given tags.

  • with_table_support: false

    Use true to add table tags support.

License

This project is a Free/Libre and Open Source software released under LGPLv3 license.

bidify-rb's People

Contributors

ahangarha avatar

Watchers

 avatar

bidify-rb's Issues

Add option for form support

Add an option for supporting form elements (rather than adding them manually using the including_tags option)

It should include:

  • input
  • textarea
  • label

Other form elements need more investigation.

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.