mdless 1.0.37 → 2.0.2

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.
data/lib/mdless/tables.rb CHANGED
@@ -1,16 +1,15 @@
1
1
  module CLIMarkdown
2
2
  class MDTableCleanup
3
-
4
- PAD_CHAR = '⎕'
3
+ PAD_CHAR = "\u00A0"
5
4
 
6
5
  def initialize(input)
7
6
  @string = input
8
- @format_row = []
9
7
  end
10
8
 
11
9
  def parse
10
+ @format_row = []
12
11
  @table = []
13
- format = []
12
+ fmt = []
14
13
  cols = 0
15
14
  rows = @string.split(/\r?\n/)
16
15
  rows.each do |row|
@@ -19,29 +18,29 @@ module CLIMarkdown
19
18
  row_array = row.split(/\|/)
20
19
  row_array.map! { |cell| cell.strip }
21
20
  if row =~ /^[\|:\- ]+$/
22
- format = row_array
21
+ fmt = row_array
23
22
  else
24
23
  @table.push row_array
25
24
  end
26
25
  cols = row_array.length if row_array.length > cols
27
26
  end
28
27
 
29
- format.each_with_index {|cell, i|
28
+ fmt.each_with_index do |cell, i|
30
29
  cell.strip!
31
- f = 'left'
32
- if cell =~ /^:.*?:$/
33
- f = 'center'
34
- elsif cell =~ /[^:]+:$/
35
- f = 'right'
30
+ f = case cell
31
+ when /^:.*?:$/
32
+ :center
33
+ when /[^:]+:$/
34
+ :right
36
35
  else
37
- f = 'just'
36
+ :just
38
37
  end
39
38
  @format_row.push(f)
40
- }
39
+ end
41
40
 
42
41
  if @format_row.length < cols
43
42
  (cols - @format_row.length).times do
44
- @format_row.push('left')
43
+ @format_row.push(:left)
45
44
  end
46
45
  end
47
46
 
@@ -60,9 +59,9 @@ module CLIMarkdown
60
59
  @table ||= parse
61
60
  end
62
61
 
63
- def column_width(i)
62
+ def column_width(idx)
64
63
  @widths ||= column_widths
65
- @widths[i]
64
+ @widths[idx]
66
65
  end
67
66
 
68
67
  def column_widths
@@ -72,7 +71,7 @@ module CLIMarkdown
72
71
  end
73
72
 
74
73
  table.each do |row|
75
- @format_row.each_with_index do |cell, i|
74
+ @format_row.each_with_index do |_, i|
76
75
  length = row[i].strip.length
77
76
  @widths[i] = length if length > @widths[i]
78
77
  end
@@ -81,32 +80,31 @@ module CLIMarkdown
81
80
  @widths
82
81
  end
83
82
 
84
- def pad(string,type,length)
85
- string.strip!
86
- if type == 'center'
87
- string.center(length, PAD_CHAR)
88
- elsif type == 'right'
89
- string.rjust(length, PAD_CHAR)
90
- elsif type == 'left'
91
- string.ljust(length, PAD_CHAR)
83
+ def pad(string, alignment, length)
84
+ case alignment
85
+ when :center
86
+ string.strip.center(length, PAD_CHAR)
87
+ when :right
88
+ string.strip.rjust(length, PAD_CHAR)
89
+ when :left
90
+ string.strip.ljust(length, PAD_CHAR)
92
91
  else
93
- string.ljust(length, PAD_CHAR)
92
+ string.strip.ljust(length, PAD_CHAR)
94
93
  end
95
94
  end
96
95
 
97
96
  def separator(length, alignment)
98
- out = "".ljust(length,'-')
97
+ out = ''.ljust(length, '-')
99
98
  case alignment
100
- when 'left'
101
- out = ':' + out + '-'
102
- when 'right'
103
- out = '-' + out + ':'
104
- when 'center'
105
- out = ":#{out}:"
99
+ when :left
100
+ ":#{out}-"
101
+ when :right
102
+ "-#{out}:"
103
+ when :center
104
+ ":#{out}:"
106
105
  else
107
- out = "-#{out}-"
106
+ "-#{out}-"
108
107
  end
109
- out
110
108
  end
111
109
 
112
110
  def header_separator_row
@@ -128,18 +126,14 @@ module CLIMarkdown
128
126
  def to_md
129
127
  output = []
130
128
  t = table.clone
131
-
132
- t.each_with_index do |row, index|
133
- row.map!.with_index { |cell, i| cell = pad(cell, @format_row[i], column_width(i)) }
134
- output.push("| #{row.join(' | ').lstrip} |")
129
+ t.each do |row|
130
+ new_row = row.map.with_index { |cell, i| pad(cell, @format_row[i], column_width(i)) }.join(' | ')
131
+ output.push("| #{new_row} |")
135
132
  end
136
133
  output.insert(1, header_separator_row)
137
134
  output.insert(0, table_border)
138
135
  output.push(table_border)
139
-
140
- output.join("\n").gsub(/((?<=\| )#{PAD_CHAR}+|#{PAD_CHAR}+(?= \|))/) {|m|
141
- " "*m.length
142
- }
136
+ output.join("\n")
143
137
  end
144
138
  end
145
139
  end
data/lib/mdless/theme.rb CHANGED
@@ -70,6 +70,7 @@ module CLIMarkdown
70
70
  'pygments_theme' => 'monokai'
71
71
  },
72
72
  'dd' => {
73
+ 'term' => 'black on_white',
73
74
  'marker' => 'd red',
74
75
  'color' => 'b white'
75
76
  },
@@ -86,7 +87,9 @@ module CLIMarkdown
86
87
  'html' => {
87
88
  'brackets' => 'd yellow on_black',
88
89
  'color' => 'yellow on_black'
89
- }
90
+ },
91
+ 'super' => 'b green',
92
+ 'text' => 'white'
90
93
  }
91
94
 
92
95
  def load_theme_file(theme_file)
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.37'
2
+ VERSION = '2.0.2'
3
3
  end
data/lib/mdless.rb CHANGED
@@ -3,11 +3,14 @@ require 'shellwords'
3
3
  require 'open3'
4
4
  require 'fileutils'
5
5
  require 'logger'
6
+ require 'tty-which'
6
7
  require 'mdless/version.rb'
7
8
  require 'mdless/colors'
8
9
  require 'mdless/tables'
9
10
  require 'mdless/hash'
10
11
  require 'mdless/theme'
12
+ require 'redcarpet'
13
+ require 'mdless/console'
11
14
  require 'mdless/converter'
12
15
 
13
16
  module CLIMarkdown
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.37
4
+ version: 2.0.2
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-09-22 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-which
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rake
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +79,7 @@ files:
51
79
  - bin/mdless
52
80
  - lib/mdless.rb
53
81
  - lib/mdless/colors.rb
82
+ - lib/mdless/console.rb
54
83
  - lib/mdless/converter.rb
55
84
  - lib/mdless/hash.rb
56
85
  - lib/mdless/tables.rb