snibbets 2.0.16 → 2.0.18

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: 7f4064d03cc2613a15f154682bd809dbcced9923cc3ce0577f17e2ae5ca1fa8f
4
- data.tar.gz: 818f92d5da7a115f280a701f71fe176ad3b3e119435e252c146ec084803521a5
3
+ metadata.gz: 7fb3029d9d0ba7c3ced5f5f0701edc62571565812b54f4d10dec34e87c10713e
4
+ data.tar.gz: 43f09bfbb8d822a5bcf5a49dca54aafe604926a9aba0f84af2d9a65b34842082
5
5
  SHA512:
6
- metadata.gz: 5cc558d53cadcf0a09bec9e22f0f67386dcfb786945df71b64ee282397f433e19bd990f20d668535768cd2669401a1f81a90cf806be0f19a6637afb67cba3643
7
- data.tar.gz: 81a674e80b35ce53dc7fdb0f5aaf5399ed0dae920f0b0c415b4dedd4d1a15c69b1ead39091f3784ffa61d44acd8244f686be511c3ca8f463bb1f34997f7f36a6
6
+ metadata.gz: e5b60a62cd24bdf2e6981db74eae3e4ca59b0e161c63cbb89c6c7fcfade6f7369ed425fcaaa059bb945d774cca02a4b12553c37dcf86e6450103306265b95970
7
+ data.tar.gz: a146b815c9c69965c6120750edd5cf0985f8cf9ca52eedaef1368b2d0ca842dfc33fc1bb4fd2b16700efca80db5a0b637dda132264e147783e53ff925995b02f
data/CHANGELOG.md.orig CHANGED
@@ -1,3 +1,30 @@
1
+ ### 2.0.18
2
+
3
+ 2023-04-16 06:57
4
+
5
+ #### FIXED
6
+
7
+ - If an invalid language (without a lexer) is supplied when using `--paste`, just use the input as the extension and tag
8
+
9
+ ### 2.0.17
10
+
11
+ 2023-04-16 06:31
12
+
13
+ #### NEW
14
+
15
+ - Languages specified in the opening fence of a code block are passed to the syntax highlighter (only affects Skylighting)
16
+
17
+ #### IMPROVED
18
+
19
+ - Add all available themes for Skylighting
20
+ - Allow a custom theme path to be provided for Skylighting by including a path in `highlight_theme` config
21
+ - Handle syntax highlighter errors, returning plain code if command fails
22
+
23
+ #### FIXED
24
+
25
+ - Disable syntax highlighting when command is being piped or redirected
26
+ - Don't syntax highlight clipboard code when using `--copy`
27
+
1
28
  ### 2.0.16
2
29
 
3
30
  2023-04-15 22:15
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snibbets (2.0.16)
4
+ snibbets (2.0.18)
5
5
  tty-which (~> 0.5, >= 0.5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -108,16 +108,6 @@ The `copy` setting determines whether the output is copied to the clipboard in a
108
108
 
109
109
  The `editor` setting is used to open the config file, and to open snippets for editing when using the `--edit` flag. This setting can be any command line utility (`code`, `subl`, `vim`, `nano`, etc.), or on macOS it can be an application name (`BBEdit`, `VS Code`, etc.) or a bundle identifier (`com.sublimetext.4`, `com.microsoft.VSCode`, etc.). If no editor is set, then the file will be opened by whatever the system default is (using `open` on macOS, `start` on Windows, or `xdg-open`on Linux).
110
110
 
111
- The `highlight` key turns on syntax highlighting. This requires that either `pygmentize` or `skyligting` is available on your system (both available via package managers like Homebrew). This feature is still in development and results may be mixed. You can also set `highlighter` to `pygments` or `skylight` to force using one highlighter over the other.
112
-
113
- You can also define a color theme with `highlight_theme`. If you're using Pygments, run `pygmentize -L styles` to see available options. If you're using Skylighting, the only currently-available options are:
114
-
115
- - breeze-dark
116
- - monokai
117
- - nord
118
- - solarized-dark
119
- - solarized-light
120
-
121
111
  The `include_blockquotes` setting determines whether blockquotes are included in the output. By default, Snibbets removes everything other than code blocks (indented or fenced) from the output it displays. But if you want to include a note that you'll see on the command line, you can put it in a block quote by preceding each line you want to preserve with a right angle bracket (`>`).
122
112
 
123
113
  The `interactive` setting determines whether menus will be displayed. This should generally be true, but if you want silent operation that just displays the best match automatically, set it to false.
@@ -126,10 +116,46 @@ The `menus` setting will determine what method is used for displaying interactiv
126
116
 
127
117
  The `name_only` key will permanently set Snibbets to only search for snippets by their filename rather than examining their contents. You can enable this at runtime using `--name-only` in the command.
128
118
 
119
+ #### Syntax Highlighting
120
+
121
+ The `highlight` key turns on syntax highlighting. This requires that either `pygmentize` or `skyligting` is available on your system (both available via package managers like Homebrew). This feature is still in development and results may be mixed. You can also set `highlighter` to `pygments` or `skylight` to force using one highlighter over the other.
122
+
123
+ Highlighting using Skylighting requires that your snippets be named with extra extensions defining the lexer to use. The last extension before `.md` (or whatever your snippet extension is set to) should be the one that the highlighter will recognize as a valid lexer, e.g. `my code.jquery.js.md`.
124
+
125
+ You can also define languages in your fenced code blocks by putting the lexer name right after the opening fence. This is used with Skylighting, but Pygments will always use it's own lexer detection. When defining multiple snippets in one file that are of different languages, this method will ensure that each one is properly highlighted.
126
+
127
+ To define a snippet as python code, for example:
128
+
129
+ ```python
130
+ class EmlServer(SMTPServer):
131
+ no = 0
132
+ def process_message(self, peer, mailfrom, rcpttos, data):
133
+ filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'),
134
+ self.no)
135
+ f = open(filename, 'w')
136
+ ```
137
+
138
+ You can also define a color scheme with `highlight_theme`. If you're using Pygments, run `pygmentize -L styles` to see available options. If you're using Skylighting, you can reference any theme in the [KDE repository]. Skylighting themes are included in Snibbets and can be referenced by their filename without `.theme`, or you can install your own themes and reference them with a full path. (I recommend `nord` when using Sylighting.)
139
+
140
+ [KDE repository]: https://github.com/KDE/syntax-highlighting/tree/master/data/themes
141
+
142
+ You can turn highlighting on or off for a single run using `--highlight` or `--no-highlight`. Syntax highlighting definitely affects copyable output, so it's automatically disabled when piping/redirecting output. When using `--copy`, the code sent to the clipboard is not highlighted.
143
+
144
+ ##### Installing a Syntax Highlighter
145
+
146
+ Snibbet's implementation of Skylighting has limited but better-looking themes, and has some lexers that Pygments lacks. However, Pygments has _more_ lexers and a wider array of themes. It also can determine the target syntax automatically better than Skylighting (which requires the syntax to be specified -- it's pulled from the extensions of your snippets), which is why Pygments is the default if it's installed and you don't configure it otherwise.
147
+
148
+ - Install [Skylighting] with [Homebrew] (`brew install pygmentize`) or [apt-get].
149
+ - Install [Pygments] using [Homebrew] (`brew install pygments`) or `pip install pygments`.
150
+
151
+ [Skylighting]: https://github.com/jgm/skylighting
152
+ [apt-get]: https://installati.one/install-skylighting-ubuntu-22-04/
153
+ [Pygments]: https://pygments.org/
154
+
129
155
  ### Usage
130
156
 
131
157
  ```
132
- Snibbets v2.0.16
158
+ Snibbets v2.0.18
133
159
 
134
160
  Usage: snibbets [options] query
135
161
  -a, --all If a file contains multiple snippets, output all of them (no menu)
@@ -142,7 +168,7 @@ Usage: snibbets [options] query
142
168
  -s, --source FOLDER Snippets folder to search
143
169
  --configure Open the configuration file in your default editor
144
170
  --[no-]blockquotes Include block quotes in output
145
- --highlight Use pygments or skylighting to syntax highlight (if installed)
171
+ --[no-]highlight Use pygments or skylighting to syntax highlight (if installed)
146
172
  --save Save the current command line options to the YAML configuration
147
173
  -h, --help Display this screen
148
174
  -v, --version Display version information
@@ -179,7 +205,7 @@ Any time you specify things like a source folder with the `--source` flag, or tu
179
205
 
180
206
  _I'm currently reworking the LaunchBar action, and it doesn't function very well at this time. I'll update when I have a chance._
181
207
 
182
- ### Installation
208
+ <!-- ### Installation
183
209
 
184
210
  The LaunchBar action can be installed simply by double clicking the `.lbaction` file in Finder. The CLI is not required for the LaunchBar action to function.
185
211
 
@@ -187,4 +213,4 @@ Once installed, run the action (type `snib` and hit return on the result) to sel
187
213
 
188
214
  ### Usage
189
215
 
190
- Type `snib` to bring the Action up, then hit Space to enter your query text. Matching files will be presented. If the selected file contains more than one snippet, a list of snippets (based on ATX headers in the file) will be presented as a child menu. Selecting a snippet and hitting return will copy the associated code block to the clipboard.
216
+ Type `snib` to bring the Action up, then hit Space to enter your query text. Matching files will be presented. If the selected file contains more than one snippet, a list of snippets (based on ATX headers in the file) will be presented as a child menu. Selecting a snippet and hitting return will copy the associated code block to the clipboard. -->
data/bin/snibbets CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby -W1
2
2
  # frozen_string_literal: true
3
3
 
4
4
  $LOAD_PATH.unshift File.join(__dir__, '..', 'lib')
@@ -6,17 +6,11 @@ require 'snibbets'
6
6
 
7
7
  module Snibbets
8
8
  class << self
9
- attr_reader :arguments, :query
9
+ attr_reader :query
10
10
 
11
11
  def run
12
- options = Snibbets.config.options
13
-
14
- @arguments = {
15
- save_config: false,
16
- edit_config: false,
17
- edit_snippet: false,
18
- paste_snippet: false
19
- }
12
+ options = Snibbets.options
13
+ arguments = Snibbets.arguments
20
14
 
21
15
  optparse = OptionParser.new do |opts|
22
16
  opts.banner = "Usage: #{File.basename(__FILE__)} [options] query"
@@ -30,7 +24,7 @@ module Snibbets
30
24
  end
31
25
 
32
26
  opts.on('-e', '--edit', 'Open the selected snippet in your configured editor') do
33
- @arguments[:edit_snippet] = true
27
+ arguments[:edit_snippet] = true
34
28
  end
35
29
 
36
30
  opts.on('-n', '--[no-]name-only', 'Only search file names, not content') do |v|
@@ -48,7 +42,7 @@ module Snibbets
48
42
  end
49
43
 
50
44
  opts.on('-p', '--paste', '--new', 'Interactively create a new snippet from clipboard contents (Mac only)') do
51
- @arguments[:paste_snippet] = true
45
+ arguments[:paste_snippet] = true
52
46
  end
53
47
 
54
48
  opts.on('-q', '--quiet', 'Skip menus and display first match') do
@@ -61,19 +55,19 @@ module Snibbets
61
55
  end
62
56
 
63
57
  opts.on('--configure', 'Open the configuration file in your default editor') do
64
- @arguments[:edit_config] = true
58
+ arguments[:edit_config] = true
65
59
  end
66
60
 
67
61
  opts.on('--[no-]blockquotes', 'Include block quotes in output') do |v|
68
62
  options[:include_blockquotes] = v
69
63
  end
70
64
 
71
- opts.on('--highlight', 'Use pygments or skylighting to syntax highlight (if installed)') do
72
- options[:highlight] = true
65
+ opts.on('--[no-]highlight', 'Use pygments or skylighting to syntax highlight (if installed)') do |v|
66
+ options[:highlight] = v
73
67
  end
74
68
 
75
69
  opts.on('--save', 'Save the current command line options to the YAML configuration') do
76
- @arguments[:save_config] = true
70
+ arguments[:save_config] = true
77
71
  end
78
72
 
79
73
  opts.on('-h', '--help', 'Display this screen') do
@@ -91,13 +85,13 @@ module Snibbets
91
85
 
92
86
  optparse.parse!
93
87
 
94
- if @arguments[:save_config]
88
+ if arguments[:save_config]
95
89
  config = Snibbets::Config.new
96
90
  config.write_config
97
91
  puts "Configuration saved to #{config.config_file}"
98
92
  end
99
93
 
100
- if @arguments[:edit_config]
94
+ if arguments[:edit_config]
101
95
  config = Snibbets::Config.new
102
96
  config.write_config
103
97
  open_snippet_in_editor(config.config_file)
@@ -110,7 +104,7 @@ module Snibbets
110
104
  Process.exit 1
111
105
  end
112
106
 
113
- if @arguments[:paste_snippet]
107
+ if arguments[:paste_snippet]
114
108
  Snibbets.new_snippet_from_clipboard
115
109
  Process.exit 0
116
110
  end
@@ -130,7 +124,7 @@ module Snibbets
130
124
  @query = CGI.unescape(@query)
131
125
 
132
126
  if @query.strip.empty?
133
- if @arguments[:save_config]
127
+ if arguments[:save_config]
134
128
  Process.exit 0
135
129
  else
136
130
  puts 'No search query'
@@ -2,7 +2,14 @@
2
2
 
3
3
  module Snibbets
4
4
  class Config
5
- attr_accessor :options, :test_editor, :config_dir, :config_file
5
+ attr_accessor :options, :arguments, :test_editor, :config_dir, :config_file
6
+
7
+ DEFAULT_ARGUMENTS = {
8
+ save_config: false,
9
+ edit_config: false,
10
+ edit_snippet: false,
11
+ paste_snippet: false
12
+ }.freeze
6
13
 
7
14
  DEFAULT_OPTIONS = {
8
15
  all: false,
@@ -28,6 +35,7 @@ module Snibbets
28
35
  @options = DEFAULT_OPTIONS.merge(custom_config)
29
36
  @options[:editor] ||= best_editor
30
37
  @options[:menus] ||= best_menu
38
+ @arguments = DEFAULT_ARGUMENTS.dup
31
39
  @test_editor = nil
32
40
 
33
41
  write_config unless @options.equal?(custom_config)
@@ -1,16 +1,34 @@
1
1
  module Snibbets
2
2
  module Highlight
3
3
  class << self
4
+ def run_command_with_input(*cmd, input: nil, fallback: nil)
5
+ stdout, _stderr, status = Open3.capture3(*cmd, stdin_data: input)
6
+ if status.success?
7
+ stdout
8
+ elsif fallback.nil?
9
+ input
10
+ else
11
+ run_command_with_input(fallback, input: input, fallback: nil)
12
+ end
13
+ end
14
+
4
15
  def highlight_pygments(executable, code, syntax, theme)
5
- puts [syntax, theme]
6
- # syntax = syntax.nil? || syntax.empty? ? '-g' : "-l #{syntax}"
16
+ syntax = syntax.nil? || syntax.empty? ? '-g' : "-l #{syntax}"
7
17
  theme = theme.nil? || theme.empty? ? '' : ",style=#{theme}"
8
- `echo #{Shellwords.escape(code)} | #{executable} -O full#{theme} -g` # #{theme}
18
+ command = "#{executable} -O full#{theme} #{syntax}"
19
+ fallback = "#{executable} -O full#{theme} -g"
20
+ run_command_with_input(command, input: code, fallback: fallback)
9
21
  end
10
22
 
11
23
  def highlight_skylight(executable, code, syntax, theme)
12
- theme ||= 'monokai'
13
- theme_file = File.join(__dir__, '..', "#{theme}.theme")
24
+ theme ||= 'nord'
25
+ theme_file = if theme =~ %r{^[/~].*?(\.theme)?$}
26
+ theme = theme.sub(/(\.theme)?$/, '.theme')
27
+ File.expand_path(theme)
28
+ else
29
+ theme = theme.sub(/\.theme$/, '')
30
+ File.join(__dir__, '..', 'themes', "#{theme}.theme")
31
+ end
14
32
 
15
33
  theme = if File.exist?(theme_file)
16
34
  "-t #{theme_file} "
@@ -19,23 +37,28 @@ module Snibbets
19
37
  end
20
38
  return code if syntax.nil? || syntax.empty?
21
39
 
22
- `echo #{Shellwords.escape(code)} | #{executable} #{theme}--syntax #{syntax}`
40
+ run_command_with_input("#{executable} #{theme}--syntax #{syntax}", input: code)
41
+ # `echo #{Shellwords.escape(code)} | #{executable} #{theme}--syntax #{syntax}`
23
42
  end
24
43
 
25
- def highlight(code, filename, theme = nil)
26
- theme ||= Snibbets.options[:highlight_theme]
27
- syntax = Lexers.syntax_from_extension(filename)
44
+ def highlight(code, filename, syntax, theme = nil)
45
+ return code unless $stdout.isatty
46
+
47
+ theme ||= Snibbets.options[:highlight_theme] || 'monokai'
48
+ syntax ||= Lexers.syntax_from_extension(filename)
49
+
50
+ return code if ['text'].include?(syntax)
28
51
 
29
52
  skylight = TTY::Which.which('skylighting')
30
53
  pygments = TTY::Which.which('pygmentize')
31
54
 
32
- if Snibbets.options[:highlighter] =~ /^s/ && skylight
55
+ if Snibbets.options[:highlighter] =~ /^s/ && !skylight.nil?
33
56
  return highlight_skylight(skylight, code, syntax, theme)
34
- elsif Snibbets.options[:highlighter] =~ /^p/ && !pygments.empty?
57
+ elsif Snibbets.options[:highlighter] =~ /^p/ && !pygments.nil?
35
58
  return highlight_pygments(pygments, code, syntax, theme)
36
- elsif !skylight.empty?
59
+ elsif !skylight.nil?
37
60
  return highlight_skylight(skylight, code, syntax, theme)
38
- elsif !pygments.empty?
61
+ elsif !pygments.nil?
39
62
  return highlight_pygments(pygments, code, syntax, theme)
40
63
  end
41
64
 
@@ -29,12 +29,12 @@ module Snibbets
29
29
 
30
30
  def ext_to_lang(ext)
31
31
  matches = lexers.select { |lex| lex[:extensions].map(&:downcase).include?(ext.downcase) }
32
- matches.map { |lex| lex[:lexer] }.first
32
+ matches.map { |lex| lex[:lexer] }.first || ext
33
33
  end
34
34
 
35
35
  def lang_to_ext(lexer)
36
36
  matches = lexers.select { |lex| lex[:lexer] == lexer || lex[:aliases].map(&:downcase).include?(lexer.downcase) }
37
- matches.map { |lex| lex[:extensions].first }.first
37
+ matches.map { |lex| lex[:extensions].first }.first || lexer
38
38
  end
39
39
 
40
40
  def syntax_from_extension(filename)
@@ -117,9 +117,11 @@ module Snibbets
117
117
  end
118
118
  end
119
119
 
120
- sans_blocks = sans_blocks.gsub(/^(`{3,})(\w+)?\s*\n(.*?)\n\1/m) do
120
+ sans_blocks = sans_blocks.gsub(/^(`{3,})(\s*\w+)?\s*\n(.*?)\n\1/m) do
121
121
  counter += 1
122
- code_blocks["block#{counter}"] = Regexp.last_match(3)
122
+ lang = Regexp.last_match(2)
123
+ lang = "<lang:#{lang.strip}>\n" if lang
124
+ code_blocks["block#{counter}"] = "#{lang}#{Regexp.last_match(3)}"
123
125
  "<block#{counter}>\n"
124
126
  end
125
127
 
@@ -153,13 +155,20 @@ module Snibbets
153
155
  title = lines.count > 1 ? lines.shift.strip.sub(/[.:]$/, '') : 'Default snippet'
154
156
  block = lines.join("\n").gsub(/<(block\d+)>/) { code_blocks[Regexp.last_match(1)] }
155
157
 
158
+ lang = nil
159
+ if block =~ /<lang:(.*?)>/
160
+ lang = Regexp.last_match(1)
161
+ block.gsub!(/<lang:.*?>\n/, '')
162
+ end
163
+
156
164
  code = block.clean_code
157
165
 
158
166
  next unless code && !code.empty?
159
167
 
160
168
  sections << {
161
169
  'title' => title,
162
- 'code' => code
170
+ 'code' => code,
171
+ 'language' => lang
163
172
  }
164
173
  end
165
174
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.16'
4
+ VERSION = '2.0.18'
5
5
  end
data/lib/snibbets.rb CHANGED
@@ -8,6 +8,7 @@ require 'shellwords'
8
8
  require 'yaml'
9
9
  require 'fileutils'
10
10
  require 'tty-which'
11
+ require 'open3'
11
12
  require_relative 'snibbets/version'
12
13
  require_relative 'snibbets/config'
13
14
  require_relative 'snibbets/which'
@@ -29,6 +30,10 @@ module Snibbets
29
30
  def options
30
31
  @options = config.options
31
32
  end
33
+
34
+ def arguments
35
+ @arguments = config.arguments
36
+ end
32
37
  end
33
38
  end
34
39
 
@@ -152,8 +157,10 @@ module Snibbets
152
157
  printf 'What language(s) does it use (separate with spaces, full names or file extensions will work)? '
153
158
  input = $stdin.gets.chomp
154
159
  langs = input.split(/ +/).map(&:strip) unless input.empty?
155
- exts = langs.map { |lang| Lexers.lang_to_ext(lang) }
156
- tags = langs.map { |lang| Lexers.ext_to_lang(lang) }.concat(langs).sort.uniq
160
+ exts = langs.map { |lang| Lexers.lang_to_ext(lang) }.delete_if(&:nil?)
161
+ tags = langs.map { |lang| Lexers.ext_to_lang(lang) }.concat(langs).delete_if(&:nil?).sort.uniq
162
+
163
+ exts = langs if exts.empty?
157
164
 
158
165
  filename = "#{title}.#{exts.join('.')}.#{Snibbets.options[:extension]}"
159
166
 
@@ -234,7 +241,7 @@ module Snibbets
234
241
  input = IO.read(filepath)
235
242
  end
236
243
 
237
- if @arguments[:edit_snippet]
244
+ if Snibbets.arguments[:edit_snippet]
238
245
  open_snippet_in_editor(filepath)
239
246
  Process.exit 0
240
247
  end
@@ -246,30 +253,30 @@ module Snibbets
246
253
  Process.exit 0
247
254
  elsif snippets.length == 1 || !Snibbets.options[:interactive]
248
255
  if Snibbets.options[:output] == 'json'
249
- print(snippets.to_json)
256
+ print(snippets.to_json, filepath)
250
257
  else
251
258
  snippets.each do |snip|
252
259
  header = File.basename(filepath, '.md')
253
260
  warn header
254
261
  warn '-' * header.length
255
262
  code = snip['code']
256
- code = Highlight.highlight(code, filepath) if Snibbets.options[:highlight]
257
- print(code)
263
+ lang = snip['language']
264
+ print(code, filepath, lang)
258
265
  end
259
266
  end
260
267
  elsif snippets.length > 1
261
268
  if Snibbets.options[:all]
262
269
  if Snibbets.options[:output] == 'json'
263
- print(snippets.to_json)
270
+ print(snippets.to_json, filepath)
264
271
  else
265
- output = []
272
+
266
273
  snippets.each do |snippet|
267
- output << snippet['title']
268
- output << '-' * snippet['title'].length
269
- output << snippet['code']
270
- output << "\n"
274
+ lang = snippet['language']
275
+ warn "# #{snippet['title']}"
276
+ # warn "# #{'-' * snippet['title'].length}"
277
+ print(snippet['code'], filepath, lang)
278
+ puts
271
279
  end
272
- print(output.join("\n"))
273
280
  end
274
281
  else
275
282
  snippets.push({ 'title' => 'All snippets', 'code' => '' })
@@ -277,39 +284,44 @@ module Snibbets
277
284
  answer = Menu.menu(snippets, filename: File.basename(filepath, '.md'), title: 'Select snippet', query: @query)
278
285
 
279
286
  if answer['title'] == 'All snippets'
280
- snippets.delete_if { |s| s['title'] == 'All snippets'}
287
+ snippets.delete_if { |s| s['title'] == 'All snippets' }
281
288
  if Snibbets.options[:output] == 'json'
282
- print(snippets.to_json)
289
+ print(snippets.to_json, filepath)
283
290
  else
284
291
  header = File.basename(filepath, '.md')
285
292
  warn header
286
293
  warn '=' * header.length
287
- output = []
294
+
288
295
  snippets.each do |snippet|
289
- output << snippet['title']
290
- output << '-' * snippet['title'].length
291
- output << snippet['code']
292
- output << "\n"
296
+ lang = snippet['language']
297
+ warn "# #{snippet['title']}"
298
+ # warn "# #{'-' * snippet['title'].length}"
299
+ print(snippet['code'], filepath, lang)
300
+ puts
293
301
  end
294
- print(output.join("\n"))
302
+
295
303
  end
296
304
  elsif Snibbets.options[:output] == 'json'
297
- print(answer.to_json)
305
+ print(answer.to_json, filepath)
298
306
  else
299
307
  header = "#{File.basename(filepath, '.md')}: #{answer['title']}"
300
308
  warn header
301
309
  warn '-' * header.length
302
310
  code = answer['code']
303
- code = Highlight.highlight(code, filepath) if Snibbets.options[:highlight]
304
- print(code)
311
+ lang = answer['language']
312
+ print(code, filepath, lang)
305
313
  end
306
314
  end
307
315
  end
308
316
  end
309
317
  end
310
318
 
311
- def print(output)
312
- $stdout.puts(output)
319
+ def print(output, filepath, syntax = nil)
320
+ if Snibbets.options[:highlight] && Snibbets.options[:output] == 'raw'
321
+ $stdout.puts(Highlight.highlight(output, filepath, syntax))
322
+ else
323
+ $stdout.puts(output)
324
+ end
313
325
  if Snibbets.options[:copy]
314
326
  OS.copy(output)
315
327
  $stderr.puts "Copied to clipboard"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snibbets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.16
4
+ version: 2.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -210,9 +210,6 @@ files:
210
210
  - Rakefile
211
211
  - bin/snibbets
212
212
  - buildnotes.md
213
- - lib/breeze-dark.theme
214
- - lib/monokai.theme
215
- - lib/nord.theme
216
213
  - lib/snibbets.rb
217
214
  - lib/snibbets/array.rb
218
215
  - lib/snibbets/config.rb
@@ -225,8 +222,6 @@ files:
225
222
  - lib/snibbets/string.rb
226
223
  - lib/snibbets/version.rb
227
224
  - lib/snibbets/which.rb
228
- - lib/solarized-dark.theme
229
- - lib/solarized-light.theme
230
225
  - snibbets.gemspec
231
226
  homepage: https://github.com/ttscoff/snibbets
232
227
  licenses: