asciidoctor-external-callout 0.0.6.pre.beta7 → 1.1.2

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: 910479158955009faec89ab7797f5b30c5d97aff3433c276fb6bc34d0f1e10c2
4
- data.tar.gz: e082c0a766caa8a2cd5f5f60f8063052f75ca398b2a6933afc06eb581c9c1e48
3
+ metadata.gz: 284ba079c9ce91935490ced1b9041717c3d733f1eb03cb428b75b3b85b5718e4
4
+ data.tar.gz: aca07340cfd7cf61f7afc90825c137e20934cb3905ab83a2be91e41ff589b2e1
5
5
  SHA512:
6
- metadata.gz: ce3c945787e12aef49a863250cbdab404e5a2c0ee7396c81c8a969829b724506c0c5cfec3bb42a407cac9bb017d03bb4d1979fd11d0539ee466339648f52f4a4
7
- data.tar.gz: 4bf8d47eb9008153011617d1e3438b7c8bff86d1e70a0686dd8494f543fac7dc4f72c7cd75d4c8ae02b9a95ddea30f8ad665a4f23e7a208775e9e6f6fa5dd145
6
+ metadata.gz: 6f6dd07c7042d9432d3e6f3de53fa67dc52248aa9a3cdc38f937c831edd66327081293c148601161eaf0a644cd7f7995ed0a9b1aeaa5df266f79d53e0565ff60
7
+ data.tar.gz: 854510529f76e96891b1ac7e482b984a0df273dbd97f8d84c37d85c940f86d6d5fd187aa79ff7e4c314913a10ab0b4439558dd31c9bbafcd76e2d5c6da8afa32
data/.gitignore CHANGED
@@ -8,6 +8,8 @@
8
8
  /tmp/
9
9
  /.idea
10
10
  **/sample.html
11
+ **/sample_global_search.html
12
+ **/sample.pdf
11
13
  *.gem
12
14
  /Gemfile.lock
13
15
  /.asciidoctor
data/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  Record of bug fixes, enhancements, and changes.
4
4
 
5
+ ## [1.1.2] – 2022-07-07
6
+
7
+ ### Fixed
8
+ - Code fix to stop the constants from reloading every time the extension is run. (Tidying up for execution inside the Asciidoc plugin)
9
+
10
+ ## [1.1.1] – 2022-06-23
11
+
12
+ ### Fixed
13
+ - Fixed regular expression to correctly detect new flags.
14
+
15
+ ## [1.1.0] – 2022-06-23
16
+
17
+ ### Added
18
+ - 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.
19
+ - Added the `i` flag for case-insensitive searches: (`@/text/i`). Again, don't go mad.
20
+
21
+ ## [1.0.0] – 2022-06-16
22
+
23
+ ### Added
24
+ - 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.)
25
+
5
26
  ## [0.0.6-beta6] – 2022-06-11
6
27
 
7
28
  ### Changed
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:
@@ -80,7 +89,46 @@ Or install it yourself as:
80
89
 
81
90
  ## Usage
82
91
 
83
- TODO: Write usage instructions here
92
+ To use the extension, you need to register it before calling one of the Asciidoc `convert` functions to render the output.
93
+
94
+ ```ruby
95
+ require 'asciidoctor-external-callout'
96
+ require 'asciidoctor'
97
+
98
+ Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'), safe: :unsafe, backend: :html5
99
+ ```
100
+
101
+ ## Use with the [IntelliJ Asciidoc Plugin](https://plugins.jetbrains.com/plugin/7391-asciidoc)
102
+
103
+ If you're not using the excellent Asciidoc plugin then you're really missing out.
104
+ One if it's lesser known features is that it supports Asciidoc extensions written in Ruby:
105
+
106
+ 1. Create a new folder structure in the root of your IntelliJ project called `.asciidoctor/lib`.
107
+ 2. Copy the file `asciidoctor-external-calllout.rb` from this distribution to `.asciidoctor/lib`.
108
+
109
+ Now, when you preview an Asciidoc file with the plugin enabled, external callouts will now show up in the preview.
110
+
111
+ ## Formatting
112
+
113
+ By default, the callout extension will put a single space between callouts that occur on the same line. If you want to adjust this, then you need to create a style that puts a horizontal margin between the callouts:
114
+
115
+ ```css
116
+ div.external-callout-block i.conum {
117
+ margin-left: 10px;
118
+ margin-right: 10px;
119
+ }
120
+ ```
121
+ The callout attaches a class called `external-callout-block` to each source listing it processes. You can use this to differentiate between standard callouts, and callouts written by the extension.
122
+
123
+ The extension also adds a class called `external-callout-list` to the list of definitions at the bottom of the source block. (There's probably no need to adjust the styling for this.)
124
+
125
+ Then to convert a document with a stylesheet, use something like this:
126
+
127
+ ```ruby
128
+ Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'),
129
+ safe: :unsafe, backend: :html5,
130
+ attributes: {'stylesheet' => './callout.css'}
131
+ ```
84
132
 
85
133
  ## Development
86
134
 
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["clogs-wrench-0z@icloud.com"]
10
10
 
11
11
  spec.summary = "Asciidoc extension for adding callouts without marking up the source listing block."
12
- # spec.description = "TODO: Write a longer description or delete this line."
12
+ spec.description = "If you can't add callout markers to your source listing" \
13
+ "(if you need to keep a shell script runnable for example), then use this."
13
14
  spec.homepage = "https://github.com/RayOffiah/asciidoctor-external-callout-ruby"
14
15
  spec.license = "MIT"
15
16
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -15,8 +15,11 @@ include Asciidoctor
15
15
 
16
16
  Asciidoctor::Extensions::register do
17
17
 
18
- LOCATION_TOKEN_RX = /@(\d+)|@\/([^\/]+?)\//
19
- LOCATION_TOKEN_ARRAY_RX = /^(@\d+|@\/[^\/]+?\/)((\s+@\d+)|(\s+@\/[^\/]+?\/))*$/
18
+ CALLOUT_SOURCE_BLOCK_ROLE ||= 'external-callout-block'
19
+ CALLOUT_ORDERED_LIST_ROLE ||= 'external-callout-list'
20
+
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}))*$/
20
23
 
21
24
  tree_processor do
22
25
 
@@ -37,6 +40,9 @@ Asciidoctor::Extensions::register do
37
40
 
38
41
  list.context = :colist
39
42
 
43
+ owner_block.add_role(CALLOUT_SOURCE_BLOCK_ROLE) unless owner_block.has_role?(CALLOUT_SOURCE_BLOCK_ROLE)
44
+ list.add_role(CALLOUT_ORDERED_LIST_ROLE) unless list.has_role?(CALLOUT_ORDERED_LIST_ROLE)
45
+
40
46
  end
41
47
 
42
48
  end
@@ -140,23 +146,27 @@ Asciidoctor::Extensions::register do
140
146
 
141
147
  if location.is_numeric?
142
148
 
143
- number = location.to_i
149
+ line_number = location.to_i
144
150
 
145
- if number <= owner_block.lines.length
146
- 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
147
153
  else
148
- warn "Out of range ==> #{number}"
154
+ warn "Line number out of range ==> #{line_number}"
149
155
  end
150
156
 
151
157
  else
152
158
 
153
159
  # Must be a string matcher then
154
160
 
155
- 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)
156
166
 
157
- if number != nil
167
+ if !found_line_numbers.empty?
158
168
 
159
- line_numbers << number
169
+ line_numbers = line_numbers.merge(found_line_numbers)
160
170
 
161
171
  else
162
172
  warn "Search term not found ==> #{location}"
@@ -179,9 +189,28 @@ Asciidoctor::Extensions::register do
179
189
 
180
190
  end
181
191
 
182
- def find_matching_lines(search_string, owner_block)
192
+ def find_matching_lines(search_string, global_search, case_insensitive, owner_block)
193
+
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
183
212
 
184
- owner_block.lines.index { |x| x.match(%r[#{search_string}]) }
213
+ found_lines
185
214
 
186
215
  end
187
216
 
data/lib/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Asciidoctor
4
4
  module External
5
5
  module Callout
6
- VERSION = "0.0.6-beta7"
6
+ VERSION = "1.1.2"
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: 0.0.6.pre.beta7
4
+ version: 1.1.2
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-11 00:00:00.000000000 Z
11
+ date: 2022-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -24,7 +24,8 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description:
27
+ description: If you can't add callout markers to your source listing(if you need to
28
+ keep a shell script runnable for example), then use this.
28
29
  email:
29
30
  - clogs-wrench-0z@icloud.com
30
31
  executables: []
@@ -61,9 +62,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
62
  version: 2.3.0
62
63
  required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  requirements:
64
- - - ">"
65
+ - - ">="
65
66
  - !ruby/object:Gem::Version
66
- version: 1.3.1
67
+ version: '0'
67
68
  requirements: []
68
69
  rubygems_version: 3.2.3
69
70
  signing_key: