snibbets 2.0.13 → 2.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/monokai.theme ADDED
@@ -0,0 +1,394 @@
1
+ {
2
+ "custom-styles": {
3
+ "C": {
4
+ "Prep. Lib": {
5
+ "selected-text-color": "#e6db74",
6
+ "text-color": "#e6db74"
7
+ }
8
+ },
9
+ "C++": {
10
+ "Qt Classes": {
11
+ "bold": false,
12
+ "selected-text-color": "#66d9ef",
13
+ "text-color": "#66d9ef"
14
+ },
15
+ "Qt Macros": {
16
+ "bold": false,
17
+ "selected-text-color": "#f92672",
18
+ "text-color": "#f92672"
19
+ },
20
+ "Qt Types": {
21
+ "bold": false,
22
+ "selected-text-color": "#66D9EF",
23
+ "text-color": "#66D9EF"
24
+ }
25
+ },
26
+ "CMake": {
27
+ "Builtin Variable": {
28
+ "selected-text-color": "#f8f8f2",
29
+ "text-color": "#f8f8f2"
30
+ },
31
+ "False Special Arg": {
32
+ "selected-text-color": "#e03232",
33
+ "text-color": "#e03232"
34
+ },
35
+ "True Special Arg": {
36
+ "selected-text-color": "#38bd38",
37
+ "text-color": "#38bd38"
38
+ }
39
+ },
40
+ "Doxygen": {
41
+ "Tags": {
42
+ "bold": false,
43
+ "selected-text-color": "#52afbf",
44
+ "text-color": "#52afbf"
45
+ },
46
+ "Word": {
47
+ "bold": false,
48
+ "selected-text-color": "#7ba822",
49
+ "text-color": "#7ba822",
50
+ "underline": true
51
+ }
52
+ },
53
+ "Diff": {
54
+ "Added line": {
55
+ "selected-text-color": "#a6e22e",
56
+ "text-color": "#a6e22e"
57
+ },
58
+ "Changed line (new)": {
59
+ "selected-text-color": "#a6e22e",
60
+ "text-color": "#a6e22e"
61
+ },
62
+ "Changed line (old)": {
63
+ "selected-text-color": "#f92672",
64
+ "text-color": "#f92672"
65
+ },
66
+ "Removed line": {
67
+ "selected-text-color": "#f92672",
68
+ "text-color": "#f92672"
69
+ }
70
+ },
71
+ "Go": {
72
+ "Builtin Function": {
73
+ "selected-text-color": "#a6e22e",
74
+ "text-color": "#a6e22e"
75
+ },
76
+ "Predeclared Identifier": {
77
+ "selected-text-color": "#ae81ff",
78
+ "text-color": "#ae81ff"
79
+ }
80
+ },
81
+ "ISO C++": {
82
+ "Attribute": {
83
+ "selected-text-color": "#f8f8f2",
84
+ "text-color": "#f8f8f2"
85
+ },
86
+ "Boost Stuff": {
87
+ "bold": false
88
+ },
89
+ "Prep. Lib": {
90
+ "selected-text-color": "#e6db74",
91
+ "text-color": "#e6db74"
92
+ },
93
+ "Standard Attribute": {
94
+ "selected-text-color": "#f8f8f2",
95
+ "text-color": "#f8f8f2"
96
+ },
97
+ "Standard Macros": {
98
+ "selected-text-color": "#f92672",
99
+ "text-color": "#f92672"
100
+ },
101
+ "Standard Suffix": {
102
+ "selected-text-color": "#f92672",
103
+ "text-color": "#f92672"
104
+ },
105
+ "UDL Numeric Suffix": {
106
+ "selected-text-color": "#f92672",
107
+ "text-color": "#f92672"
108
+ },
109
+ "UDL String Suffix": {
110
+ "selected-text-color": "#f92672",
111
+ "text-color": "#f92672"
112
+ }
113
+ },
114
+ "JSON": {
115
+ "Style_String_Key": {
116
+ "italic": false,
117
+ "selected-text-color": "#f92672",
118
+ "text-color": "#f92672"
119
+ }
120
+ },
121
+ "JavaScript": {
122
+ "Object Member": {
123
+ "selected-text-color": "#f8f8f2",
124
+ "text-color": "#f8f8f2"
125
+ },
126
+ "Substitution": {
127
+ "selected-text-color": "#f92672",
128
+ "text-color": "#f92672"
129
+ }
130
+ },
131
+ "JavaScript React (JSX)": {
132
+ "Component Tag": {
133
+ "bold": false,
134
+ "selected-text-color": "#66d9ef",
135
+ "text-color": "#66d9ef"
136
+ }
137
+ },
138
+ "Makefile": {
139
+ "FuncParam": {
140
+ "selected-text-color": "#fd971f",
141
+ "text-color": "#fd971f"
142
+ },
143
+ "Target": {
144
+ "selected-text-color": "#a6e22e",
145
+ "text-color": "#a6e22e"
146
+ },
147
+ "Variable": {
148
+ "italic": false,
149
+ "selected-text-color": "#f8f8f2",
150
+ "text-color": "#f8f8f2"
151
+ }
152
+ },
153
+ "Markdown": {
154
+ "Emphasis Text": {
155
+ "selected-text-color": "#66D9EF",
156
+ "text-color": "#66D9EF"
157
+ },
158
+ "Reference-Link ID": {
159
+ "selected-text-color": "#ae81ff",
160
+ "text-color": "#ae81ff"
161
+ },
162
+ "Reference-Link Name": {
163
+ "selected-text-color": "#ae81ff",
164
+ "text-color": "#ae81ff"
165
+ },
166
+ "Reference-Link Target": {
167
+ "selected-text-color": "#ae81ff",
168
+ "text-color": "#ae81ff"
169
+ },
170
+ "Strong Text": {
171
+ "selected-text-color": "#66d9ef",
172
+ "text-color": "#66d9ef"
173
+ }
174
+ },
175
+ "Python": {
176
+ "Import": {
177
+ "selected-text-color": "#f92672",
178
+ "text-color": "#f92672"
179
+ }
180
+ },
181
+ "Rust": {
182
+ "Definition": {
183
+ "selected-text-color": "#a6e22e",
184
+ "text-color": "#a6e22e"
185
+ },
186
+ "Lifetime": {
187
+ "selected-text-color": "#f92672",
188
+ "text-color": "#f92672"
189
+ },
190
+ "Macro": {
191
+ "selected-text-color": "#a6e22e",
192
+ "text-color": "#a6e22e"
193
+ },
194
+ "Self": {
195
+ "selected-text-color": "#fd971f",
196
+ "text-color": "#fd971f"
197
+ }
198
+ },
199
+ "TypeScript": {
200
+ "Function (Built-in)": {
201
+ "selected-text-color": "#a6e22e",
202
+ "text-color": "#a6e22e"
203
+ },
204
+ "Object Member": {
205
+ "selected-text-color": "#f8f8f2",
206
+ "text-color": "#f8f8f2"
207
+ },
208
+ "Substitution": {
209
+ "selected-text-color": "#f92672",
210
+ "text-color": "#f92672"
211
+ }
212
+ },
213
+ "TypeScript React (TSX)": {
214
+ "Component Tag": {
215
+ "bold": false,
216
+ "selected-text-color": "#66d9ef",
217
+ "text-color": "#66d9ef"
218
+ },
219
+ "Substitution": {
220
+ "selected-text-color": "#f92672",
221
+ "text-color": "#f92672"
222
+ }
223
+ }
224
+ },
225
+ "editor-colors": {
226
+ "BackgroundColor": "#272822",
227
+ "BracketMatching": "#5b5a4a",
228
+ "CodeFolding": "#3a3b32",
229
+ "CurrentLine": "#3e3d32",
230
+ "CurrentLineNumber": "#d1d931",
231
+ "IconBorder": "#272822",
232
+ "IndentationLine": "#6272a4",
233
+ "LineNumbers": "#909194",
234
+ "MarkBookmark": "#66D9EF",
235
+ "MarkBreakpointActive": "#ff5555",
236
+ "MarkBreakpointDisabled": "#bd93f9",
237
+ "MarkBreakpointReached": "#f1fa8c",
238
+ "MarkError": "#ff5555",
239
+ "MarkExecution": "#44475a",
240
+ "MarkWarning": "#ffb86c",
241
+ "ModifiedLines": "#ff473d",
242
+ "ReplaceHighlight": "#735d16",
243
+ "SavedLines": "#20e852",
244
+ "SearchHighlight": "#245676",
245
+ "Separator": "#45474e",
246
+ "SpellChecking": "#ff5555",
247
+ "TabMarker": "#6272a4",
248
+ "TemplateBackground": "#23241e",
249
+ "TemplateFocusedPlaceholder": "#22231d",
250
+ "TemplatePlaceholder": "#22231d",
251
+ "TemplateReadOnlyPlaceholder": "#262721",
252
+ "TextSelection": "#3f413e",
253
+ "WordWrapMarker": "#282a36"
254
+ },
255
+ "metadata": {
256
+ "copyright": [
257
+ "SPDX-FileCopyrightText: 2006 Wimer Hazenberg",
258
+ "SPDX-FileCopyrightText: 2020 Waqar Ahmed <waqar.17a@gmail.com>"
259
+ ],
260
+ "license": "SPDX-License-Identifier: MIT",
261
+ "name": "Monokai",
262
+ "revision": 6
263
+ },
264
+ "text-styles": {
265
+ "Alert": {
266
+ "bold": true,
267
+ "selected-text-color": "#ff5555",
268
+ "text-color": "#ff5555"
269
+ },
270
+ "Annotation": {
271
+ "selected-text-color": "#75715e",
272
+ "text-color": "#75715e"
273
+ },
274
+ "Attribute": {
275
+ "selected-text-color": "#f92672",
276
+ "text-color": "#f92672"
277
+ },
278
+ "BaseN": {
279
+ "selected-text-color": "#ae81ff",
280
+ "text-color": "#ae81ff"
281
+ },
282
+ "BuiltIn": {
283
+ "selected-text-color": "#66D9EF",
284
+ "text-color": "#66D9EF"
285
+ },
286
+ "Char": {
287
+ "selected-text-color": "#e6db74",
288
+ "text-color": "#e6db74"
289
+ },
290
+ "Comment": {
291
+ "selected-text-color": "#75715e",
292
+ "text-color": "#75715e"
293
+ },
294
+ "CommentVar": {
295
+ "selected-text-color": "#75715e",
296
+ "text-color": "#75715e"
297
+ },
298
+ "Constant": {
299
+ "selected-text-color": "#ae81ff",
300
+ "text-color": "#ae81ff"
301
+ },
302
+ "ControlFlow": {
303
+ "selected-text-color": "#f92672",
304
+ "text-color": "#f92672"
305
+ },
306
+ "DataType": {
307
+ "italic": true,
308
+ "selected-text-color": "#66d9ef",
309
+ "text-color": "#66d9ef"
310
+ },
311
+ "DecVal": {
312
+ "selected-text-color": "#ae81ff",
313
+ "text-color": "#ae81ff"
314
+ },
315
+ "Documentation": {
316
+ "selected-text-color": "#75715e",
317
+ "text-color": "#75715e"
318
+ },
319
+ "Error": {
320
+ "selected-text-color": "#ff5555",
321
+ "text-color": "#ff5555",
322
+ "underline": true
323
+ },
324
+ "Extension": {
325
+ "bold": true,
326
+ "selected-text-color": "#a6e22e",
327
+ "text-color": "#a6e22e"
328
+ },
329
+ "Float": {
330
+ "selected-text-color": "#ae81ff",
331
+ "text-color": "#ae81ff"
332
+ },
333
+ "Function": {
334
+ "selected-text-color": "#a6e22e",
335
+ "text-color": "#a6e22e"
336
+ },
337
+ "Import": {
338
+ "selected-text-color": "#f92672",
339
+ "text-color": "#f92672"
340
+ },
341
+ "Information": {
342
+ "selected-text-color": "#f1fa8c",
343
+ "text-color": "#f1fa8c"
344
+ },
345
+ "Keyword": {
346
+ "selected-text-color": "#f92672",
347
+ "text-color": "#f92672"
348
+ },
349
+ "Normal": {
350
+ "selected-text-color": "#f8f8f2",
351
+ "text-color": "#f8f8f2"
352
+ },
353
+ "Operator": {
354
+ "selected-text-color": "#f8f8f2",
355
+ "text-color": "#f8f8f2"
356
+ },
357
+ "Others": {
358
+ "selected-text-color": "#a6e22e",
359
+ "text-color": "#a6e22e"
360
+ },
361
+ "Preprocessor": {
362
+ "selected-text-color": "#f92672",
363
+ "text-color": "#f92672"
364
+ },
365
+ "RegionMarker": {
366
+ "selected-text-color": "#75715e",
367
+ "text-color": "#75715e"
368
+ },
369
+ "SpecialChar": {
370
+ "selected-text-color": "#ae81ff",
371
+ "text-color": "#ae81ff"
372
+ },
373
+ "SpecialString": {
374
+ "selected-text-color": "#e6db74",
375
+ "text-color": "#e6db74"
376
+ },
377
+ "String": {
378
+ "selected-text-color": "#e6db74",
379
+ "text-color": "#e6db74"
380
+ },
381
+ "Variable": {
382
+ "selected-text-color": "#f8f8f2",
383
+ "text-color": "#f8f8f2"
384
+ },
385
+ "VerbatimString": {
386
+ "selected-text-color": "#d8c72c",
387
+ "text-color": "#d8c72c"
388
+ },
389
+ "Warning": {
390
+ "selected-text-color": "#ff5555",
391
+ "text-color": "#ff5555"
392
+ }
393
+ }
394
+ }
data/lib/nord.theme ADDED
@@ -0,0 +1,181 @@
1
+ {
2
+ "_comments": [
3
+ "Last update: Jul 28, 2020 (revision 3)",
4
+ "This theme has been adapted from: https://www.nordtheme.com"
5
+ ],
6
+ "metadata": {
7
+ "copyright": [
8
+ "SPDX-FileCopyrightText: 2016 Arctic Ice Studio <development@arcticicestudio.com>",
9
+ "SPDX-FileCopyrightText: 2016 Sven Greb <development@svengreb.de>",
10
+ "SPDX-FileCopyrightText: 2020 Nibaldo González <nibgonz@gmail.com>"
11
+ ],
12
+ "license": "SPDX-License-Identifier: MIT",
13
+ "name": "Nord",
14
+ "revision": 3
15
+ },
16
+ "editor-colors": {
17
+ "BackgroundColor": "#2e3440",
18
+ "BracketMatching": "#4c566a",
19
+ "CodeFolding": "#434c5e",
20
+ "CurrentLine": "#3b4252",
21
+ "CurrentLineNumber": "#616e88",
22
+ "IconBorder": "#2e3440",
23
+ "IndentationLine": "#434c5e",
24
+ "LineNumbers": "#4c566a",
25
+ "MarkBookmark": "#55749a",
26
+ "MarkBreakpointActive": "#79aab9",
27
+ "MarkBreakpointDisabled": "#b48ead",
28
+ "MarkBreakpointReached": "#91a97e",
29
+ "MarkError": "#a95862",
30
+ "MarkExecution": "#4c566a",
31
+ "MarkWarning": "#d0b47d",
32
+ "ModifiedLines": "#ebcb8b",
33
+ "ReplaceHighlight": "#8e6057",
34
+ "SavedLines": "#a3be8c",
35
+ "SearchHighlight": "#5f8491",
36
+ "Separator": "#3b4252",
37
+ "SpellChecking": "#bf616a",
38
+ "TabMarker": "#3e4656",
39
+ "TemplateBackground": "#3b4252",
40
+ "TemplateFocusedPlaceholder": "#81a1c1",
41
+ "TemplatePlaceholder": "#5e81ac",
42
+ "TemplateReadOnlyPlaceholder": "#4c566a",
43
+ "TextSelection": "#4c566a",
44
+ "WordWrapMarker": "#3f4859"
45
+ },
46
+ "text-styles": {
47
+ "Alert": {
48
+ "background-color": "#3b4252",
49
+ "bold": true,
50
+ "selected-text-color": "#bf616a",
51
+ "text-color": "#bf616a"
52
+ },
53
+ "Annotation": {
54
+ "selected-text-color": "#d08770",
55
+ "text-color": "#d08770"
56
+ },
57
+ "Attribute": {
58
+ "selected-text-color": "#8fbcbb",
59
+ "text-color": "#8fbcbb"
60
+ },
61
+ "BaseN": {
62
+ "selected-text-color": "#b48ead",
63
+ "text-color": "#b48ead"
64
+ },
65
+ "BuiltIn": {
66
+ "italic": true,
67
+ "selected-text-color": "#88c0d0",
68
+ "text-color": "#88c0d0"
69
+ },
70
+ "Char": {
71
+ "selected-text-color": "#ebcb8b",
72
+ "text-color": "#ebcb8b"
73
+ },
74
+ "Comment": {
75
+ "selected-text-color": "#616e88",
76
+ "text-color": "#616e88"
77
+ },
78
+ "CommentVar": {
79
+ "selected-text-color": "#e5e9f0",
80
+ "text-color": "#e5e9f0"
81
+ },
82
+ "Constant": {
83
+ "bold": true,
84
+ "selected-text-color": "#eceff4",
85
+ "text-color": "#eceff4"
86
+ },
87
+ "ControlFlow": {
88
+ "bold": true,
89
+ "selected-text-color": "#81a1c1",
90
+ "text-color": "#81a1c1"
91
+ },
92
+ "DataType": {
93
+ "selected-text-color": "#81a1c1",
94
+ "text-color": "#81a1c1"
95
+ },
96
+ "DecVal": {
97
+ "selected-text-color": "#b48ead",
98
+ "text-color": "#b48ead"
99
+ },
100
+ "Documentation": {
101
+ "selected-text-color": "#5e81ac",
102
+ "text-color": "#5e81ac"
103
+ },
104
+ "Error": {
105
+ "selected-text-color": "#bf616a",
106
+ "text-color": "#bf616a",
107
+ "underline": true
108
+ },
109
+ "Extension": {
110
+ "bold": true,
111
+ "selected-text-color": "#8fbcbb",
112
+ "text-color": "#8fbcbb"
113
+ },
114
+ "Float": {
115
+ "selected-text-color": "#b48ead",
116
+ "text-color": "#b48ead"
117
+ },
118
+ "Function": {
119
+ "selected-text-color": "#88c0d0",
120
+ "text-color": "#88c0d0"
121
+ },
122
+ "Import": {
123
+ "selected-text-color": "#a3be8c",
124
+ "text-color": "#a3be8c"
125
+ },
126
+ "Information": {
127
+ "selected-text-color": "#ebcb8b",
128
+ "text-color": "#ebcb8b"
129
+ },
130
+ "Keyword": {
131
+ "bold": true,
132
+ "selected-text-color": "#81a1c1",
133
+ "text-color": "#81a1c1"
134
+ },
135
+ "Normal": {
136
+ "selected-text-color": "#d8dee9",
137
+ "text-color": "#d8dee9"
138
+ },
139
+ "Operator": {
140
+ "selected-text-color": "#81a1c1",
141
+ "text-color": "#81a1c1"
142
+ },
143
+ "Others": {
144
+ "selected-text-color": "#8fbcbb",
145
+ "text-color": "#8fbcbb"
146
+ },
147
+ "Preprocessor": {
148
+ "selected-text-color": "#5e81ac",
149
+ "text-color": "#5e81ac"
150
+ },
151
+ "RegionMarker": {
152
+ "background-color": "#3b4252",
153
+ "selected-text-color": "#88c0d0",
154
+ "text-color": "#88c0d0"
155
+ },
156
+ "SpecialChar": {
157
+ "selected-text-color": "#ebcb8b",
158
+ "text-color": "#ebcb8b"
159
+ },
160
+ "SpecialString": {
161
+ "selected-text-color": "#d08770",
162
+ "text-color": "#d08770"
163
+ },
164
+ "String": {
165
+ "selected-text-color": "#a3be8c",
166
+ "text-color": "#a3be8c"
167
+ },
168
+ "Variable": {
169
+ "selected-text-color": "#5e81ac",
170
+ "text-color": "#5e81ac"
171
+ },
172
+ "VerbatimString": {
173
+ "selected-text-color": "#8dae70",
174
+ "text-color": "#8dae70"
175
+ },
176
+ "Warning": {
177
+ "selected-text-color": "#bf616a",
178
+ "text-color": "#bf616a"
179
+ }
180
+ }
181
+ }
@@ -10,6 +10,8 @@ module Snibbets
10
10
  editor: nil,
11
11
  extension: 'md',
12
12
  highlight: false,
13
+ highlighter: nil,
14
+ highlight_theme: 'monokai',
13
15
  include_blockquotes: false,
14
16
  interactive: true,
15
17
  launchbar: false,
@@ -1,26 +1,46 @@
1
1
  module Snibbets
2
- class Highlight
3
- def highlight_pygments(executable, code, syntax, theme)
4
- syntax = syntax.empty? ? '-g' : "-l #{syntax}"
5
- `echo #{Shellwords.escape(code)} | #{executable} #{syntax}`
6
- end
2
+ module Highlight
3
+ class << self
4
+ def highlight_pygments(executable, code, syntax, theme)
5
+ puts [syntax, theme]
6
+ # syntax = syntax.nil? || syntax.empty? ? '-g' : "-l #{syntax}"
7
+ theme = theme.nil? || theme.empty? ? '' : ",style=#{theme}"
8
+ `echo #{Shellwords.escape(code)} | #{executable} -O full#{theme} -g` # #{theme}
9
+ end
7
10
 
8
- def highlight_skylight(executable, code, syntax, theme)
9
- return code if syntax.empty?
11
+ def highlight_skylight(executable, code, syntax, theme)
12
+ theme ||= 'monokai'
13
+ theme_file = File.join(__dir__, '..', "#{theme}.theme")
14
+ puts theme_file
15
+ theme = if File.exist?(theme_file)
16
+ "-t #{theme_file} "
17
+ else
18
+ ''
19
+ end
20
+ return code if syntax.nil? || syntax.empty?
10
21
 
11
- `echo #{Shellwords.escape(code)} | #{executable} --syntax #{syntax}`
12
- end
22
+ `echo #{Shellwords.escape(code)} | #{executable} #{theme}--syntax #{syntax}`
23
+ end
13
24
 
14
- def highlight(code, filename, theme = 'monokai')
15
- syntax = syntax_from_extension(filename)
25
+ def highlight(code, filename, theme = nil)
26
+ theme ||= Snibbets.options[:highlight_theme]
27
+ syntax = Lexers.syntax_from_extension(filename)
16
28
 
17
- skylight = TTY::Which.which('skylighting')
18
- return highlight_skylight(skylight, code, syntax, theme) unless skylight.empty?
29
+ skylight = TTY::Which.which('skylighting')
30
+ pygments = TTY::Which.which('pygmentize')
19
31
 
20
- pygments = TTY::Which.which('pygmentize')
21
- return highlight_pygments(pygments, code, syntax, theme) unless pygments.empty?
32
+ if Snibbets.options[:highlighter] =~ /^s/ && skylight
33
+ return highlight_skylight(skylight, code, syntax, theme)
34
+ elsif Snibbets.options[:highlighter] =~ /^p/ && !pygments.empty?
35
+ return highlight_pygments(pygments, code, syntax, theme)
36
+ elsif !skylight.empty?
37
+ return highlight_skylight(skylight, code, syntax, theme)
38
+ elsif !pygments.empty?
39
+ return highlight_pygments(pygments, code, syntax, theme)
40
+ end
22
41
 
23
- code
42
+ code
43
+ end
24
44
  end
25
45
  end
26
46
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require_relative 'lexers_db'
2
3
 
3
4
  module Snibbets
4
5
  # Lexer definitions
@@ -10,7 +11,7 @@ module Snibbets
10
11
 
11
12
  def build_lexers
12
13
  lex = []
13
- IO.read('lib/snibbets/lexers_db.txt').split(/\n/).each do |line|
14
+ LEXERS_DB.split(/\n/).each do |line|
14
15
  key = line.match(/(?mi)^((, )?[^,]+?)+?(?=\[)/)[0]
15
16
  keys = key.split(/,/).map(&:strip)
16
17
  value = line.match(/\[(.*?)\]/)[1]
@@ -37,7 +38,8 @@ module Snibbets
37
38
  end
38
39
 
39
40
  def syntax_from_extension(filename)
40
- ext_to_lang(filename.split(/\./)[1])
41
+ exts = filename.split(/\./)[1..-2]
42
+ ext_to_lang(exts[-1])
41
43
  end
42
44
  end
43
45
  end