Skip to content

Commit b7f2568

Browse files
committed
Refactored search options error handling.
1 parent 98dd2de commit b7f2568

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,21 @@ Rather than tagging the code, you add a location token at the end of a list item
5353

5454
Two types of location token are supported:
5555

56-
@_number_
56+
**@_number_**
5757
: 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.
5858

59-
60-
@/_text_/
59+
**@/_text_/**
6160
: 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.
6261
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. +
6362
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.
6463

65-
@/_text_/g
64+
**@/_text_/g**
6665
: 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.
6766

68-
@/_text_/i
67+
**@/_text_/i**
6968
: This is a case-insensitive search.
7069

71-
@/_text_/gi
70+
**@/_text_/gi**
7271
: And of course, you can combine the two, though I'm not sure why you'd want to.
7372

7473
## Installation

lib/asciidoctor-external-callout.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ def get_search_options(location)
228228
# This is just for completeness, but make sure that
229229
# none of the options are mentioned twice in the list
230230

231-
match_array = matches[1].split ""
232-
raise "Invalid search options: #{matches[1]}" if match_array.uniq.length != match_array.length
231+
raise "Invalid search options: #{matches[1]}" if matches[1].match /^(.).*\1$/
233232

234233
options[:case_insensitive] = true if matches[1].include? 'i'
235234
options[:global_search] = true if matches[1].include? 'g'

0 commit comments

Comments
 (0)