snibbets 2.0.27 → 2.0.29

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f787f19a0ad33d36951029f1d367cb0c8d1b1f4e4b0af0725a678b8b6c55fe5
4
- data.tar.gz: 31ae62df88fbae803a93d3a50a8f3125ed9c6c58e0f3ae2f08c511d1673d6c29
3
+ metadata.gz: c514df1f69038d43d34563cc23735ccb8c3912f407a533d90aeacc5e924c81a5
4
+ data.tar.gz: bce3c77b30ee7369040fcc3af38801ad0b21a53c5f5ce7d991c4f95ec14a249e
5
5
  SHA512:
6
- metadata.gz: 76afe13255327745446d6367b2b64f1266692df02ae039442d01437af42ce87488c86c87d0e65d327552a992c1a3eb570f5e071fc5427191a880f04f34039954
7
- data.tar.gz: 3656f676bacce960fe21dfa5e0773d90e3c90059181c80e5836d36ec59709e286bd3dba914162d9b3a30a0afb35bf3e0c7036c73a724e8c609b9113d66acca68
6
+ metadata.gz: a41ac5237f863911b9950670073fb6922ebf341e1ad06650e475de18f724028edcb1589b5ffcd50c47ef8f144161ecde58c50761967e6f7a60b66586ac1c2a15
7
+ data.tar.gz: a8d3281abaa277a56e85d4e5275a68cf825fe3bb13eb5714bc43d186bd1a5ec681cf44fdea35290539fb1005c15d8dde308fe44a47295e3f46a5e4e4541f03be
data/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
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
+
22
+ ### 2.0.28
23
+
24
+ 2023-04-18 09:18
25
+
26
+ #### NEW
27
+
28
+ - `--nvultra` will open the selected snippet in nvUltra
29
+
30
+ #### IMPROVED
31
+
32
+ - Use Readline for entering info with `--paste`, allows for better editing experience
33
+ - Allow `--edit` with `--paste` to open the new snippet in your editor immediately
34
+
35
+ #### FIXED
36
+
37
+ - Code indentation with `--paste`
38
+ - Nil error when highlighting without extension
39
+ - When detecting indented code blocks, require a blank line (or start of file) before them, to avoid picking up lines within indented lists
40
+
1
41
  ### 2.0.27
2
42
 
3
43
  2023-04-17 15:54
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snibbets (2.0.27)
4
+ snibbets (2.0.29)
5
5
  mdless (~> 1.0, >= 1.0.32)
6
6
  tty-reader (~> 0.9, >= 0.9.0)
7
7
  tty-which (~> 0.5, >= 0.5.0)
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.27
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)
@@ -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
- # Returns an array of snippets. Single snippets are returned without a
97
- # title, multiple snippets get titles from header lines
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
@@ -125,7 +118,7 @@ module Snibbets
125
118
  "<block#{counter}>\n"
126
119
  end
127
120
 
128
- sans_blocks = sans_blocks.gsub(/(?mi)^((?: {4,}|\t+)\S[\S\s]*?)(?=\n\S|\Z)/) do
121
+ sans_blocks = sans_blocks.gsub(/(?mi)(?<=\n\n|\A)\n?((?: {4,}|\t+)\S[\S\s]*?)(?=\n\S|\Z)/) do
129
122
  counter += 1
130
123
  code = Regexp.last_match(1).split(/\n/)
131
124
 
@@ -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|
@@ -148,10 +158,9 @@ module Snibbets
148
158
 
149
159
  parts.each do |part|
150
160
  lines = part.split(/\n/).strip_empty
151
-
152
161
  next if lines.blocks == 0
153
162
 
154
- title = lines.count > 1 ? lines.shift.strip.sub(/[.:]$/, '') : 'Default snippet'
163
+ title = lines.count > 1 && lines[0] !~ /<block\d+>/ ? lines.shift.strip.sub(/[.:]$/, '') : 'Default snippet'
155
164
  block = lines.join("\n").gsub(/<(block\d+)>/) { code_blocks[Regexp.last_match(1)] }
156
165
 
157
166
  lang = nil
@@ -166,7 +175,7 @@ module Snibbets
166
175
 
167
176
  sections << {
168
177
  'title' => title,
169
- 'code' => code,
178
+ 'code' => code.strip_empty,
170
179
  'language' => lang
171
180
  }
172
181
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.27'
4
+ VERSION = '2.0.29'
5
5
  end
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
- if Snibbets.options[:output] == 'json'
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
- snippets.push({ 'title' => 'All snippets', 'code' => '' })
295
+ select_snippet(snippets, filepath)
296
+ end
297
+ end
298
+ end
299
+ end
306
300
 
307
- answer = Menu.menu(snippets, filename: File.basename(filepath, '.md'), title: 'Select snippet', query: @query)
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
- if answer['title'] == 'All snippets'
310
- snippets.delete_if { |s| s['title'] == 'All snippets' }
311
- if Snibbets.options[:output] == 'json'
312
- print(snippets.to_json, filepath)
313
- else
314
- header = File.basename(filepath, '.md')
315
- warn header
316
- warn '=' * header.length
317
-
318
- snippets.each do |snippet|
319
- lang = snippet['language']
320
- warn "### #{snippet['title']} ###"
321
- # warn "# #{'-' * snippet['title'].length}"
322
- print(snippet['code'], filepath, lang)
323
- puts
324
- end
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
- end
327
- elsif Snibbets.options[:output] == 'json'
328
- print(answer.to_json, filepath)
329
- else
330
- header = "#{File.basename(filepath, '.md')}: #{answer['title']}"
331
- warn header
332
- warn '-' * header.length
333
- code = answer['code']
334
- lang = answer['language']
335
- print(code, filepath, lang)
336
- end
337
- end
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snibbets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.27
4
+ version: 2.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler