searchlink 2.3.86 → 2.3.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/searchlink +20 -19
- data/lib/searchlink/config.rb +1 -1
- data/lib/searchlink/curl/html.rb +23 -20
- data/lib/searchlink/curl/json.rb +5 -7
- data/lib/searchlink/help.rb +6 -2
- data/lib/searchlink/output.rb +8 -8
- data/lib/searchlink/parse.rb +49 -60
- data/lib/searchlink/plist/generator.rb +178 -0
- data/lib/searchlink/plist/parser.rb +263 -0
- data/lib/searchlink/plist/version.rb +5 -0
- data/lib/searchlink/plist.rb +12 -202
- data/lib/searchlink/script_plugin.rb +1 -3
- data/lib/searchlink/search.rb +1 -5
- data/lib/searchlink/searches/google.rb +3 -1
- data/lib/searchlink/searches/history.rb +5 -5
- data/lib/searchlink/searches/linkding.rb +2 -2
- data/lib/searchlink/searches/popup.rb +14 -15
- data/lib/searchlink/searches/setapp.rb +3 -1
- data/lib/searchlink/searches/shortener.rb +14 -14
- data/lib/searchlink/searches/shorteners/bitly.rb +2 -1
- data/lib/searchlink/searches/shorteners/tinyurl.rb +2 -1
- data/lib/searchlink/searches/social.rb +33 -28
- data/lib/searchlink/searches/twitter.rb +11 -12
- data/lib/searchlink/searches.rb +17 -17
- data/lib/searchlink/string.rb +50 -50
- data/lib/searchlink/url.rb +5 -2
- data/lib/searchlink/util.rb +13 -0
- data/lib/searchlink/version.rb +4 -4
- data/lib/searchlink.rb +3 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ec0f6dcca720a1630213bc1addbad3dc28cc949756b5d43ca74394b9a3a1023
|
4
|
+
data.tar.gz: 979260379965c9d0c69de75990fea6639f8cd628f4cf1c9fd7b9f9b226170761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0934cdf6a1c087e2fe2dee24bb962ca699fcfafc9848260fd0c75500c2d1531e75cb5f6a33ce4a32ab586c7594ef630a325ccca644bbf0a3a68ca659997d9ab4'
|
7
|
+
data.tar.gz: e4767b29327c7f7147efb584ea3e1dee68eafd982802b5b3375b6dddd8f3eb8e1aeb4ed444f9f8486422999eeb6f6b7f4bf94e8b051124d48c3d265867a05827
|
data/bin/searchlink
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
SILENT = ENV
|
5
|
-
|
4
|
+
SILENT = ENV.fetch("SL_SILENT", nil) =~ /false/i ? false : true
|
5
|
+
NO_CONFIRM = ENV.fetch("SL_NO_CONFIRM", nil) =~ /true/i ? true : false
|
6
|
+
$LOAD_PATH.unshift File.join(__dir__, "..")
|
6
7
|
|
7
8
|
# import
|
8
|
-
require
|
9
|
+
require "lib/searchlink"
|
9
10
|
|
10
11
|
if RUBY_VERSION.to_f > 1.9
|
11
12
|
Encoding.default_external = Encoding::UTF_8
|
@@ -20,9 +21,19 @@ SL::Searches.load_custom
|
|
20
21
|
# SL::Searches.load_searches
|
21
22
|
|
22
23
|
overwrite = true
|
23
|
-
backup = SL.config[
|
24
|
+
backup = SL.config["backup"]
|
24
25
|
|
25
|
-
if
|
26
|
+
if ARGV.empty?
|
27
|
+
input = $stdin.read.scrubup
|
28
|
+
sl.parse(input)
|
29
|
+
output = SL.output&.join
|
30
|
+
|
31
|
+
if SL.clipboard
|
32
|
+
print input
|
33
|
+
else
|
34
|
+
print output
|
35
|
+
end
|
36
|
+
else
|
26
37
|
files = []
|
27
38
|
ARGV.each do |arg|
|
28
39
|
case arg
|
@@ -30,7 +41,7 @@ if !ARGV.empty?
|
|
30
41
|
print SL.version_check
|
31
42
|
puts
|
32
43
|
sl.help_cli
|
33
|
-
$stdout.puts
|
44
|
+
$stdout.puts "See https://github.com/ttscoff/searchlink/wiki for help"
|
34
45
|
Process.exit 0
|
35
46
|
when /^(--?)?v(er(s(ion)?)?)?$/
|
36
47
|
print SL.version_check
|
@@ -46,7 +57,7 @@ if !ARGV.empty?
|
|
46
57
|
|
47
58
|
files.each do |file|
|
48
59
|
if File.exist?(file) && `file -b "#{file}"|grep -c text`.to_i.positive?
|
49
|
-
input =
|
60
|
+
input = File.read(file).scrubup
|
50
61
|
|
51
62
|
backup_file = "#{file}.bak"
|
52
63
|
backup_file = "#{file}.bak 1" if File.exist?(backup_file)
|
@@ -55,12 +66,12 @@ if !ARGV.empty?
|
|
55
66
|
FileUtils.cp(file, backup_file) if backup && overwrite
|
56
67
|
|
57
68
|
sl.parse(input)
|
58
|
-
output = SL.output&.join
|
69
|
+
output = SL.output&.join
|
59
70
|
|
60
71
|
next unless output
|
61
72
|
|
62
73
|
if overwrite
|
63
|
-
File.open(file,
|
74
|
+
File.open(file, "w") do |f|
|
64
75
|
f.puts output
|
65
76
|
end
|
66
77
|
else
|
@@ -70,14 +81,4 @@ if !ARGV.empty?
|
|
70
81
|
warn "Error reading #{file}"
|
71
82
|
end
|
72
83
|
end
|
73
|
-
else
|
74
|
-
input = $stdin.read.scrubup
|
75
|
-
sl.parse(input)
|
76
|
-
output = SL.output&.join('')
|
77
|
-
|
78
|
-
if SL.clipboard
|
79
|
-
print input
|
80
|
-
else
|
81
|
-
print output
|
82
|
-
end
|
83
84
|
end
|
data/lib/searchlink/config.rb
CHANGED
@@ -184,7 +184,7 @@ module SL
|
|
184
184
|
# hash can override existing search triggers.
|
185
185
|
config["custom_site_searches"] ||= {
|
186
186
|
"bt" => "brettterpstra.com",
|
187
|
-
"imdb" => "imdb.com"
|
187
|
+
"imdb" => "imdb.com"
|
188
188
|
}
|
189
189
|
|
190
190
|
# confirm existence of links generated from custom search replacements
|
data/lib/searchlink/curl/html.rb
CHANGED
@@ -90,7 +90,7 @@ module Curl
|
|
90
90
|
tag: tag,
|
91
91
|
source: tag_source,
|
92
92
|
attrs: attrs,
|
93
|
-
content: contents
|
93
|
+
content: contents
|
94
94
|
}
|
95
95
|
end
|
96
96
|
|
@@ -147,7 +147,7 @@ module Curl
|
|
147
147
|
output << {
|
148
148
|
type: "opengraph",
|
149
149
|
attrs: nil,
|
150
|
-
src: @meta[src]
|
150
|
+
src: @meta[src]
|
151
151
|
}
|
152
152
|
end
|
153
153
|
images = tags(%w[img source])
|
@@ -162,21 +162,21 @@ module Curl
|
|
162
162
|
image, media = s.split(/ /)
|
163
163
|
srcset << {
|
164
164
|
src: image,
|
165
|
-
media: media
|
165
|
+
media: media
|
166
166
|
}
|
167
167
|
end
|
168
168
|
end
|
169
169
|
output << {
|
170
170
|
type: "srcset",
|
171
171
|
attrs: img[:attrs],
|
172
|
-
images: srcset
|
172
|
+
images: srcset
|
173
173
|
}
|
174
174
|
end
|
175
175
|
when /img/
|
176
176
|
output << {
|
177
177
|
type: "img",
|
178
178
|
src: img[:attrs].filter { |a| a[:key] =~ /src/i }.first[:value],
|
179
|
-
attrs: img[:attrs]
|
179
|
+
attrs: img[:attrs]
|
180
180
|
}
|
181
181
|
end
|
182
182
|
end
|
@@ -189,7 +189,7 @@ module Curl
|
|
189
189
|
links = @links.nil? ? 0 : @links.count
|
190
190
|
[
|
191
191
|
%(<HTMLCurl: @code="#{@code}" @url="#{@url}" @title="#{@title}"),
|
192
|
-
%(@description=#{@description} @headers:#{headers} @meta:#{meta} @links:#{links}>)
|
192
|
+
%(@description=#{@description} @headers:#{headers} @meta:#{meta} @links:#{links}>)
|
193
193
|
].join(" ")
|
194
194
|
end
|
195
195
|
|
@@ -202,11 +202,13 @@ module Curl
|
|
202
202
|
##
|
203
203
|
def h(level = '\d')
|
204
204
|
res = []
|
205
|
-
headlines = @body.to_enum(:scan, %r{<h(?<level>#{level})(?<tag> .*?)?>(?<text>.*?)</h#{level}>}i).map
|
205
|
+
headlines = @body.to_enum(:scan, %r{<h(?<level>#{level})(?<tag> .*?)?>(?<text>.*?)</h#{level}>}i).map do
|
206
|
+
Regexp.last_match
|
207
|
+
end
|
206
208
|
headlines.each do |m|
|
207
209
|
headline = { level: m["level"] }
|
208
210
|
if m["tag"].nil?
|
209
|
-
|
211
|
+
nil
|
210
212
|
else
|
211
213
|
attrs = m["tag"].to_enum(:scan, /(?<attr>\w+)=(?<quot>["'])(?<content>.*?)\k<quot>/).map { Regexp.last_match }
|
212
214
|
attrs.each { |a| headline[a["attr"].to_sym] = a["content"] }
|
@@ -256,10 +258,10 @@ module Curl
|
|
256
258
|
|
257
259
|
attrs.map! do |a|
|
258
260
|
val = if a["key"] =~ /^(class|rel)$/
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
261
|
+
a["value"].nil? ? "" : a["value"].split(/ /)
|
262
|
+
else
|
263
|
+
a["value"]
|
264
|
+
end
|
263
265
|
{ key: a["key"], value: val }
|
264
266
|
end
|
265
267
|
end
|
@@ -268,7 +270,7 @@ module Curl
|
|
268
270
|
source: tag.to_s,
|
269
271
|
attrs: attrs,
|
270
272
|
content: tag["content"],
|
271
|
-
tags: content_tags(tag["content"])
|
273
|
+
tags: content_tags(tag["content"])
|
272
274
|
}
|
273
275
|
end
|
274
276
|
end
|
@@ -359,7 +361,7 @@ module Curl
|
|
359
361
|
title: title,
|
360
362
|
rel: rel,
|
361
363
|
text: text,
|
362
|
-
class: link_class
|
364
|
+
class: link_class
|
363
365
|
}
|
364
366
|
links << link
|
365
367
|
end
|
@@ -402,9 +404,7 @@ module Curl
|
|
402
404
|
headers = headers.nil? ? "" : headers.map { |h, v| %(-H "#{h}: #{v}") }.join(" ")
|
403
405
|
compress = compressed ? "--compressed" : ""
|
404
406
|
source = `#{@curl} -#{flags} #{compress} #{headers} '#{url}' 2>/dev/null`
|
405
|
-
if source.nil? || source.empty?
|
406
|
-
source = `#{@curl} -#{flags} #{compress} -A "#{agent}" #{headers} '#{url}' 2>/dev/null`
|
407
|
-
end
|
407
|
+
source = `#{@curl} -#{flags} #{compress} -A "#{agent}" #{headers} '#{url}' 2>/dev/null` if source.nil? || source.empty?
|
408
408
|
|
409
409
|
return false if source.nil? || source.empty?
|
410
410
|
|
@@ -425,18 +425,21 @@ module Curl
|
|
425
425
|
end
|
426
426
|
|
427
427
|
if headers["content-type"] =~ /json/
|
428
|
-
return { url: url, code: code, headers: headers, meta: nil, links: nil, head: nil, body: source.strip,
|
428
|
+
return { url: url, code: code, headers: headers, meta: nil, links: nil, head: nil, body: source.strip,
|
429
|
+
source: source.strip, body_links: nil, body_images: nil }
|
429
430
|
end
|
430
431
|
|
431
432
|
head = source.match(%r{(?<=<head>)(.*?)(?=</head>)}mi)
|
432
433
|
|
433
434
|
if head.nil?
|
434
|
-
{ url: url, code: code, headers: headers, meta: nil, links: nil, head: nil, body: source.strip,
|
435
|
+
{ url: url, code: code, headers: headers, meta: nil, links: nil, head: nil, body: source.strip,
|
436
|
+
source: source.strip, body_links: nil, body_images: nil }
|
435
437
|
else
|
436
438
|
meta = meta_tags(head[1])
|
437
439
|
links = link_tags(head[1])
|
438
440
|
body = source.match(%r{<body.*?>(.*?)</body>}mi)[1]
|
439
|
-
{ url: url, code: code, headers: headers, meta: meta, links: links, head: head[1], body: body,
|
441
|
+
{ url: url, code: code, headers: headers, meta: meta, links: links, head: head[1], body: body,
|
442
|
+
source: source.strip, body_links: body_links, body_images: body_images }
|
440
443
|
end
|
441
444
|
end
|
442
445
|
|
data/lib/searchlink/curl/json.rb
CHANGED
@@ -28,10 +28,10 @@ module Curl
|
|
28
28
|
target = json
|
29
29
|
parts.each do |part|
|
30
30
|
target = if part =~ /(?<key>[^\[]+)\[(?<int>\d+)\]/
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
target[key][int.to_i]
|
32
|
+
else
|
33
|
+
target[part]
|
34
|
+
end
|
35
35
|
end
|
36
36
|
|
37
37
|
target
|
@@ -58,9 +58,7 @@ module Curl
|
|
58
58
|
compress = compressed ? "--compressed" : ""
|
59
59
|
|
60
60
|
source = `#{@curl} -#{flags} #{compress} #{headers} #{data} "#{url}" 2>/dev/null`
|
61
|
-
if source.nil? || source.empty?
|
62
|
-
source = `#{@curl} -#{flags} #{compress} -A "#{agent}" #{headers} '#{url}' 2>/dev/null`
|
63
|
-
end
|
61
|
+
source = `#{@curl} -#{flags} #{compress} -A "#{agent}" #{headers} '#{url}' 2>/dev/null` if source.nil? || source.empty?
|
64
62
|
|
65
63
|
return false if source.nil? || source.empty?
|
66
64
|
|
data/lib/searchlink/help.rb
CHANGED
@@ -67,7 +67,9 @@ module SL
|
|
67
67
|
|
68
68
|
if SL.config["custom_site_searches"]
|
69
69
|
text += "\n-- [Custom Searches] ----------------------\n"
|
70
|
-
SL.config["custom_site_searches"].sort_by
|
70
|
+
SL.config["custom_site_searches"].sort_by do |l, _s|
|
71
|
+
l
|
72
|
+
end.each { |label, site| text += "!#{label}#{label.spacer} #{site}\n" }
|
71
73
|
end
|
72
74
|
text
|
73
75
|
end
|
@@ -80,7 +82,9 @@ module SL
|
|
80
82
|
out << '<table id="custom">'
|
81
83
|
out << "<thead><td>Shortcut</td><td>Search Type</td></thead>"
|
82
84
|
out << "<tbody>"
|
83
|
-
SL.config["custom_site_searches"].each
|
85
|
+
SL.config["custom_site_searches"].each do |label, site|
|
86
|
+
out << "<tr><td><code>!#{label}</code></td><td>#{site}</td></tr>"
|
87
|
+
end
|
84
88
|
out << "</tbody>"
|
85
89
|
out << "</table>"
|
86
90
|
out.join("\n")
|
data/lib/searchlink/output.rb
CHANGED
@@ -248,10 +248,10 @@ module SL
|
|
248
248
|
|
249
249
|
out = ""
|
250
250
|
inline = if SL.originput.split(/\n/).length > 1
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
251
|
+
false
|
252
|
+
else
|
253
|
+
SL.config["inline"] || SL.originput.split(/\n/).length == 1
|
254
|
+
end
|
255
255
|
|
256
256
|
SL.errors.each do |k, v|
|
257
257
|
next if v.empty?
|
@@ -259,10 +259,10 @@ module SL
|
|
259
259
|
v.each_with_index do |err, i|
|
260
260
|
out += "(#{k}) #{err}"
|
261
261
|
out += if inline
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
262
|
+
i == v.length - 1 ? " | " : ", "
|
263
|
+
else
|
264
|
+
"\n"
|
265
|
+
end
|
266
266
|
end
|
267
267
|
end
|
268
268
|
|
data/lib/searchlink/parse.rb
CHANGED
@@ -4,7 +4,7 @@ module SL
|
|
4
4
|
class SearchLink
|
5
5
|
# Confirm a URL with a popup if requested
|
6
6
|
def confirmed?(url)
|
7
|
-
return true
|
7
|
+
return true if !SL.config["confirm"] || NO_CONFIRM
|
8
8
|
|
9
9
|
SL::Shortener.confirm?(url)
|
10
10
|
end
|
@@ -19,16 +19,14 @@ module SL
|
|
19
19
|
|
20
20
|
parse_commands(input)
|
21
21
|
|
22
|
-
SL.config["inline"] = true if input.scan(
|
22
|
+
SL.config["inline"] = true if input.scan("](").length == 1 && input.split("\n").length == 1
|
23
23
|
SL.errors = {}
|
24
24
|
SL.report = []
|
25
25
|
SL.shortener = :none
|
26
26
|
|
27
27
|
# Check for new version
|
28
28
|
latest_version = SL.new_version?
|
29
|
-
if latest_version
|
30
|
-
SL.add_output("<!-- v#{latest_version} available, run SearchLink on the word 'update' to install. -->")
|
31
|
-
end
|
29
|
+
SL.add_output("<!-- v#{latest_version} available, run SearchLink on the word 'update' to install. -->") if latest_version
|
32
30
|
|
33
31
|
@links = {}
|
34
32
|
SL.footer = []
|
@@ -41,14 +39,14 @@ module SL
|
|
41
39
|
input.scan(/\[(.*?)\]:\s+(.*?)\n/).each { |match| @links[match[1].strip] = match[0] }
|
42
40
|
|
43
41
|
@prefix = if SL.config["prefix_random"]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
if input =~ /\[(\d{4}-)\d+\]: \S+/
|
43
|
+
Regexp.last_match(1)
|
44
|
+
else
|
45
|
+
format("%04d-", rand(9999))
|
46
|
+
end
|
47
|
+
else
|
48
|
+
""
|
49
|
+
end
|
52
50
|
|
53
51
|
@highest_marker = 0
|
54
52
|
input.scan(/^\s{,3}\[(?:#{@prefix})?(\d+)\]: /).each do
|
@@ -65,7 +63,7 @@ module SL
|
|
65
63
|
if SL.config["complete_bare"]
|
66
64
|
rx = %r{(?ix-m)(?<!\(|:\s|<)(?:
|
67
65
|
(?:https?://)(?:[\da-z.-]+)\.(?:[a-z.]{2,6})
|
68
|
-
(?:[/\w\d.\-()_
|
66
|
+
(?:[/\w\d.\-()_+=?&%]*?(?=[\s\n]|$))
|
69
67
|
)}
|
70
68
|
input.gsub!(rx) do
|
71
69
|
url_match = Regexp.last_match
|
@@ -76,17 +74,17 @@ module SL
|
|
76
74
|
if input =~ /\[\n(.*?\n)+\]\((.*?)?\)/
|
77
75
|
input.gsub!(/\[\n(((\s*(?:[-+*]|\d+\.)?\s+)*(!\S+ +)?(.*?))\n)+\]\((!\S+.*?)?\)/) do
|
78
76
|
m = Regexp.last_match
|
79
|
-
lines = m[0].split(
|
77
|
+
lines = m[0].split("\n")
|
80
78
|
lines = lines[1..-2]
|
81
79
|
lines.map do |l|
|
82
80
|
el_rx = /(\s*(?:[-+*]|\d+\.)?\s+)?(!\S+ )?(\w.*?)$/
|
83
81
|
if l =~ el_rx
|
84
82
|
els = l.match(el_rx)
|
85
83
|
search = if els[2]
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
els[2].strip
|
85
|
+
else
|
86
|
+
m[6] || "!g"
|
87
|
+
end
|
90
88
|
"#{els[1]}[#{els[3].strip}](#{search})"
|
91
89
|
else
|
92
90
|
l
|
@@ -97,7 +95,7 @@ module SL
|
|
97
95
|
|
98
96
|
# Handle links in the form of [text](url) or [text](url "title")
|
99
97
|
if input =~ /\[(.*?)\]\((.*?)\)/
|
100
|
-
lines = input.split(
|
98
|
+
lines = input.split("\n")
|
101
99
|
out = []
|
102
100
|
|
103
101
|
total_links = input.scan(/\[(.*?)\]\((.*?)\)/).length
|
@@ -146,9 +144,7 @@ module SL
|
|
146
144
|
end
|
147
145
|
|
148
146
|
counter_links += 1
|
149
|
-
unless SILENT
|
150
|
-
$stderr.print("\033[0K\rProcessed: #{counter_links} of #{total_links}, #{counter_errors} errors. ")
|
151
|
-
end
|
147
|
+
$stderr.print("\033[0K\rProcessed: #{counter_links} of #{total_links}, #{counter_errors} errors. ") unless SILENT
|
152
148
|
|
153
149
|
@link_text = this_match[1] || ""
|
154
150
|
link_info = parse_arguments(this_match[2].strip).strip || ""
|
@@ -209,10 +205,10 @@ module SL
|
|
209
205
|
m = Regexp.last_match
|
210
206
|
|
211
207
|
search_type = if m[1].nil?
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
208
|
+
SL::GoogleSearch.api_key? ? "gg" : "g"
|
209
|
+
else
|
210
|
+
m[1]
|
211
|
+
end
|
216
212
|
|
217
213
|
search_type.extract_shortener!
|
218
214
|
|
@@ -228,9 +224,7 @@ module SL
|
|
228
224
|
search_terms = @link_text if search_terms == ""
|
229
225
|
|
230
226
|
# if the input starts with a +, append it to the link text as the search terms
|
231
|
-
if search_terms.strip =~ /^\+[^+]/
|
232
|
-
search_terms = "#{@link_text} #{search_terms.strip.sub(/^\+\s*/, "")}"
|
233
|
-
end
|
227
|
+
search_terms = "#{@link_text} #{search_terms.strip.sub(/^\+\s*/, '')}" if search_terms.strip =~ /^\+[^+]/
|
234
228
|
|
235
229
|
# if the end of input contain "^", copy to clipboard instead of STDOUT
|
236
230
|
SL.clipboard = true if search_terms =~ /(!!)?\^(!!)?$/
|
@@ -270,9 +264,7 @@ module SL
|
|
270
264
|
search_terms = false
|
271
265
|
end
|
272
266
|
|
273
|
-
if search_type && !search_terms.empty?
|
274
|
-
search_type, search_terms = custom_search(search_type, search_terms)
|
275
|
-
end
|
267
|
+
search_type, search_terms = custom_search(search_type, search_terms) if search_type && !search_terms.empty?
|
276
268
|
|
277
269
|
SL.add_query(query) if query
|
278
270
|
|
@@ -292,13 +284,11 @@ module SL
|
|
292
284
|
|
293
285
|
if @url
|
294
286
|
res = confirmed?(@url)
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
@url = res if res.is_a?(String) && SL::URL.url?(res)
|
299
|
-
end
|
287
|
+
return match unless res
|
288
|
+
|
289
|
+
@url = res if res.is_a?(String) && SL::URL.url?(res)
|
300
290
|
|
301
|
-
title = SL::URL.title(@url) if SL.titleize && title
|
291
|
+
title = SL::URL.title(@url) if SL.titleize && (title.nil? || title.empty?)
|
302
292
|
|
303
293
|
@link_text = title if @link_text == "" && title
|
304
294
|
force_title = search_type =~ /def/ ? true : false
|
@@ -361,7 +351,7 @@ module SL
|
|
361
351
|
elsif SL.footer.empty?
|
362
352
|
SL.add_output input
|
363
353
|
else
|
364
|
-
last_line = input.strip.split(
|
354
|
+
last_line = input.strip.split("\n")[-1]
|
365
355
|
case last_line
|
366
356
|
when /^\[.*?\]: http/
|
367
357
|
SL.add_output "#{input.rstrip}\n"
|
@@ -473,10 +463,10 @@ module SL
|
|
473
463
|
when /^([tfilm])?@(\S+)\s*$/
|
474
464
|
type = Regexp.last_match(1)
|
475
465
|
type ||= if Regexp.last_match(2) =~ /[a-z0-9_]@[a-z0-9_.]+/i
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
466
|
+
"m"
|
467
|
+
else
|
468
|
+
"t"
|
469
|
+
end
|
480
470
|
@link_text = input.sub(/^[tfilm]/, "")
|
481
471
|
SL.add_query(query) if query
|
482
472
|
@url, title = SL::SocialSearch.social_handle(type, @link_text)
|
@@ -492,7 +482,7 @@ module SL
|
|
492
482
|
if res
|
493
483
|
if res.is_a?(String) && SL::URL.url?(res)
|
494
484
|
@url = res
|
495
|
-
title = SL::URL.title(@url)
|
485
|
+
title = SL::URL.title(@url) if SL.titleize && title == ""
|
496
486
|
end
|
497
487
|
|
498
488
|
if type =~ /sp(ell)?/
|
@@ -582,7 +572,8 @@ module SL
|
|
582
572
|
|
583
573
|
input.parse_flags! unless skip_flags
|
584
574
|
|
585
|
-
options = %w[debug country_code inline prefix_random include_titles remove_seo validate_links complete_bare
|
575
|
+
options = %w[debug country_code inline prefix_random include_titles remove_seo validate_links complete_bare
|
576
|
+
confirm]
|
586
577
|
options.each do |o|
|
587
578
|
if input =~ /^ *#{o}:\s+(\S+)$/
|
588
579
|
val = Regexp.last_match(1).strip
|
@@ -648,10 +639,10 @@ module SL
|
|
648
639
|
note = mtch[1].strip
|
649
640
|
@footnote_counter += 1
|
650
641
|
ref = if !@link_text.empty? && @link_text.scan(/\s/).empty?
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
642
|
+
@link_text
|
643
|
+
else
|
644
|
+
format("%<p>sfn%<c>04d", p: @prefix, c: @footnote_counter)
|
645
|
+
end
|
655
646
|
SL.add_footer "[^#{ref}]: #{note}"
|
656
647
|
res = "[^#{ref}]"
|
657
648
|
@cursor_difference += (SL.match_length - res.length)
|
@@ -675,12 +666,16 @@ module SL
|
|
675
666
|
search_type = "r"
|
676
667
|
tokens = v.scan(/\$term\d+[ds]?/).sort.uniq
|
677
668
|
|
678
|
-
if
|
669
|
+
if tokens.empty?
|
670
|
+
search_terms = v.gsub(/\$term[ds]?/i) do |mtch|
|
671
|
+
search_terms.downcase! if mtch =~ /d$/i
|
672
|
+
search_terms.slugify! if mtch =~ /s$/i
|
673
|
+
search_terms.url_encode
|
674
|
+
end
|
675
|
+
else
|
679
676
|
highest_token = 0
|
680
677
|
tokens.each do |token|
|
681
|
-
if token =~ /(\d+)[ds]?$/ && Regexp.last_match(1).to_i > highest_token
|
682
|
-
highest_token = Regexp.last_match(1).to_i
|
683
|
-
end
|
678
|
+
highest_token = Regexp.last_match(1).to_i if token =~ /(\d+)[ds]?$/ && Regexp.last_match(1).to_i > highest_token
|
684
679
|
end
|
685
680
|
terms_p = search_terms.split(/ +/)
|
686
681
|
if terms_p.length > highest_token
|
@@ -706,12 +701,6 @@ module SL
|
|
706
701
|
v.gsub!(/#{Regexp.escape(t) + re_down}/, replacement.url_encode)
|
707
702
|
end
|
708
703
|
search_terms = v
|
709
|
-
else
|
710
|
-
search_terms = v.gsub(/\$term[ds]?/i) do |mtch|
|
711
|
-
search_terms.downcase! if mtch =~ /d$/i
|
712
|
-
search_terms.slugify! if mtch =~ /s$/i
|
713
|
-
search_terms.url_encode
|
714
|
-
end
|
715
704
|
end
|
716
705
|
else
|
717
706
|
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|