mdless 2.1.9 → 2.1.10

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: 7b6335a8f0eb1e43af37924810a1e8e6b94f5b2da35b745824f3ce735536777d
4
- data.tar.gz: 54643d669cfef096d92405e4b1ed2a216c749a67c3fb2f03dc32ad91e7a5f98a
3
+ metadata.gz: 4dc58e8318fcc9ffc8a4b148f902a71bc5ef7179098b2b58f210cb1f2e4e0bc3
4
+ data.tar.gz: 0c57011d06d423819b0766b77813134af58c85d539fcd177eb5eff08c55ea635
5
5
  SHA512:
6
- metadata.gz: 8a3d3fc7ee471da0cd3b882deba060a19728492a2493c06cca461029ce7d664940e8e0f602a324c71ede7d8e0b617365e7375cb4702cd7b19a91d440fda32a24
7
- data.tar.gz: be3fc65aca571dcc96af250f8bc0faf0e5c8be3a7ed1a2b30229fd5fd501e6087a8990bcc43f5d8f60b21599167833f55381a759a54e7765a3be4db729e16de4
6
+ metadata.gz: 6161f939a995dde611d4c8ce6dbdf75a97a4c42f051f24c2486812e994b74c5eaf67548c4f308c5b01f64df9b00cc6c1ba2699928e788817e5a8f38c5c09772e
7
+ data.tar.gz: b63230e50bf1c9b8e4e502282928c3d3d56867269a1c61abe73a0e0b3c3ad2b6b174f7767a046c858210a606084d3c41f6dda15852ede26f58ae97a8026b1b13
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 2.1.10
2
+ : Spinner while processing to indicate working
3
+ : Image links can now be converted to reference format, with correct coloring
4
+ : Render image links before reference link conversion
5
+
1
6
  2.1.9
2
7
  : Code block prefix configurable, can be left empty to make more copyable code blocks
3
8
  : Remove empty lines from block quotes
@@ -358,25 +358,6 @@ module Redcarpet
358
358
  "#{pre_element}#{color('highlight')}#{text}#{xc}#{post_element}"
359
359
  end
360
360
 
361
- def color_image_tag(link, title, alt_text)
362
- [
363
- color('image bang'),
364
- '!',
365
- color('image brackets'),
366
- '[',
367
- color('image title'),
368
- alt_text,
369
- color('image brackets'),
370
- '](',
371
- color('image url'),
372
- link,
373
- title.nil? ? '' : %( "#{title}"),
374
- color('image brackets'),
375
- ')',
376
- xc,
377
- ].join
378
- end
379
-
380
361
  def image(link, title, alt_text)
381
362
  "<<img>>#{link}||#{title}||#{alt_text}<</img>>"
382
363
  end
@@ -404,6 +385,37 @@ module Redcarpet
404
385
  ].join
405
386
  end
406
387
 
388
+ def color_image_tag(link, title, alt_text)
389
+ image = [
390
+ color('image brackets'),
391
+ '[',
392
+ color('image title'),
393
+ alt_text,
394
+ color('image brackets'),
395
+ '](',
396
+ color('image url'),
397
+ link,
398
+ title.nil? ? '' : %( "#{title}"),
399
+ color('image brackets'),
400
+ ')'
401
+ ].join
402
+
403
+ @@links << {
404
+ link: image,
405
+ url: link,
406
+ title: title,
407
+ content: alt_text,
408
+ image: true
409
+ }
410
+
411
+ [
412
+ color('image bang'),
413
+ '!',
414
+ image,
415
+ xc
416
+ ].join
417
+ end
418
+
407
419
  def color_link_reference(link, idx, content)
408
420
  [
409
421
  pre_element,
@@ -422,7 +434,7 @@ module Redcarpet
422
434
  ].join
423
435
  end
424
436
 
425
- def color_reference_link(link, title, content)
437
+ def color_reference_link(link, title, content, image: false)
426
438
  [
427
439
  color('link brackets'),
428
440
  '[',
@@ -432,13 +444,31 @@ module Redcarpet
432
444
  ']:',
433
445
  color('text'),
434
446
  ' ',
435
- color('link url'),
447
+ image ? color('image url') : color('link url'),
436
448
  link,
437
449
  title.nil? ? '' : %( "#{title}"),
438
450
  xc
439
451
  ].join
440
452
  end
441
453
 
454
+ def color_image_reference(idx, content)
455
+ [
456
+ pre_element,
457
+ color('image brackets'),
458
+ '[',
459
+ color('image title'),
460
+ content,
461
+ color('image brackets'),
462
+ '][',
463
+ color('link url'),
464
+ idx,
465
+ color('image brackets'),
466
+ ']',
467
+ xc,
468
+ post_element
469
+ ].join
470
+ end
471
+
442
472
  def link(link, title, content)
443
473
  res = color_link(link, title&.strip, content&.strip)
444
474
  @@links << {
@@ -785,7 +815,7 @@ module Redcarpet
785
815
  end
786
816
 
787
817
  def color_links(input)
788
- input.gsub(/(?mi)(?<!\\e)\[(?<text>[^\[]+)\]\((?<url>\S+)(?: +"(?<title>.*?)")?\)/) do
818
+ input.gsub(/(?mi)(?<!\\e)\[(?<text>[^\[]+)\]\((?<url>\S+)(?: +"(?<title>.*?)")? *\)/) do
789
819
  m = Regexp.last_match
790
820
  color_link(m['url'].uncolor, m['title']&.uncolor, m['text'].uncolor)
791
821
  end
@@ -805,16 +835,18 @@ module Redcarpet
805
835
  url = link[:url].uncolor
806
836
  content = link[:content]
807
837
  title = link[:title]&.uncolor
808
- graf.gsub!(/#{Regexp.escape(link[:link].gsub(/\n/, ' '))}/, color_link_reference(url, counter, content))
838
+ image = link.key?(:image) && link[:image] ? true : false
839
+ colored_link = image ? color_image_reference(counter, content) : color_link_reference(url, counter, content)
840
+ graf.gsub!(/#{Regexp.escape(link[:link].gsub(/\n/, ' '))}/, colored_link)
809
841
  if MDLess.options[:links] == :paragraph
810
842
  if links_added
811
- graf += "\n#{color_reference_link(url, title, counter)}"
843
+ graf += "\n#{color_reference_link(url, title, counter, image: image)}"
812
844
  else
813
- graf = "#{graf}\n\n#{color_reference_link(url, title, counter)}"
845
+ graf = "#{graf}\n\n#{color_reference_link(url, title, counter, image: image)}"
814
846
  links_added = true
815
847
  end
816
848
  else
817
- @@footer_links << color_reference_link(url, title, counter)
849
+ @@footer_links << color_reference_link(url, title, counter, image: image)
818
850
  end
819
851
  counter += 1
820
852
  end
@@ -997,11 +1029,12 @@ module Redcarpet
997
1029
  input = fix_equations(input)
998
1030
  # misc html
999
1031
  input.gsub!(%r{<br */?>}, "#{pre_element}\n#{post_element}")
1032
+ # render images
1033
+ input = render_images(input) if MDLess.options[:local_images]
1000
1034
  # format links
1001
1035
  input = reference_links(input) if MDLess.options[:links] == :reference || MDLess.options[:links] == :paragraph
1002
1036
  # lists
1003
1037
  input = fix_lists(input)
1004
- input = render_images(input) if MDLess.options[:local_images]
1005
1038
  input = highlight_tags(input) if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
1006
1039
  fix_colors(input)
1007
1040
  end
@@ -287,20 +287,58 @@ module CLIMarkdown
287
287
  tables: true,
288
288
  underline: false)
289
289
 
290
+ spinner = TTY::Spinner.new("[:spinner] Processing ...", format: :dots_3, clear: true)
291
+
290
292
  if !args.empty?
291
293
  files = args.delete_if { |f| !File.exist?(f) }
292
294
  files.each do |file|
293
- MDLess.log.info(%(Processing "#{file}"))
294
- MDLess.file = file
295
+ spinner.run do |spinner|
296
+ MDLess.log.info(%(Processing "#{file}"))
297
+ MDLess.file = file
298
+
299
+ begin
300
+ input = IO.read(file).force_encoding('utf-8')
301
+ rescue StandardError
302
+ input = IO.read(file)
303
+ end
304
+ raise 'Nil input' if input.nil?
305
+
306
+ input.scrub!
307
+ input.gsub!(/\r?\n/, "\n")
308
+
309
+ if MDLess.options[:taskpaper] == :auto
310
+ MDLess.options[:taskpaper] = if CLIMarkdown::TaskPaper.is_taskpaper?(input)
311
+ MDLess.log.info('TaskPaper detected')
312
+ true
313
+ else
314
+ false
315
+ end
316
+ end
295
317
 
296
- begin
297
- input = IO.read(file).force_encoding('utf-8')
298
- rescue StandardError
299
- input = IO.read(file)
318
+ if MDLess.options[:list]
319
+ if MDLess.options[:taskpaper]
320
+ puts CLIMarkdown::TaskPaper.list_projects(input)
321
+ else
322
+ puts list_headers(input)
323
+ end
324
+ Process.exit 0
325
+ else
326
+ if MDLess.options[:taskpaper]
327
+ input = input.color_meta(MDLess.cols)
328
+ input = CLIMarkdown::TaskPaper.highlight(input)
329
+ @output = input.highlight_tags
330
+ else
331
+ @output = markdown.render(input)
332
+ end
333
+ end
300
334
  end
301
- raise 'Nil input' if input.nil?
302
-
303
- input.scrub!
335
+ end
336
+ printout
337
+ elsif !$stdin.isatty
338
+ MDLess.log.info(%(Processing STDIN))
339
+ spinner.run do |spinner|
340
+ MDLess.file = nil
341
+ input = $stdin.read.scrub
304
342
  input.gsub!(/\r?\n/, "\n")
305
343
 
306
344
  if MDLess.options[:taskpaper] == :auto
@@ -330,37 +368,6 @@ module CLIMarkdown
330
368
  end
331
369
  end
332
370
  printout
333
- elsif !$stdin.isatty
334
- MDLess.file = nil
335
- input = $stdin.read.scrub
336
- input.gsub!(/\r?\n/, "\n")
337
-
338
- if MDLess.options[:taskpaper] == :auto
339
- MDLess.options[:taskpaper] = if CLIMarkdown::TaskPaper.is_taskpaper?(input)
340
- MDLess.log.info('TaskPaper detected')
341
- true
342
- else
343
- false
344
- end
345
- end
346
-
347
- if MDLess.options[:list]
348
- if MDLess.options[:taskpaper]
349
- puts CLIMarkdown::TaskPaper.list_projects(input)
350
- else
351
- puts list_headers(input)
352
- end
353
- Process.exit 0
354
- else
355
- if MDLess.options[:taskpaper]
356
- input = input.color_meta(MDLess.cols)
357
- input = CLIMarkdown::TaskPaper.highlight(input)
358
- @output = input.highlight_tags
359
- else
360
- @output = markdown.render(input)
361
- end
362
- end
363
- printout
364
371
  else
365
372
  warn 'No input'
366
373
  Process.exit 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.1.9'
4
+ VERSION = '2.1.10'
5
5
  end
data/lib/mdless.rb CHANGED
@@ -5,6 +5,7 @@ require 'fileutils'
5
5
  require 'logger'
6
6
  require 'tty-which'
7
7
  require 'tty-screen'
8
+ require 'tty-spinner'
8
9
  require 'mdless/version.rb'
9
10
  require 'mdless/colors'
10
11
  require 'mdless/tables'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.9
4
+ version: 2.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-spinner
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement