asciidoctor-external-callout 1.0.0 → 1.1.4

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: 92129f0b6fe96367004f4aa8e3f44b8bdf1182e56b07f296bb1d341a9568c7a1
4
+ data.tar.gz: c342a82f9630d128c38d1b87a802aa8a59791dc4666576cea6ced8ccea99aaae
5
5
  SHA512:
6
- metadata.gz: 7b48ae24cdb081bedffb3702cd10821ac8739e52d372042dfeb851acb9d0b607d3e72afb6fd6e7cabc0be2a81647eaf50f46604ba3b0f44b5d30ea2db9616608
7
- data.tar.gz: 53cd492e35f520d503d7643723a4289abe3f88ef8f9b00607d494e1e2e0240692e58da74af6f05d0f10e365070ac24fe0d195612b29b589f8579e585eccc6797
6
+ metadata.gz: 6c292169bea665e64331fbd2a9e473860d26845c953c8fa64666b10a262c205cd978dc786ec31584df864c04fa59c0301ad2d00e8db218dff033ecd9320baad1
7
+ data.tar.gz: 2d571d81ea89b61250050c64ecdf6f7b94b18ca60ce9653c294d1c95fdd8fe824807791d0e98e82fa9026571569dba93daaa5a26ce439be96517ea02e6ef1888
data/.gitignore CHANGED
@@ -8,6 +8,9 @@
8
8
  /tmp/
9
9
  /.idea
10
10
  **/sample.html
11
+ **/sample_global_search.html
12
+ **/callout-list-block-sample.html
13
+ **/sample.pdf
11
14
  *.gem
12
15
  /Gemfile.lock
13
16
  /.asciidoctor
data/CHANGELOG.md CHANGED
@@ -2,7 +2,30 @@
2
2
 
3
3
  Record of bug fixes, enhancements, and changes.
4
4
 
5
- ## [1.0.0] – 22-06-16
5
+ ## [1.1.3] – 2022-07-07-16
6
+
7
+ ### Fixed
8
+
9
+ - The global and case-insensitive flags (ig) are now parsing correctly: using ii or gg will cause prevent the callout block from being processed. Thanks to Hakim Cassimally for finding the bug.
10
+ - Escaped slash characters were not being processed in the search. Thanks to Hakim Cassimally for finding the bug.
11
+
12
+ ## [1.1.2] – 2022-07-07
13
+
14
+ ### Fixed
15
+ - Code fix to stop the constants from reloading every time the extension is run. (Tidying up for execution inside the Asciidoc plugin)
16
+
17
+ ## [1.1.1] – 2022-06-23
18
+
19
+ ### Fixed
20
+ - Fixed regular expression to correctly detect new flags.
21
+
22
+ ## [1.1.0] – 2022-06-23
23
+
24
+ ### Added
25
+ - 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.
26
+ - Added the `i` flag for case-insensitive searches: (`@/text/i`). Again, don't go mad.
27
+
28
+ ## [1.0.0] – 2022-06-16
6
29
 
7
30
  ### Added
8
31
  - 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
@@ -53,15 +53,23 @@ Rather than tagging the code, you add a location token at the end of a list item
53
53
 
54
54
  Two types of location token are supported:
55
55
 
56
- @_number_
56
+ **@_number_**
57
57
  : This format takes a numeric value indicating the line in the source block where the callout should appear. The callouts will appear at the end of the line. Multiple callouts on the same line will have a single space between them.
58
58
 
59
-
60
- @/_text_/
59
+ **@/_text_/**
61
60
  : The text between the two slashes will be used in a regex search. A callout will be placed at the end of the first matching line.
62
61
  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
62
  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
63
 
64
+ **@/_text_/g**
65
+ : 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.
66
+
67
+ **@/_text_/i**
68
+ : This is a case-insensitive search.
69
+
70
+ **@/_text_/gi**
71
+ : And of course, you can combine the two, though I'm not sure why you'd want to.
72
+
65
73
  ## Installation
66
74
 
67
75
  Add this line to your application's Gemfile:
@@ -15,11 +15,14 @@ include Asciidoctor
15
15
 
16
16
  Asciidoctor::Extensions::register do
17
17
 
18
- CALLOUT_SOURCE_BLOCK_ROLE = 'external-callout-block'
19
- CALLOUT_ORDERED_LIST_ROLE = 'external-callout-list'
18
+ CALLOUT_SOURCE_BLOCK_ROLE ||= 'external-callout-block'
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+)|(@\/(?:\\\/|[^\/])+?\/[ig]{0,2})/
22
+ LOCATION_TOKEN_ARRAY_RX ||= /^(@\d+|@\/(?:\\\/|[^\/]|)+?\/[ig]{0,2})((\s+@\d+)|(\s+@\/(?:\\\/|[^\/]|)+?\/[ig]{0,2}))*$/
23
+
24
+ SEARCH_STRING_RX ||= /\/((?:\\\/|[^\/])+?)\//
25
+ SEARCH_OPTIONS_RX ||= /\/(?:\\\/|[^\/])+?\/([ig]{0,2})/
23
26
 
24
27
  tree_processor do
25
28
 
@@ -146,23 +149,26 @@ Asciidoctor::Extensions::register do
146
149
 
147
150
  if location.is_numeric?
148
151
 
149
- number = location.to_i
152
+ line_number = location.to_i
150
153
 
151
- if number <= owner_block.lines.length
152
- line_numbers << (number - 1)
154
+ if line_number.between?(1, owner_block.lines.length)
155
+ line_numbers << (line_number - 1) # Because the line number is now an array index, so -1
153
156
  else
154
- warn "Out of range ==> #{number}"
157
+ warn "Line number out of range ==> #{line_number}"
155
158
  end
156
159
 
157
160
  else
158
161
 
159
162
  # Must be a string matcher then
163
+ search_options = get_search_options location
160
164
 
161
- number = find_matching_lines(location, owner_block)
165
+ search_string = location[SEARCH_STRING_RX, 1]
166
+ found_line_numbers = find_matching_lines(search_string, search_options[:global_search],
167
+ search_options[:case_insensitive], owner_block)
162
168
 
163
- if number != nil
169
+ if !found_line_numbers.empty?
164
170
 
165
- line_numbers << number
171
+ line_numbers = line_numbers.merge(found_line_numbers)
166
172
 
167
173
  else
168
174
  warn "Search term not found ==> #{location}"
@@ -185,9 +191,49 @@ Asciidoctor::Extensions::register do
185
191
 
186
192
  end
187
193
 
188
- def find_matching_lines(search_string, owner_block)
194
+ def find_matching_lines(search_string, global_search, case_insensitive, owner_block)
195
+
196
+ if case_insensitive
197
+ string_to_match = Regexp.new(search_string, Regexp::IGNORECASE)
198
+ else
199
+ string_to_match = Regexp.new(search_string)
200
+ end
201
+ found_lines = Set.new
202
+
203
+ owner_block.lines.each_with_index do |line, index|
204
+
205
+ if line.match(string_to_match) != nil
206
+
207
+ found_lines << index
208
+
209
+ return found_lines unless global_search
210
+
211
+ end
212
+
213
+ end
214
+
215
+ found_lines
216
+
217
+ end
218
+
219
+ def get_search_options(location)
220
+
221
+ options = { :case_insensitive => false,
222
+ :global_search => false }
223
+
224
+ matches = location.match(SEARCH_OPTIONS_RX)
225
+
226
+ return options unless matches
227
+
228
+ # This is just for completeness, but make sure that
229
+ # none of the options are mentioned twice in the list
230
+
231
+ raise "Invalid search options: #{matches[1]}" if matches[1].match /^(.).*\1$/
232
+
233
+ options[:case_insensitive] = true if matches[1].include? 'i'
234
+ options[:global_search] = true if matches[1].include? 'g'
189
235
 
190
- owner_block.lines.index { |x| x.match(%r[#{search_string}]) }
236
+ return options
191
237
 
192
238
  end
193
239
 
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.4"
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.4
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-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor