snibbets 2.0.28 → 2.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/snibbets/string.rb +24 -14
- data/lib/snibbets/version.rb +1 -1
- data/lib/snibbets.rb +45 -42
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c514df1f69038d43d34563cc23735ccb8c3912f407a533d90aeacc5e924c81a5
|
4
|
+
data.tar.gz: bce3c77b30ee7369040fcc3af38801ad0b21a53c5f5ce7d991c4f95ec14a249e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a41ac5237f863911b9950670073fb6922ebf341e1ad06650e475de18f724028edcb1589b5ffcd50c47ef8f144161ecde58c50761967e6f7a60b66586ac1c2a15
|
7
|
+
data.tar.gz: a8d3281abaa277a56e85d4e5275a68cf825fe3bb13eb5714bc43d186bd1a5ec681cf44fdea35290539fb1005c15d8dde308fe44a47295e3f46a5e4e4541f03be
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
### 2.0.29
|
2
|
+
|
3
|
+
2023-04-18 10:45
|
4
|
+
|
5
|
+
#### NEW
|
6
|
+
|
7
|
+
- `--nvultra` will open the selected snippet in nvUltra
|
8
|
+
|
9
|
+
#### IMPROVED
|
10
|
+
|
11
|
+
- Use Readline for entering info with `--paste`, allows for better editing experience
|
12
|
+
- Allow `--edit` with `--paste` to open the new snippet in your editor immediately
|
13
|
+
- Better removal of extra leading/trailing newlines
|
14
|
+
|
15
|
+
#### FIXED
|
16
|
+
|
17
|
+
- Code indentation with `--paste`
|
18
|
+
- Nil error when highlighting without extension
|
19
|
+
- When detecting indented code blocks, require a blank line (or start of file) before them, to avoid picking up lines within indented lists
|
20
|
+
- Selecting 'All snippets' could return blank results in some cases
|
21
|
+
|
1
22
|
### 2.0.28
|
2
23
|
|
3
24
|
2023-04-18 09:18
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -157,7 +157,7 @@ Snibbet's implementation of Skylighting has limited but better-looking themes, a
|
|
157
157
|
### Usage
|
158
158
|
|
159
159
|
```
|
160
|
-
Snibbets v2.0.
|
160
|
+
Snibbets v2.0.29
|
161
161
|
|
162
162
|
Usage: snibbets [options] query
|
163
163
|
-a, --all If a file contains multiple snippets, output all of them (no menu)
|
data/lib/snibbets/string.rb
CHANGED
@@ -16,6 +16,10 @@ module Snibbets
|
|
16
16
|
replace remove_spotlight_tags
|
17
17
|
end
|
18
18
|
|
19
|
+
def strip_empty
|
20
|
+
split(/\n/).strip_empty.join("\n")
|
21
|
+
end
|
22
|
+
|
19
23
|
def remove_meta
|
20
24
|
input = dup
|
21
25
|
lines = input.split(/\n/)
|
@@ -93,22 +97,11 @@ module Snibbets
|
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
96
|
-
|
97
|
-
|
98
|
-
def snippets
|
99
|
-
content = dup.remove_meta
|
100
|
-
# If there's only one snippet, just clean it and return
|
101
|
-
# return [{ 'title' => '', 'code' => content.clean_code.strip }] unless multiple?
|
102
|
-
|
103
|
-
# Split content by ATX headers. Everything on the line after the #
|
104
|
-
# becomes the title, code is gleaned from text between that and the
|
105
|
-
# next ATX header (or end)
|
106
|
-
sections = []
|
100
|
+
def replace_blocks
|
101
|
+
sans_blocks = dup
|
107
102
|
counter = 0
|
108
103
|
code_blocks = {}
|
109
104
|
|
110
|
-
sans_blocks = content.dup
|
111
|
-
|
112
105
|
if Snibbets.options[:include_blockquotes]
|
113
106
|
sans_blocks = sans_blocks.gsub(/(?mi)(^(>.*?)(\n|$))+/) do
|
114
107
|
counter += 1
|
@@ -133,6 +126,23 @@ module Snibbets
|
|
133
126
|
"<block#{counter}>\n"
|
134
127
|
end
|
135
128
|
|
129
|
+
[sans_blocks, code_blocks]
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns an array of snippets. Single snippets are returned without a
|
133
|
+
# title, multiple snippets get titles from header lines
|
134
|
+
def snippets
|
135
|
+
content = dup.remove_meta
|
136
|
+
# If there's only one snippet, just clean it and return
|
137
|
+
# return [{ 'title' => '', 'code' => content.clean_code.strip }] unless multiple?
|
138
|
+
|
139
|
+
# Split content by ATX headers. Everything on the line after the #
|
140
|
+
# becomes the title, code is gleaned from text between that and the
|
141
|
+
# next ATX header (or end)
|
142
|
+
sections = []
|
143
|
+
|
144
|
+
sans_blocks, code_blocks = content.replace_blocks
|
145
|
+
|
136
146
|
content = []
|
137
147
|
if sans_blocks =~ /<block\d+>/
|
138
148
|
sans_blocks.each_line do |line|
|
@@ -165,7 +175,7 @@ module Snibbets
|
|
165
175
|
|
166
176
|
sections << {
|
167
177
|
'title' => title,
|
168
|
-
'code' => code,
|
178
|
+
'code' => code.strip_empty,
|
169
179
|
'language' => lang
|
170
180
|
}
|
171
181
|
end
|
data/lib/snibbets/version.rb
CHANGED
data/lib/snibbets.rb
CHANGED
@@ -282,6 +282,7 @@ module Snibbets
|
|
282
282
|
header = File.basename(filepath, '.md')
|
283
283
|
warn header
|
284
284
|
warn '-' * header.length
|
285
|
+
warn ''
|
285
286
|
code = snip['code']
|
286
287
|
lang = snip['language']
|
287
288
|
print(code, filepath, lang)
|
@@ -289,52 +290,54 @@ module Snibbets
|
|
289
290
|
end
|
290
291
|
elsif snippets.length > 1
|
291
292
|
if Snibbets.options[:all]
|
292
|
-
|
293
|
-
print(snippets.to_json, filepath)
|
294
|
-
else
|
295
|
-
|
296
|
-
snippets.each do |snippet|
|
297
|
-
lang = snippet['language']
|
298
|
-
warn "### #{snippet['title']} ###"
|
299
|
-
# warn "# #{'-' * snippet['title'].length}"
|
300
|
-
print(snippet['code'], filepath, lang)
|
301
|
-
puts
|
302
|
-
end
|
303
|
-
end
|
293
|
+
print_all(snippets, filepath)
|
304
294
|
else
|
305
|
-
|
295
|
+
select_snippet(snippets, filepath)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
306
300
|
|
307
|
-
|
301
|
+
def select_snippet(snippets, filepath)
|
302
|
+
snippets.push({ 'title' => 'All snippets', 'code' => '' })
|
303
|
+
answer = Menu.menu(snippets.dup, filename: File.basename(filepath, '.md'), title: 'Select snippet', query: @query)
|
308
304
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
305
|
+
if answer['title'] == 'All snippets'
|
306
|
+
snippets.delete_if { |s| s['title'] == 'All snippets' }
|
307
|
+
if Snibbets.options[:output] == 'json'
|
308
|
+
print(snippets.to_json, filepath)
|
309
|
+
else
|
310
|
+
header = File.basename(filepath, '.md')
|
311
|
+
warn header
|
312
|
+
warn '=' * header.length
|
313
|
+
warn ''
|
314
|
+
print_all(snippets, filepath)
|
315
|
+
end
|
316
|
+
elsif Snibbets.options[:output] == 'json'
|
317
|
+
print(answer.to_json, filepath)
|
318
|
+
else
|
319
|
+
header = "#{File.basename(filepath, '.md')}: #{answer['title']}"
|
320
|
+
warn header
|
321
|
+
warn '-' * header.length
|
322
|
+
warn ''
|
323
|
+
code = answer['code']
|
324
|
+
lang = answer['language']
|
325
|
+
print(code, filepath, lang)
|
326
|
+
end
|
327
|
+
end
|
325
328
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
329
|
+
def print_all(snippets, filepath)
|
330
|
+
if Snibbets.options[:output] == 'json'
|
331
|
+
print(snippets.to_json, filepath)
|
332
|
+
else
|
333
|
+
|
334
|
+
snippets.each do |snippet|
|
335
|
+
lang = snippet['language']
|
336
|
+
warn "### #{snippet['title']} ###"
|
337
|
+
warn ''
|
338
|
+
# warn "# #{'-' * snippet['title'].length}"
|
339
|
+
print(snippet['code'], filepath, lang)
|
340
|
+
puts
|
338
341
|
end
|
339
342
|
end
|
340
343
|
end
|