bidify 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -3
- data/lib/bidify/version.rb +1 -1
- data/lib/bidify.rb +3 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 869c99f4077d50f88ff976b15ab4106fd15900e45af1bd5673de5255b6cfb8ef
|
4
|
+
data.tar.gz: 688dfb1fcab1cbfb627a851951ca80a16479c96c6498b036f3a0e3453441b7f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56b5b3058a06f7fe748796490cf53d940b81257bfa4e7990045d788170082a000c463a2fce8c85a9e1d63eb306d2ff471b95f5091fddd0ed49a2e328aaebd3cc
|
7
|
+
data.tar.gz: aa3cdec3d581149a8c57ee692d4bb912eb86adadddbad364ebda35acda25d6c0905eb329b79406adf187f486adef4077ac246c28b73aacbea4b1ac63922c4fdf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Bidify (Ruby)
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/bidify.svg)](https://badge.fury.io/rb/bidify)
|
4
|
-
|
5
3
|
Bidify helps to add bidirectional text support to HTML documents.
|
6
4
|
|
7
5
|
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.
|
@@ -11,8 +9,9 @@ The project is in its very early stage of development and its interface or funct
|
|
11
9
|
```rb
|
12
10
|
require 'bidify'
|
13
11
|
|
14
|
-
html_input = '<
|
12
|
+
html_input = '<p>some content even in nested format</p>'
|
15
13
|
bidified_html = Bidify.bidify(html_input)
|
14
|
+
# bidified_html: '<p dir="auto">some content even in nested format</p>'
|
16
15
|
```
|
17
16
|
|
18
17
|
## License
|
data/lib/bidify/version.rb
CHANGED
data/lib/bidify.rb
CHANGED
@@ -8,7 +8,7 @@ require 'nokogiri'
|
|
8
8
|
#
|
9
9
|
# bidified_html = Bidify.bidify(regular_html)
|
10
10
|
module Bidify
|
11
|
-
@bidifiable_tags = %w[h1 h2 h3 h4 h5 h6 p
|
11
|
+
@bidifiable_tags = %w[div h1 h2 h3 h4 h5 h6 p ul ol blockquote]
|
12
12
|
|
13
13
|
class << self
|
14
14
|
###
|
@@ -16,23 +16,16 @@ module Bidify
|
|
16
16
|
def bidify(input_html)
|
17
17
|
html_node = Nokogiri::HTML.fragment(input_html)
|
18
18
|
bidify_recursively(html_node, { root: true })
|
19
|
+
|
19
20
|
html_node.to_s
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
25
|
def bidify_recursively(html_node, options = {})
|
25
|
-
return unless html_node.children.count.positive?
|
26
|
-
|
27
|
-
apply_bidi(html_node, options)
|
28
|
-
end
|
29
|
-
|
30
|
-
def apply_bidi(node, options)
|
31
26
|
seen_the_first_bidifiable_element = false
|
32
27
|
|
33
|
-
|
34
|
-
next if child_node.blank?
|
35
|
-
|
28
|
+
html_node.children.each do |child_node|
|
36
29
|
bidify_recursively(child_node)
|
37
30
|
|
38
31
|
if (options[:root] || seen_the_first_bidifiable_element) && @bidifiable_tags.include?(child_node.name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bidify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mostafa Ahangarha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|