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 +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +24 -1
- data/README.md +11 -3
- data/lib/asciidoctor-external-callout.rb +59 -13
- data/lib/version.rb +1 -1
- 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: 92129f0b6fe96367004f4aa8e3f44b8bdf1182e56b07f296bb1d341a9568c7a1
|
4
|
+
data.tar.gz: c342a82f9630d128c38d1b87a802aa8a59791dc4666576cea6ced8ccea99aaae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c292169bea665e64331fbd2a9e473860d26845c953c8fa64666b10a262c205cd978dc786ec31584df864c04fa59c0301ad2d00e8db218dff033ecd9320baad1
|
7
|
+
data.tar.gz: 2d571d81ea89b61250050c64ecdf6f7b94b18ca60ce9653c294d1c95fdd8fe824807791d0e98e82fa9026571569dba93daaa5a26ce439be96517ea02e6ef1888
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,30 @@
|
|
2
2
|
|
3
3
|
Record of bug fixes, enhancements, and changes.
|
4
4
|
|
5
|
-
## [1.
|
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
|
-
|
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
|
19
|
-
CALLOUT_ORDERED_LIST_ROLE
|
18
|
+
CALLOUT_SOURCE_BLOCK_ROLE ||= 'external-callout-block'
|
19
|
+
CALLOUT_ORDERED_LIST_ROLE ||= 'external-callout-list'
|
20
20
|
|
21
|
-
LOCATION_TOKEN_RX
|
22
|
-
LOCATION_TOKEN_ARRAY_RX
|
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
|
-
|
152
|
+
line_number = location.to_i
|
150
153
|
|
151
|
-
if
|
152
|
-
line_numbers << (
|
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 "
|
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
|
-
|
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
|
169
|
+
if !found_line_numbers.empty?
|
164
170
|
|
165
|
-
line_numbers
|
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
|
-
|
236
|
+
return options
|
191
237
|
|
192
238
|
end
|
193
239
|
|
data/lib/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2022-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|