bidify 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28b6f2a2a467a1c0c61b7da79e06f2113cce82e0142c1c4646ba07a47261033f
4
- data.tar.gz: 82ac8d4762aaf7ca746c5e7a3b1d285e85528929c4649c1396f68884b2b4863b
3
+ metadata.gz: 1422cfe24a1d9befab548ffcc1322e8c338c4071b59fc507fb27d1612bd0c9c2
4
+ data.tar.gz: e5be73c633debf5ab749773605daf538bc7dbd061e8a5bd149361987b5ce0eb7
5
5
  SHA512:
6
- metadata.gz: efa3b752d9cabd3f6a37deb3a6a3a870214d2ccb3ccb6471d754dc99e6402ec389b2e18b44cc8c94ba2602a5c67a11628c72e572bed14f55e3adaf7884c2453a
7
- data.tar.gz: 68f8d08def9b0a02c3ed7e34d10832bb29cbd918f6c59337585f51acf83a85e4c7d75ea50c89f8285f0d2d3e061f982d060edc0c4c00810a64ae775aa87d0b71
6
+ metadata.gz: c916797e6d73a4ab03947501b987d3eb4f8900a7deac7459c5b3756878ac6ce8aabc772eb1051b668e89c1de0997ca472d0425fbbe1a53d205aea2ac69c6641b
7
+ data.tar.gz: 7be01ddcf9db62892c70bd0e18084de7df6afa2d5ebedc1c3788cf419822712611687fa9c1f4a1a807b00dd7d3fa6f7954557c680004b881bb287eee1d4f44b4
data/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.3.1] - 2023-08-26
11
+ ### Security
12
+ - Upgrade `nokogiry` for security issues with libxml2 dependency (#14)
13
+
14
+ ## [0.3.0] - 2023-07-30
15
+
16
+ ### Added
17
+ - Added a feature to stop budification if an element already has dir attribute
18
+ and a `greedy` option to force bidification on all nested elements (#10)
19
+ - Added options for `only_tags`, `including_tags`, and `excluding_tags` (#12)
20
+
21
+ ## [0.2.0] - 2023-07-02
22
+
23
+ ### Changed
24
+ - BREAKING: change the interface (#8)
25
+
26
+ ### Added
27
+ - Added `with_table_support` option (#9)
28
+
29
+ ## [0.1.1] - 2023-06-25
30
+
31
+ ### Added
32
+ - Include `div` in the default bidifiable tags (#6)
33
+
34
+ ### Fixed
35
+ - Fix issues with lists by stoping bidification on `li` tags (#4)
36
+
37
+ ## [0.1.0] - 2023-06-22
38
+
39
+ The initial release with the core functionality (#1)
40
+
41
+ [unreleased]: https://github.com/dobidi/bidify-rb/compare/v0.3.1...HEAD
42
+ [0.3.1]: https://github.com/dobidi/bidify-rb/compare/v0.3.0...v0.3.1
43
+ [0.3.0]: https://github.com/dobidi/bidify-rb/compare/v0.2.0...v0.3.0
44
+ [0.2.0]: https://github.com/dobidi/bidify-rb/compare/v0.1.1...v0.2.0
45
+ [0.1.1]: https://github.com/dobidi/bidify-rb/compare/v0.1.0...v0.1.1
46
+ [0.1.0]: https://github.com/dobidi/bidify-rb/releases/tag/v0.1.0
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bidify (0.1.1)
5
- nokogiri (~> 1.14)
4
+ bidify (0.3.1)
5
+ nokogiri (~> 1.15)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -10,15 +10,16 @@ GEM
10
10
  ast (2.4.2)
11
11
  diff-lcs (1.5.0)
12
12
  json (2.6.3)
13
- nokogiri (1.15.2-x86_64-linux)
13
+ nokogiri (1.15.4-x86_64-linux)
14
14
  racc (~> 1.4)
15
15
  parallel (1.23.0)
16
- parser (3.2.2.1)
16
+ parser (3.2.2.3)
17
17
  ast (~> 2.4.1)
18
- racc (1.7.0)
18
+ racc
19
+ racc (1.7.1)
19
20
  rainbow (3.1.1)
20
21
  regexp_parser (2.8.1)
21
- rexml (3.2.5)
22
+ rexml (3.2.6)
22
23
  rspec (3.12.0)
23
24
  rspec-core (~> 3.12.0)
24
25
  rspec-expectations (~> 3.12.0)
@@ -28,10 +29,10 @@ GEM
28
29
  rspec-expectations (3.12.3)
29
30
  diff-lcs (>= 1.2.0, < 2.0)
30
31
  rspec-support (~> 3.12.0)
31
- rspec-mocks (3.12.5)
32
+ rspec-mocks (3.12.6)
32
33
  diff-lcs (>= 1.2.0, < 2.0)
33
34
  rspec-support (~> 3.12.0)
34
- rspec-support (3.12.0)
35
+ rspec-support (3.12.1)
35
36
  rubocop (1.51.0)
36
37
  json (~> 2.3)
37
38
  parallel (~> 1.10)
@@ -42,16 +43,16 @@ GEM
42
43
  rubocop-ast (>= 1.28.0, < 2.0)
43
44
  ruby-progressbar (~> 1.7)
44
45
  unicode-display_width (>= 2.4.0, < 3.0)
45
- rubocop-ast (1.28.1)
46
+ rubocop-ast (1.29.0)
46
47
  parser (>= 3.2.1.0)
47
48
  rubocop-capybara (2.18.0)
48
49
  rubocop (~> 1.41)
49
50
  rubocop-factory_bot (2.23.1)
50
51
  rubocop (~> 1.33)
51
- rubocop-performance (1.18.0)
52
+ rubocop-performance (1.19.0)
52
53
  rubocop (>= 1.7.0, < 2.0)
53
54
  rubocop-ast (>= 0.4.0)
54
- rubocop-rspec (2.22.0)
55
+ rubocop-rspec (2.23.2)
55
56
  rubocop (~> 1.33)
56
57
  rubocop-capybara (~> 2.17)
57
58
  rubocop-factory_bot (~> 2.22)
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Bidify helps to add bidirectional text support to HTML documents.
4
4
 
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.
5
+ The project is in its very early stage of development, and its interface or
6
+ functionality may break from one version to another. Use it with caution.
6
7
 
7
8
  ## Usage
8
9
 
@@ -10,22 +11,20 @@ The project is in its very early stage of development and its interface or funct
10
11
  require 'bidify'
11
12
 
12
13
  html_input = '<p>some content even in nested format</p>'
13
- bidified_html = Bidify.bidify(html_input)
14
+ bidified_html = Bidify.bidify_html_string(html_input)
14
15
  # bidified_html: '<p dir="auto">some content even in nested format</p>'
15
16
  ```
16
17
 
17
18
  ## Rules
18
19
 
19
- The `dir="auto"` attribute should be applied on "bidifiable" tags as per the following rules:
20
+ Bidification (the `dir="auto"` attribute) follows these simple rules:
20
21
 
21
- - Only apply on "bidifiable" tags.
22
- - All top-level elements
23
- - All child elements except the first child
22
+ - It applies to "bidifiable" tags.
23
+ - It excludes the first immediate child element.
24
+ - It excludes `li` tags.
24
25
 
25
- Bidifiable elements can be defined as per the use case requirements (not yet implemented).
26
- The default bidifiable tags are: `div`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `ul`, `ol`, `blockquote`.
27
-
28
- Notice that `li` elements shouldn't get `dir=auto` otherwise, the list appearance gets damaged.
26
+ The default bidifiable tags are `div`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`,
27
+ `p`, `ul`, `ol`, and `blockquote`. One can modify this list using options.
29
28
 
30
29
  As a complementary step, CSS styles should use [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values). Here are a few examples:
31
30
 
@@ -40,6 +39,48 @@ padding-inline-end: 10px;
40
39
  border-inline-start: 1px;
41
40
  ```
42
41
 
42
+ ## Configuration
43
+
44
+ To use this gem with custom configuration, use the following syntax and pass
45
+ options while creating an instance of bidifier:
46
+
47
+ ```rb
48
+ options = {
49
+ # ...
50
+ }
51
+
52
+ bidifier = Bidify::HtmlStringBidifier.new(options)
53
+
54
+ puts bidifier.apply('<div>input stringified html</div>')
55
+ ```
56
+
57
+ ### Options
58
+
59
+ Available options with their default values are as follows:
60
+
61
+ - `excluding_tags: []`
62
+
63
+ Removes tags from the list of bidifiable tags. This option affects the
64
+ provided tags in `including_tags` options.
65
+
66
+ - `including_tags: []`
67
+
68
+ Adds new tags to the list of bidifiable tags
69
+
70
+ - `greedy: false`
71
+
72
+ By default, bidification stops when it reaches an element that has `dir`
73
+ attribute. Use `true` to disregard any existing `dir` attributes.
74
+
75
+ - `only_tags: []`
76
+
77
+ It sets the bidifiable tags to the given tags.
78
+
79
+ - `with_table_support: false`
80
+
81
+ Use `true` to add table tags support.
82
+
43
83
  ## License
44
84
 
45
- This project is a Free/Libre and Open Source software released under LGPLv3 license.
85
+ This project is a Free/Libre and Open Source software released under LGPLv3
86
+ license.
@@ -23,12 +23,17 @@ module Bidify
23
23
  def configure
24
24
  @bidifiable_tags = DEFAULT_BIDIFIABLE_TAGS.dup
25
25
  @bidifiable_tags.concat(TABLE_TAGS) if @options[:with_table_support]
26
+ @bidifiable_tags.concat(@options[:including_tags]) if @options.key?(:including_tags)
27
+ @bidifiable_tags.delete_if { |tag| @options[:excluding_tags]&.include?(tag) }
28
+ @bidifiable_tags = @options[:only_tags] if @options.key?(:only_tags)
26
29
  end
27
30
 
28
31
  def bidify_recursively(html_node, options = {})
29
32
  seen_the_first_bidifiable_element = false
30
33
 
31
34
  html_node.children.each do |child_node|
35
+ next if stop_recursion_at?(child_node)
36
+
32
37
  bidify_recursively(child_node)
33
38
 
34
39
  if (options[:root] || seen_the_first_bidifiable_element) && @bidifiable_tags.include?(child_node.name)
@@ -42,5 +47,11 @@ module Bidify
42
47
  def actual_content?(node)
43
48
  node.element? || (node.text? && !node.blank?)
44
49
  end
50
+
51
+ def stop_recursion_at?(node)
52
+ return false if @options[:greedy] == true
53
+
54
+ node.has_attribute?('dir')
55
+ end
45
56
  end
46
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bidify
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
5
5
  end
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.2.0
4
+ version: 0.3.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-07-02 00:00:00.000000000 Z
11
+ date: 2023-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '1.15'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '1.15'
27
27
  description: Bidify helps to add bidirectional text support to HTML document
28
28
  email:
29
29
  - ahangarha@riseup.net
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - CHANGELOG.md
34
35
  - Gemfile
35
36
  - Gemfile.lock
36
37
  - LICENSE