mdless 1.0.32 → 1.0.35

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: fa89ffe14d9828b457116dde396a11bde06bbe58a258f721b5d0c0d2e5d381bf
4
- data.tar.gz: 2b12d4353cf2f836b0dea6491f7671fae7d269e8b3617cfc92ba8f90e58da0ce
3
+ metadata.gz: 6dce520c83c9816d3124e96eefd5f76af0fdb7f1b98515d1b1cbe2dd602fa34e
4
+ data.tar.gz: fa054888f473b9cab79cdd4446d39092d0e947f20e4feecccc07ff47ab55fc55
5
5
  SHA512:
6
- metadata.gz: 47a0731cd6e4a7febf475f253406938726deebb1e1cbb5808e2048789ab5f695ba9e234656ce40316978eb12e7da2d08b4bed3b42d27614a89fd8ed2ceffa725
7
- data.tar.gz: 9d74ae761471b840e816e4b15ceb81697bbccdf7331d5431a0845727599967383c361c890008bc795312f91374f243a0f6696b953e6c38b197377913a64b6b86
6
+ metadata.gz: e932ba8df8b972fb44d99e6e834abf8068c3c419c7f174b4ca29075dc5d03ab186a8fb5fdf3ff2d4e4ba8679db8f5f493761ebfd4d89f3192f009dcf262aae86
7
+ data.tar.gz: a2862dcbb7c98960b115afa053b9585e0094489e531ca6daebbf0ce961b36e4f933170ba0ed42329c3cf779e6bcafd00436e765380bfc87a47579564d6001f48
@@ -22,11 +22,11 @@ module CLIMarkdown
22
22
  opts.banner = "#{version} by Brett Terpstra\n\n> Usage: #{CLIMarkdown::EXECUTABLE_NAME} [options] [path]\n\n"
23
23
 
24
24
  @options[:color] = true
25
- opts.on( '-c', '--[no-]color', 'Colorize output (default on)' ) do |c|
25
+ opts.on('-c', '--[no-]color', 'Colorize output (default on)') do |c|
26
26
  @options[:color] = c
27
27
  end
28
28
 
29
- opts.on( '-d', '--debug LEVEL', 'Level of debug messages to output' ) do |level|
29
+ opts.on('-d', '--debug LEVEL', 'Level of debug messages to output') do |level|
30
30
  if level.to_i > 0 && level.to_i < 5
31
31
  @log.level = 5 - level.to_i
32
32
  else
@@ -35,7 +35,7 @@ module CLIMarkdown
35
35
  end
36
36
  end
37
37
 
38
- opts.on( '-h', '--help', 'Display this screen' ) do
38
+ opts.on('-h', '--help', 'Display this screen') do
39
39
  puts opts
40
40
  exit
41
41
  end
@@ -54,8 +54,8 @@ module CLIMarkdown
54
54
  end
55
55
  end
56
56
  end
57
- opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)' ) do
58
- if exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
57
+ opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)') do
58
+ if exec_available('imgcat') || exec_available('chafa') # && ENV['TERM_PROGRAM'] == 'iTerm.app'
59
59
  @options[:local_images] = true
60
60
  @options[:remote_images] = true
61
61
  else
@@ -64,51 +64,51 @@ module CLIMarkdown
64
64
  end
65
65
 
66
66
  @options[:links] = :inline
67
- opts.on( '--links=FORMAT', 'Link style ([inline, reference], default inline) [NOT CURRENTLY IMPLEMENTED]' ) do |format|
67
+ opts.on('--links=FORMAT', 'Link style ([inline, reference], default inline) [NOT CURRENTLY IMPLEMENTED]') do |format|
68
68
  if format =~ /^r/i
69
69
  @options[:links] = :reference
70
70
  end
71
71
  end
72
72
 
73
73
  @options[:list] = false
74
- opts.on( '-l', '--list', 'List headers in document and exit' ) do
74
+ opts.on('-l', '--list', 'List headers in document and exit' ) do
75
75
  @options[:list] = true
76
76
  end
77
77
 
78
78
  @options[:pager] = true
79
- opts.on( '-p', '--[no-]pager', 'Formatted output to pager (default on)' ) do |p|
79
+ opts.on('-p', '--[no-]pager', 'Formatted output to pager (default on)') do |p|
80
80
  @options[:pager] = p
81
81
  end
82
82
 
83
- opts.on( '-P', 'Disable pager (same as --no-pager)' ) do
83
+ opts.on('-P', 'Disable pager (same as --no-pager)') do
84
84
  @options[:pager] = false
85
85
  end
86
86
 
87
87
  @options[:section] = nil
88
- opts.on( '-s', '--section=NUMBER', 'Output only a headline-based section of the input (numeric from --list)' ) do |section|
89
- @options[:section] = section.to_i
88
+ opts.on('-s', '--section=NUMBER[,NUMBER]', 'Output only a headline-based section of the input (numeric from --list)') do |section|
89
+ @options[:section] = section.split(/ *, */).map(&:strip).map(&:to_i)
90
90
  end
91
91
 
92
92
  @options[:theme] = 'default'
93
- opts.on( '-t', '--theme=THEME_NAME', 'Specify an alternate color theme to load' ) do |theme|
93
+ opts.on('-t', '--theme=THEME_NAME', 'Specify an alternate color theme to load') do |theme|
94
94
  @options[:theme] = theme
95
95
  end
96
96
 
97
- opts.on( '-v', '--version', 'Display version number' ) do
97
+ opts.on('-v', '--version', 'Display version number') do
98
98
  puts version
99
99
  exit
100
100
  end
101
101
 
102
- @options[:width] = %x{tput cols}.strip.to_i
103
- opts.on( '-w', '--width=COLUMNS', 'Column width to format for (default terminal width)' ) do |columns|
102
+ @options[:width] = `tput cols`.strip.to_i
103
+ opts.on('-w', '--width=COLUMNS', 'Column width to format for (default: terminal width)') do |columns|
104
104
  @options[:width] = columns.to_i
105
105
  end
106
106
  end
107
107
 
108
108
  begin
109
109
  optparse.parse!
110
- rescue OptionParser::ParseError => pe
111
- $stderr.puts "error: #{pe.message}"
110
+ rescue OptionParser::ParseError => e
111
+ warn "error: #{e.message}"
112
112
  exit 1
113
113
  end
114
114
 
@@ -122,7 +122,7 @@ module CLIMarkdown
122
122
  @ref_links = {}
123
123
  @footnotes = {}
124
124
 
125
- if args.length > 0
125
+ if !args.empty?
126
126
  files = args.delete_if { |f| !File.exist?(f) }
127
127
  files.each do |file|
128
128
  @log.info(%(Processing "#{file}"))
@@ -488,6 +488,10 @@ module CLIMarkdown
488
488
  end
489
489
 
490
490
  def convert_markdown(input)
491
+ ## Replace setex headers with ATX
492
+ input.gsub!(/^([^\n]+)\n={3,}\s*$/m, "# \\1\n")
493
+ input.gsub!(/^([^\n]+?)\n-{3,}\s*$/m, "## \\1\n")
494
+
491
495
  @headers = get_headers(input)
492
496
  input += "\n\n@@@"
493
497
  # yaml/MMD headers
@@ -527,7 +531,6 @@ module CLIMarkdown
527
531
 
528
532
  end
529
533
 
530
-
531
534
  # Gather reference links
532
535
  input.gsub!(/^\s{,3}(?<![\e*])\[\b(.+)\b\]: +(.+)/) do |m|
533
536
  match = Regexp.last_match
@@ -544,34 +547,34 @@ module CLIMarkdown
544
547
  end
545
548
 
546
549
  if @options[:section]
547
- in_section = false
548
- top_level = 1
549
550
  new_content = []
550
-
551
- input.split(/\n/).each {|graf|
552
- if graf =~ /^(#+) *(.*?)( *#+)?$/
553
- level = $1.length
554
- title = $2
555
-
556
- if in_section
557
- if level >= top_level
551
+ @options[:section].each do |sect|
552
+ in_section = false
553
+ top_level = 1
554
+ input.split(/\n/).each do |graf|
555
+ if graf =~ /^(#+) *(.*?)( *#+)?$/
556
+ m = Regexp.last_match
557
+ level = m[1].length
558
+ title = m[2]
559
+ if in_section
560
+ if level >= top_level
561
+ new_content.push(graf)
562
+ else
563
+ in_section = false
564
+ break
565
+ end
566
+ elsif title.downcase == @headers[sect - 1][1].downcase
567
+ in_section = true
568
+ top_level = level + 1
558
569
  new_content.push(graf)
559
570
  else
560
- in_section = false
561
- break
571
+ next
562
572
  end
563
- elsif title.downcase == "#{@headers[@options[:section] - 1][1].downcase}"
564
- in_section = true
565
- top_level = level + 1
573
+ elsif in_section
566
574
  new_content.push(graf)
567
- else
568
- next
569
575
  end
570
- elsif in_section
571
- new_content.push(graf)
572
576
  end
573
- }
574
-
577
+ end
575
578
  input = new_content.join("\n")
576
579
  end
577
580
 
@@ -623,23 +626,23 @@ module CLIMarkdown
623
626
  input.gsub!(/(?i-m)(^[ \t]*[`~]{3,})([\s\S]*?)\n([\s\S]*?)\1/m) do
624
627
  language = nil
625
628
  m = Regexp.last_match
626
- first_indent = m[1].gsub(/\t/,' ').match(/^ */)[0].size
629
+ first_indent = m[1].gsub(/\t/, ' ').match(/^ */)[0].size
627
630
 
628
- if m[2] && m[2].strip.length > 0
631
+ if m[2] && !m[2].strip.empty?
629
632
  language = m[2].strip.split(/ /)[0]
630
- code_block = pad_max(m[3].to_s,'')
631
- leader = language ? language : 'code'
633
+ code_block = pad_max(m[3].to_s, '')
634
+ leader = language || 'code'
632
635
  else
633
636
  first_line = m[3].to_s.split(/\n/)[0]
634
637
 
635
- if first_line =~ /^\s*#!.*\/.+/
636
- shebang = first_line.match(/^\s*#!.*\/(?:env )?([^\/]+)$/)
638
+ if first_line =~ %r{^\s*#!.*/.+}
639
+ shebang = first_line.match(%r{^\s*#!.*/(?:env )?([^/]+)$})
637
640
  language = shebang[1]
638
641
  code_block = m[3]
639
- leader = shebang[1] ? shebang[1] : 'code'
642
+ leader = shebang[1] || 'code'
640
643
  else
641
644
  code_block = pad_max(m[3].to_s, "#{color('code_block eol')}¬")
642
- leader = language ? language : 'code'
645
+ leader = language || 'code'
643
646
  end
644
647
  end
645
648
  leader += xc
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.32'
2
+ VERSION = '1.0.35'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.32
4
+ version: 1.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake