auto_html 2.1.0 → 2.2.0

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: fe9d59c6aaaa2ac3a738aaceeab582872044be2d3983957e6cc3f973023fa10a
4
- data.tar.gz: 4667fc4cd2183f36a8141446050b8ab31abbbdd6ef06ae8bf547fd75a43660db
3
+ metadata.gz: b28e538bc39b96cfd089a514bf914d70d0bffa8d06a7e5da68c2511007b1ed56
4
+ data.tar.gz: 98cc74ba362f145671522fe9d5ec73e73ca3f4faf5e3aeaebaf4931f89e10c08
5
5
  SHA512:
6
- metadata.gz: b091f4972d71693b18ffb2d19ecc9fa9361d4f0787a7a75bc0c9f10aee59b7d3dc346909a741485ef7ce2e82e2c9960e5cc45d8ad38f53a0e4fed8a590bb7f46
7
- data.tar.gz: 4d79645b12e7ff1e7884f460b36c9d95496698780f2854183afdaa719b585d98f328fdb99355dc08949c7696dfb420195c1113b53e751bf0267f77a291bc2dd3
6
+ metadata.gz: d2dfb80c815dd62b04b3e04e325a4c36cd30566e9e87cc96d42316d6c1562f870f12fd2fba8398e9a9ab800e950e76ccc19b43bbf3963c1cda78b3d10aecb15a
7
+ data.tar.gz: c37a2a7df0ad7af97b4538589358ba1575ee11af8bdb804e4d5b1588f5e2563e4568816984b8ded111f1b8892bc511596a8404d41792a7a69c93bf5a0d8801fb
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AutoHtml
2
2
 
3
- AutoHtml is a collection of filters that transforms plain text into HTML code.
3
+ AutoHtml is a collection of filters that transforms plain text into HTML code. See [live demo](https://autohtml.makeme.tools).
4
4
 
5
5
  ## Installation
6
6
 
@@ -33,8 +33,8 @@ AutoHtml uses concepts found in "Pipes and Filters" processing design pattern:
33
33
 
34
34
  ```ruby
35
35
  link_filter = AutoHtml::Link.new(target: '_blank')
36
- link_filter.call('Checkout out my blog: http://rors.org')
37
- # => 'Checkout out my blog: <a target="blank" href="http://rors.org">http://rors.org</a>'
36
+ link_filter.call('Checkout out auto_html: https://github.com/dejan/auto_html')
37
+ # => 'Checkout out my blog: <a target="blank" href="https://github.com/dejan/auto_html">https://github.com/dejan/auto_html</a>'
38
38
 
39
39
  emoji_filter = AutoHtml::Emoji.new
40
40
  emoji_filter.call(':point_left: yo!')
@@ -42,14 +42,14 @@ emoji_filter.call(':point_left: yo!')
42
42
 
43
43
  # Use Pipeline to combine filters
44
44
  base_format = AutoHtml::Pipeline.new(link_filter, emoji_filter)
45
- base_format.call('Checkout out my blog: http://rors.org :point_left: yo!')
46
- # => 'Checkout out my blog: <a href="http://rors.org">http://rors.org</a> <img src="/images/emoji/unicode/1f448.png" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo!'
45
+ base_format.call('Checkout out auto_html: https://github.com/dejan/auto_html :point_left: yo!')
46
+ # => 'Checkout out my blog: <a href="https://github.com/dejan/auto_html">https://github.com/dejan/auto_html</a> <img src="/images/emoji/unicode/1f448.png" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo!'
47
47
 
48
48
  # A pipeline can be reused in another pipeline. Note that the order of filters is important - ie you want
49
49
  # `Image` before `Link` filter so that URL of the image gets transformed to `img` tag and not `a` tag.
50
50
  comment_format = AutoHtml::Pipeline.new(AutoHtml::Markdown.new, AutoHtml::Image.new, base_format)
51
- comment_format.call("Hello!\n\n Checkout out my blog: http://rors.org :point_left: yo! \n\n http://gifs.joelglovier.com/boom/booyah.gif")
52
- # => "<p>Hello!</p>\n\n<p>Checkout out my blog: <a href="<img src="http://rors.org" target="_blank">http://rors.org</a> <img src="/images/emoji/unicode/1f448.png" />" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo! </p>\n\n<p><a href="<img src="http://gifs.joelglovier.com/boom/booyah.gif" />" target="_blank"><img src="http://gifs.joelglovier.com/boom/booyah.gif" /></a></p>\n"
51
+ comment_format.call("Hello!\n\n Checkout out auto_html: https://github.com/dejan/auto_html :point_left: yo! \n\n http://gifs.joelglovier.com/boom/booyah.gif")
52
+ # => "<p>Hello!</p>\n\n<p>Checkout out my blog: <a href="<img src="https://github.com/dejan/auto_html" target="_blank">https://github.com/dejan/auto_html</a> <img src="/images/emoji/unicode/1f448.png" />" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo! </p>\n\n<p><a href="<img src="http://gifs.joelglovier.com/boom/booyah.gif" />" target="_blank"><img src="http://gifs.joelglovier.com/boom/booyah.gif" /></a></p>\n"
53
53
  ```
54
54
 
55
55
  ## Bundled filters
@@ -89,6 +89,26 @@ comment = Comment.new(text: 'Hey!')
89
89
  comment.text_html # => '<p>Hey!</p>'
90
90
  ```
91
91
 
92
+ ## Development
93
+
94
+ ### Install dependencies
95
+
96
+ ```sh
97
+ bundle install
98
+ ```
99
+
100
+ ### Run Rubocop
101
+
102
+ ```sh
103
+ rake rubocop
104
+ ```
105
+
106
+ ### Run tests
107
+
108
+ ```sh
109
+ rake spec
110
+ ```
111
+
92
112
  ## Licence
93
113
 
94
114
  AutoHtml is released under the [MIT License](https://raw.githubusercontent.com/dejan/auto_html/master/MIT-LICENSE).
@@ -7,13 +7,14 @@ require 'rexml/document'
7
7
  module AutoHtml
8
8
  # Link filter
9
9
  class Link
10
- def initialize(target: nil, rel: nil)
10
+ def initialize(target: nil, rel: nil, short_domains: false)
11
11
  @target = target
12
12
  @rel = rel
13
+ @short_domains = short_domains
13
14
  end
14
15
 
15
16
  def call(text)
16
- Rinku.auto_link(text, :all, attributes)
17
+ Rinku.auto_link(text, :all, attributes, nil, flags)
17
18
  end
18
19
 
19
20
  private
@@ -29,5 +30,9 @@ module AutoHtml
29
30
  def target_attr
30
31
  %(target="#{@target}") if @target
31
32
  end
33
+
34
+ def flags
35
+ @short_domains ? Rinku::AUTOLINK_SHORT_DOMAINS : 0
36
+ end
32
37
  end
33
38
  end
@@ -4,8 +4,8 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe AutoHtml::Image do
6
6
  it 'transforms an image link to image tag' do
7
- result = subject.call('http://rors.org/images/rails.png')
8
- expect(result).to eq('<img src="http://rors.org/images/rails.png" />')
7
+ result = subject.call('https://example.org/images/rails.png')
8
+ expect(result).to eq('<img src="https://example.org/images/rails.png" />')
9
9
  end
10
10
 
11
11
  it 'transforms image link with a param to image tag' do
@@ -30,8 +30,8 @@ RSpec.describe AutoHtml::Image do
30
30
  end
31
31
 
32
32
  it 'transforms an image link within text to image tag' do
33
- result = subject.call('Which do you prefer, this one http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG, or this one http://rors.org/images/rails.png?')
34
- expect(result).to eq('Which do you prefer, this one <img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" />, or this one <img src="http://rors.org/images/rails.png" />?')
33
+ result = subject.call('Which do you prefer, this one http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG, or this one https://example.org/images/rails.png?')
34
+ expect(result).to eq('Which do you prefer, this one <img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" />, or this one <img src="https://example.org/images/rails.png" />?')
35
35
  end
36
36
 
37
37
  it 'transforms an image link with a lot of param to image tag' do
@@ -33,21 +33,32 @@ RSpec.describe AutoHtml::Link do
33
33
  expect(result).to eq '<a href="http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0">http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0</a>'
34
34
  end
35
35
 
36
+ it 'not transforms short domain URL' do
37
+ result = subject.call('http://localhost:3000')
38
+ expect(result).to eq 'http://localhost:3000'
39
+ end
40
+
36
41
  it 'transforms with target options' do
37
42
  filter = described_class.new(target: '_blank')
38
- result = filter.call('http://rors.org')
39
- expect(result).to eq '<a href="http://rors.org" target="_blank">http://rors.org</a>'
43
+ result = filter.call('https://example.org')
44
+ expect(result).to eq '<a href="https://example.org" target="_blank">https://example.org</a>'
40
45
  end
41
46
 
42
47
  it 'transforms with rel options' do
43
48
  filter = described_class.new(rel: 'nofollow')
44
- result = filter.call('http://rors.org')
45
- expect(result).to eq '<a href="http://rors.org" rel="nofollow">http://rors.org</a>'
49
+ result = filter.call('https://example.org')
50
+ expect(result).to eq '<a href="https://example.org" rel="nofollow">https://example.org</a>'
51
+ end
52
+
53
+ it 'transforms with short_domains options' do
54
+ filter = described_class.new(short_domains: true)
55
+ result = filter.call('http://localhost:3000')
56
+ expect(result).to eq '<a href="http://localhost:3000">http://localhost:3000</a>'
46
57
  end
47
58
 
48
59
  it 'transforms with target and rel options' do
49
60
  filter = described_class.new(target: '_blank', rel: 'nofollow')
50
- result = filter.call('http://rors.org')
51
- expect(result).to eq '<a href="http://rors.org" target="_blank" rel="nofollow">http://rors.org</a>'
61
+ result = filter.call('https://example.org')
62
+ expect(result).to eq '<a href="https://example.org" target="_blank" rel="nofollow">https://example.org</a>'
52
63
  end
53
64
  end
@@ -6,14 +6,14 @@ RSpec.describe AutoHtml::Pipeline do
6
6
  subject { described_class.new(AutoHtml::SimpleFormat.new, AutoHtml::Image.new, AutoHtml::Link.new) }
7
7
 
8
8
  it 'does not transforms input when no filters provided' do
9
- input = 'Hey check out my blog => http://rors.org'
9
+ input = 'Hey check out my blog => https://example.org'
10
10
  result = described_class.new.call(input)
11
11
  expect(result).to eq input
12
12
  end
13
13
 
14
14
  it 'transforms input using provided filters' do
15
- result = subject.call 'Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org'
16
- expect(result).to eq '<p>Check the logo: <img src="http://rors.org/images/rails.png" />. Visit: <a href="http://rubyonrails.org">http://rubyonrails.org</a></p>'
15
+ result = subject.call 'Check the logo: https://example.org/images/rails.png. Visit: http://rubyonrails.org'
16
+ expect(result).to eq '<p>Check the logo: <img src="https://example.org/images/rails.png" />. Visit: <a href="http://rubyonrails.org">http://rubyonrails.org</a></p>'
17
17
  end
18
18
 
19
19
  it 'is blank if input is blank' do
@@ -4,8 +4,8 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe AutoHtml::SimpleFormat do
6
6
  it 'formats input using simple rules' do
7
- result = subject.call('Hey check out my blog => http://rors.org')
8
- expect(result).to eq '<p>Hey check out my blog => http://rors.org</p>'
7
+ result = subject.call('Hey check out my blog => https://example.org')
8
+ expect(result).to eq '<p>Hey check out my blog => https://example.org</p>'
9
9
 
10
10
  expect(subject.call("crazy\r\n cross\r platform linebreaks")).to eq "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>"
11
11
  expect(subject.call("A paragraph\n\nand another one!")).to eq "<p>A paragraph</p>\n\n<p>and another one!</p>"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dejan Simic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-04 00:00:00.000000000 Z
11
+ date: 2025-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemoji
@@ -39,75 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rinku
42
+ name: rexml
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: 3.3.9
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: 3.3.9
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 13.0.6
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 13.0.6
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.3'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.3'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec_junit_formatter
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.2'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
56
+ name: rinku
99
57
  requirement: !ruby/object:Gem::Requirement
100
58
  requirements:
101
59
  - - "~>"
102
60
  - !ruby/object:Gem::Version
103
- version: '1.23'
104
- type: :development
61
+ version: '2.0'
62
+ type: :runtime
105
63
  prerelease: false
106
64
  version_requirements: !ruby/object:Gem::Requirement
107
65
  requirements:
108
66
  - - "~>"
109
67
  - !ruby/object:Gem::Version
110
- version: '1.23'
68
+ version: '2.0'
111
69
  description: Collection of filters for transforming text into HTML code
112
70
  email: desimic@gmail.com
113
71
  executables: []
@@ -139,7 +97,7 @@ licenses:
139
97
  - MIT
140
98
  metadata:
141
99
  rubygems_mfa_required: 'true'
142
- post_install_message:
100
+ post_install_message:
143
101
  rdoc_options: []
144
102
  require_paths:
145
103
  - lib
@@ -154,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
112
  - !ruby/object:Gem::Version
155
113
  version: '0'
156
114
  requirements: []
157
- rubygems_version: 3.2.22
158
- signing_key:
115
+ rubygems_version: 3.5.20
116
+ signing_key:
159
117
  specification_version: 4
160
118
  summary: Plain text to HTML conversion
161
119
  test_files: []