asciidoctor-external-callout 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53e488dac87a1685e9450b031e44aea9ef5d265b92f974965e7b212df326b284
4
- data.tar.gz: 27559c5adc5c7daf42eb2b958ed6d96be360d6ee4a25689e726f2c42dffca8b5
3
+ metadata.gz: a6968fdcf2ef95e88f45bc923c8f971cd0ecea32fe0054b39920403d270c99ff
4
+ data.tar.gz: d9bc142aa3d6cd397cfc8e6fd6dca889e6e0e03e0546a2fc97ed8b8aea49de18
5
5
  SHA512:
6
- metadata.gz: 7b48ae24cdb081bedffb3702cd10821ac8739e52d372042dfeb851acb9d0b607d3e72afb6fd6e7cabc0be2a81647eaf50f46604ba3b0f44b5d30ea2db9616608
7
- data.tar.gz: 53cd492e35f520d503d7643723a4289abe3f88ef8f9b00607d494e1e2e0240692e58da74af6f05d0f10e365070ac24fe0d195612b29b589f8579e585eccc6797
6
+ metadata.gz: 1084e775864420eba3dad00a363068912260f8fddfeac62c3771ede801562edda9f27428ace473e364d1a4a02e673b07db1c9c8ab5153a5f88036f739104a640
7
+ data.tar.gz: 6a5b4f84193d7d41346bb71b69acc37b24d3ccdd30aae1760c0c5c437bfb68d4e4e60047c13a0c36c565ead529a815a01371aeb85a6df24ba8a70856b8b4e6af
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /tmp/
9
9
  /.idea
10
10
  **/sample.html
11
+ **/sample_global_search.html
11
12
  *.gem
12
13
  /Gemfile.lock
13
14
  /.asciidoctor
data/CHANGELOG.md CHANGED
@@ -2,7 +2,18 @@
2
2
 
3
3
  Record of bug fixes, enhancements, and changes.
4
4
 
5
- ## [1.0.0] – 22-06-16
5
+ ## [1.1.1] – 2022-06-23
6
+
7
+ ### Fixed
8
+ - Fixed regular expression to correctly detect new flags.
9
+
10
+ ## [1.1.0] – 2022-06-23
11
+
12
+ ### Added
13
+ - The text search now supports a global flag (`@/text/g`). The `g` flag will add the callout to all the lines that match the search criteria. Use wisely.
14
+ - Added the `i` flag for case-insensitive searches: (`@/text/i`). Again, don't go mad.
15
+
16
+ ## [1.0.0] – 2022-06-16
6
17
 
7
18
  ### Added
8
19
  - Added roles to the source block and the callout list so that CSS folk can pick them out to make style changes (For example, adjusting the gap between callout items in the source code block.)
data/README.md CHANGED
@@ -62,6 +62,15 @@ Two types of location token are supported:
62
62
  If you have a large listing then it may be preferable to use the text search rather than counting all the lines. It may also be preferable to use a smaller listing, as a long listing might mean that your description is a bit too general. +
63
63
  Using the text search method means that the location of the callout will move with the line; handy if you're referencing a source file that might get the occasional tweak outside your control.
64
64
 
65
+ @/_text_/g
66
+ : Works the same as the standard text search; the `g` flag means that callouts willl be added to _all_ the lines that match the search string, instead of just the first one.
67
+
68
+ @/_text_/i
69
+ : This is a case-insensitive search.
70
+
71
+ @/_text_/gi
72
+ : And of course, you can combine the two, though I'm not sure why you'd want to.
73
+
65
74
  ## Installation
66
75
 
67
76
  Add this line to your application's Gemfile:
@@ -18,8 +18,8 @@ Asciidoctor::Extensions::register do
18
18
  CALLOUT_SOURCE_BLOCK_ROLE = 'external-callout-block'
19
19
  CALLOUT_ORDERED_LIST_ROLE = 'external-callout-list'
20
20
 
21
- LOCATION_TOKEN_RX = /@(\d+)|@\/([^\/]+?)\//
22
- LOCATION_TOKEN_ARRAY_RX = /^(@\d+|@\/[^\/]+?\/)((\s+@\d+)|(\s+@\/[^\/]+?\/))*$/
21
+ LOCATION_TOKEN_RX = /@(\d+)|(@\/[^\/]+?\/(?:i|g|gi|ig){0,2})/
22
+ LOCATION_TOKEN_ARRAY_RX = /^(@\d+|@\/[^\/]+?\/(i|g|gi|ig){0,2})((\s+@\d+)|(\s+@\/[^\/]+?\/(i|g|gi|ig){0,2}))*$/
23
23
 
24
24
  tree_processor do
25
25
 
@@ -146,23 +146,27 @@ Asciidoctor::Extensions::register do
146
146
 
147
147
  if location.is_numeric?
148
148
 
149
- number = location.to_i
149
+ line_number = location.to_i
150
150
 
151
- if number <= owner_block.lines.length
152
- line_numbers << (number - 1)
151
+ if line_number.between?(1, owner_block.lines.length)
152
+ line_numbers << (line_number - 1) # Because the line number is now an array index, so -1
153
153
  else
154
- warn "Out of range ==> #{number}"
154
+ warn "Line number out of range ==> #{line_number}"
155
155
  end
156
156
 
157
157
  else
158
158
 
159
159
  # Must be a string matcher then
160
160
 
161
- number = find_matching_lines(location, owner_block)
161
+ # Is this a global search?
162
+ global_search = !!location.match(/\/([^\/]+?)\/.*g.*/)
163
+ case_insensitive = !!location.match(/\/([^\/]+?)\/.*i.*/)
164
+ search_string = location[/\/([^\/]+?)\//, 1]
165
+ found_line_numbers = find_matching_lines(search_string, global_search, case_insensitive, owner_block)
162
166
 
163
- if number != nil
167
+ if !found_line_numbers.empty?
164
168
 
165
- line_numbers << number
169
+ line_numbers = line_numbers.merge(found_line_numbers)
166
170
 
167
171
  else
168
172
  warn "Search term not found ==> #{location}"
@@ -185,9 +189,28 @@ Asciidoctor::Extensions::register do
185
189
 
186
190
  end
187
191
 
188
- def find_matching_lines(search_string, owner_block)
192
+ def find_matching_lines(search_string, global_search, case_insensitive, owner_block)
189
193
 
190
- owner_block.lines.index { |x| x.match(%r[#{search_string}]) }
194
+ if case_insensitive
195
+ string_to_match = Regexp.new(search_string, Regexp::IGNORECASE)
196
+ else
197
+ string_to_match = Regexp.new(search_string)
198
+ end
199
+ found_lines = Set.new
200
+
201
+ owner_block.lines.each_with_index do |line, index|
202
+
203
+ if line.match(string_to_match) != nil
204
+
205
+ found_lines << index
206
+
207
+ return found_lines unless global_search
208
+
209
+ end
210
+
211
+ end
212
+
213
+ found_lines
191
214
 
192
215
  end
193
216
 
data/lib/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Asciidoctor
4
4
  module External
5
5
  module Callout
6
- VERSION = "1.0.0"
6
+ VERSION = "1.1.1"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-external-callout
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Offiah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-16 00:00:00.000000000 Z
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor