mdless 2.1.44 → 2.1.46

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
@@ -14,7 +14,7 @@ module CLIMarkdown
14
14
  rows = @string.split(/\r?\n/)
15
15
  rows.each do |row|
16
16
  row.strip!
17
- row.sub!(/^\s*\|?/,'').sub!(/\|?\s*$/,'')
17
+ row.sub!(/^\s*\|?/, "").sub!(/\|?\s*$/, "")
18
18
  row_array = row.split(/\|/)
19
19
  row_array.map! { |cell| cell.strip }
20
20
  if row =~ /^[\|:\- ]+$/
@@ -28,13 +28,13 @@ module CLIMarkdown
28
28
  fmt.each_with_index do |cell, i|
29
29
  cell.strip!
30
30
  f = case cell
31
- when /^:.*?:$/
32
- :center
33
- when /[^:]+:$/
34
- :right
35
- else
36
- :just
37
- end
31
+ when /^:.*?:$/
32
+ :center
33
+ when /[^:]+:$/
34
+ :right
35
+ else
36
+ :just
37
+ end
38
38
  @format_row.push(f)
39
39
  end
40
40
 
@@ -81,20 +81,21 @@ module CLIMarkdown
81
81
  end
82
82
 
83
83
  def pad(string, alignment, length)
84
+ naked = string.uncolor.remove_pre_post.strip
84
85
  case alignment
85
86
  when :center
86
- string.strip.center(length, PAD_CHAR)
87
+ naked.strip.center(length, PAD_CHAR).sub(/#{Regexp.escape(naked)}/, string)
87
88
  when :right
88
- string.strip.rjust(length, PAD_CHAR)
89
+ naked.strip.rjust(length, PAD_CHAR).sub(/#{Regexp.escape(naked)}/, string)
89
90
  when :left
90
- string.strip.ljust(length, PAD_CHAR)
91
+ naked.strip.ljust(length, PAD_CHAR).sub(/#{Regexp.escape(naked)}/, string)
91
92
  else
92
- string.strip.ljust(length, PAD_CHAR)
93
+ naked.strip.ljust(length, PAD_CHAR).sub(/#{Regexp.escape(naked)}/, string)
93
94
  end
94
95
  end
95
96
 
96
97
  def separator(length, alignment)
97
- out = ''.ljust(length, '-')
98
+ out = "".ljust(length, "-")
98
99
  case alignment
99
100
  when :left
100
101
  ":#{out}-"
@@ -112,7 +113,7 @@ module CLIMarkdown
112
113
  @format_row.each_with_index do |column, i|
113
114
  output.push separator(column_width(i), column)
114
115
  end
115
- "|#{output.join('|')}|"
116
+ "|#{output.join("|")}|"
116
117
  end
117
118
 
118
119
  def table_border
@@ -120,14 +121,14 @@ module CLIMarkdown
120
121
  @format_row.each_with_index do |column, i|
121
122
  output.push separator(column_width(i), column)
122
123
  end
123
- "+#{output.join('+').gsub(/:/,'-')}+"
124
+ "+#{output.join("+").gsub(/:/, "-")}+"
124
125
  end
125
126
 
126
127
  def to_md
127
128
  output = []
128
129
  t = table.clone
129
130
  t.each do |row|
130
- new_row = row.map.with_index { |cell, i| pad(cell, @format_row[i], column_width(i)) }.join(' | ')
131
+ new_row = row.map.with_index { |cell, i| pad(cell, @format_row[i], column_width(i)) }.join(" | ")
131
132
  output.push("| #{new_row} |")
132
133
  end
133
134
  output.insert(1, header_separator_row)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.1.44'
4
+ VERSION = '2.1.46'
5
5
  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: 2.1.44
4
+ version: 2.1.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-08 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet