markdown_exec 2.7.2 → 2.7.4

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/colorize.rb CHANGED
@@ -13,23 +13,15 @@ class String
13
13
  # @return [String] The formatted string.
14
14
  def method_missing(method_name, *args, &block)
15
15
  case method_name.to_s
16
- # when /^bg_rgb_/
17
- # bytes = $'.split('_')
18
- # bg_rgb_color(bytes[0..2].join(';'))
19
16
  when /^fg_bg_rgb_/
20
- pp [__LINE__, caller[0]]; binding.irb
21
17
  bytes = $'.split('_')
22
18
  fg_bg_rgb_color(bytes[0..2].join(';'), bytes[3..5].join(';'))
23
19
  when /^fg_bg_rgbh_/
24
- pp [__LINE__, caller[0]]; binding.irb
25
20
  hex_to_fg_bg_rgb($')
26
21
  when /^fg_rgb_/
27
- pp [__LINE__, caller[0]]; binding.irb
28
22
  fg_rgb_color($'.gsub('_', ';'))
29
23
  when /^fg_rgbh_/
30
- pp [__LINE__, caller[0]]; binding.irb
31
24
  hex_to_rgb($')
32
-
33
25
  when 'to_a', 'to_ary', 'to_hash', 'to_int', 'to_io', 'to_regexp'
34
26
  nil
35
27
  else
@@ -41,24 +33,14 @@ class String
41
33
  #
42
34
  # @return [String] The string wrapped in an ANSI control sequence.
43
35
  def ansi_control_sequence
44
- pp [__LINE__, caller[0]]; binding.irb
45
36
  "\033[#{self}\033[0m"
46
37
  end
47
38
 
48
- # # Applies a 24-bit RGB background color to the string.
49
- # #
50
- # # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
51
- # # @return [String] The string with the applied RGB foreground color.
52
- # def bg_rgb_color(rgb)
53
- # "48;2;#{rgb}m#{self}".ansi_control_sequence
54
- # end
55
-
56
39
  # Applies a 24-bit RGB foreground color to the string.
57
40
  #
58
41
  # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
59
42
  # @return [String] The string with the applied RGB foreground color.
60
43
  def fg_bg_rgb_color(fg_rgb, bg_rgb)
61
- pp [__LINE__, caller[0]]; binding.irb
62
44
  "38;2;#{fg_rgb}m\033[48;2;#{bg_rgb}m#{self}".ansi_control_sequence
63
45
  end
64
46
 
@@ -67,7 +49,6 @@ class String
67
49
  # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
68
50
  # @return [String] The string with the applied RGB foreground color.
69
51
  def fg_rgb_color(rgb)
70
- pp [__LINE__, caller[0]]; binding.irb
71
52
  "38;2;#{rgb}m#{self}".ansi_control_sequence
72
53
  end
73
54
 
@@ -76,7 +57,6 @@ class String
76
57
  # @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
77
58
  # @return [String] The string with the applied RGB foreground color.
78
59
  def hex_to_fg_bg_rgb(hex_str)
79
- pp [__LINE__, caller[0]]; binding.irb
80
60
  values = hex_str.split('_').map { |hex| hex.to_i(16).to_s }
81
61
  fg_bg_rgb_color(
82
62
  values[0..2].join(';'),
@@ -89,7 +69,6 @@ class String
89
69
  # @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
90
70
  # @return [String] The string with the applied RGB foreground color.
91
71
  def hex_to_rgb(hex_str)
92
- pp [__LINE__, caller[0]]; binding.irb
93
72
  fg_rgb_color(
94
73
  hex_str.split('_').map { |hex| hex.to_i(16).to_s }.join(';')
95
74
  )
@@ -99,7 +78,6 @@ class String
99
78
  #
100
79
  # @return [String] The original string.
101
80
  def plain
102
- pp [__LINE__, caller[0]]; binding.irb
103
81
  self
104
82
  end
105
83
 
@@ -126,20 +104,16 @@ class String
126
104
  def violet; fg_rgbh_94_00_D3; end
127
105
  def yellow; fg_rgbh_FF_FF_00; end
128
106
 
129
- def x
130
- pp [__LINE__, caller[1]]; binding.irb
131
- end
132
-
133
107
  # graphics modes
134
- def bold; x; "\033[1m#{self}\033[22m"; end
135
- def bold_italic; x; "\033[1m\033[3m#{self}\033[22m\033[23m"; end
136
- def bold_underline; x; "\033[1m\033[4m#{self}\033[22m\033[24m"; end
137
- def dim; x; "\033[2m#{self}\033[22m"; end
138
- def italic; x; "\033[3m#{self}\033[23m"; end
139
- def underline; x; "\033[4m#{self}\033[24m"; end
140
- def underline_italic; x; "\033[4m\033[3m#{self}\033[23m\033[24m"; end
141
- def blinking; x; "\033[5m#{self}\033[25m"; end
142
- def inverse; x; "\033[7m#{self}\033[27m"; end
143
- def hidden; x; "\033[8m#{self}\033[28m"; end
144
- def strikethrough; x; "\033[9m#{self}\033[29m"; end
108
+ def bold; "\033[1m#{self}\033[22m"; end
109
+ def bold_italic; "\033[1m\033[3m#{self}\033[22m\033[23m"; end
110
+ def bold_underline; "\033[1m\033[4m#{self}\033[22m\033[24m"; end
111
+ def dim; "\033[2m#{self}\033[22m"; end
112
+ def italic; "\033[3m#{self}\033[23m"; end
113
+ def underline; "\033[4m#{self}\033[24m"; end
114
+ def underline_italic; "\033[4m\033[3m#{self}\033[23m\033[24m"; end
115
+ def blinking; "\033[5m#{self}\033[25m"; end
116
+ def inverse; "\033[7m#{self}\033[27m"; end
117
+ def hidden; "\033[8m#{self}\033[28m"; end
118
+ def strikethrough; "\033[9m#{self}\033[29m"; end
145
119
  end
data/lib/fcb.rb CHANGED
@@ -33,6 +33,10 @@ module MarkdownExec
33
33
  title: '',
34
34
  type: ''
35
35
  }.merge(options)
36
+ # @attrs[:raw_body] ||= @attrs[:body]
37
+ # @attrs[:raw_dname] ||= @attrs[:dname]
38
+ # @attrs[:raw_s0printable] ||= @attrs[:s0printable]
39
+ # @attrs[:raw_s1decorated] ||= @attrs[:s1decorated]
36
40
  end
37
41
 
38
42
  def code_name_included?(*names)
@@ -43,6 +47,10 @@ module MarkdownExec
43
47
  Regexp.new(regexp) =~ @attrs[:oname]
44
48
  end
45
49
 
50
+ def delete_key(key)
51
+ @attrs.delete(key)
52
+ end
53
+
46
54
  # Derives a title from the body of an FCB object.
47
55
  # @param fcb [Object] The FCB object whose title is to be derived.
48
56
  # @return [String] The derived title.
@@ -57,10 +65,38 @@ module MarkdownExec
57
65
  @attrs[:title] = if body_content.count == 1
58
66
  body_content.first
59
67
  else
60
- FCB::format_multiline_body_as_title(body_content)
68
+ FCB.format_multiline_body_as_title(body_content)
61
69
  end
62
70
  end
63
71
 
72
+ # def body=(value)
73
+ # ww0 'body=', value
74
+ # # binding.irb
75
+ # @attrs[:raw_body] ||= value
76
+ # @attrs[:body] = value
77
+ # end
78
+
79
+ # def dname=(value)
80
+ # ww0 'dname=', value
81
+ # binding.irb if value == ' | Species| Not specified'
82
+ # @attrs[:raw_dname] ||= value
83
+ # @attrs[:dname] = value
84
+ # end
85
+
86
+ # def s0printable=(value)
87
+ # ww0 's0printable=', value
88
+ # # binding.irb
89
+ # @attrs[:raw_s0printable] ||= value
90
+ # @attrs[:s0printable] = value
91
+ # end
92
+
93
+ # def s1decorated=(value)
94
+ # ww0 's1decorated=', value
95
+ # # binding.irb
96
+ # @attrs[:raw_s1decorated] ||= value
97
+ # @attrs[:s1decorated] = value
98
+ # end
99
+
64
100
  # Processes a block to generate its summary, modifying its attributes
65
101
  # based on various matching criteria.
66
102
  # It handles special formatting for bash blocks, extracting and setting
@@ -75,6 +111,7 @@ module MarkdownExec
75
111
  block_name_nick_match: @delegate_object[:block_name_nick_match],
76
112
  id: ''
77
113
  )
114
+ # binding.irb
78
115
  call = @attrs[:call] = @attrs[:start_line]&.match(
79
116
  Regexp.new(block_calls_scan)
80
117
  )&.fetch(1, nil)
@@ -85,7 +122,7 @@ module MarkdownExec
85
122
  @attrs[:nickname] = $~[0]
86
123
  derive_title_from_body
87
124
  else
88
- bm = NamedCaptureExtractor::extract_named_groups(
125
+ bm = NamedCaptureExtractor.extract_named_groups(
89
126
  titlexcall,
90
127
  block_name_match
91
128
  )
@@ -161,7 +198,6 @@ module MarkdownExec
161
198
  end
162
199
 
163
200
  # Expand variables in attributes
164
- ####
165
201
  def expand_variables_in_attributes!(pattern, replacements)
166
202
  @attrs[:raw_dname] ||= @attrs[:dname]
167
203
  @attrs[:dname] = @attrs[:dname]&.gsub(pattern) do |match|
@@ -179,14 +215,14 @@ module MarkdownExec
179
215
  end
180
216
 
181
217
  # Replace variables in each line of `body` if `body` is present
182
- if @attrs[:body]
183
- @attrs[:raw_body] ||= @attrs[:body]
184
- @attrs[:body] = @attrs[:body]&.map do |line|
185
- if line.empty?
186
- line
187
- else
188
- line.gsub(pattern) { |match| replacements[match] }
189
- end
218
+ return unless @attrs[:body]
219
+
220
+ @attrs[:raw_body] ||= @attrs[:body]
221
+ @attrs[:body] = @attrs[:body]&.map do |line|
222
+ if line.empty?
223
+ line
224
+ else
225
+ line.gsub(pattern) { |match| replacements[match] }
190
226
  end
191
227
  end
192
228
  end
data/lib/format_table.rb CHANGED
@@ -63,20 +63,31 @@ module MarkdownTableFormatter
63
63
  end
64
64
  end
65
65
 
66
- def format_cell(cell, align, width)
67
- case align
68
- when :center
69
- cell.center(width)
70
- when :right
71
- cell.rjust(width)
72
- else
73
- cell.ljust(width)
74
- end
66
+ def format_cell(cell, align, width, truncate: true)
67
+ plain_string = cell.gsub(/\033\[[\d;]+m|\033\[0m/, '')
68
+ truncated = false
69
+ ret = TrackedString.new(
70
+ case
71
+ when truncate && plain_string.length > width
72
+ truncated = true
73
+ plain_string[0, width]
74
+ when align == :center
75
+ cell.center(width)
76
+ when align == :right
77
+ cell.rjust(width)
78
+ else
79
+ cell.ljust(width)
80
+ end
81
+ )
82
+ ret.truncated = truncated
83
+ ret
75
84
  end
76
85
 
77
86
  def format_row_line__hs(
78
87
  row, alignment_indicators, column_widths, decorate,
79
- text_sym: :text, style_sym: :color
88
+ style_sym: :color,
89
+ text_sym: :text,
90
+ truncate: true
80
91
  )
81
92
  return HierarchyString.new if row.cells.nil?
82
93
 
@@ -92,8 +103,10 @@ module MarkdownTableFormatter
92
103
  style_sym => decorate && decorate[row.role] }
93
104
  else
94
105
  {
95
- text_sym => format_cell(cell, alignment_indicators[i],
96
- column_widths[i]),
106
+ text_sym => format_cell(
107
+ cell, alignment_indicators[i], column_widths[i],
108
+ truncate: truncate
109
+ ),
97
110
  style_sym => decoration_style(row.role, row.counter, decorate)
98
111
  }
99
112
  end
@@ -106,9 +119,15 @@ module MarkdownTableFormatter
106
119
  )
107
120
  end
108
121
 
109
- def format_rows__hs(rows, alignment_indicators, column_widths, decorate)
122
+ def format_rows__hs(
123
+ rows, alignment_indicators, column_widths, decorate,
124
+ truncate: true
125
+ )
110
126
  rows.map do |row|
111
- format_row_line__hs(row, alignment_indicators, column_widths, decorate)
127
+ format_row_line__hs(
128
+ row, alignment_indicators, column_widths, decorate,
129
+ truncate: truncate
130
+ )
112
131
  end
113
132
  end
114
133
 
@@ -116,7 +135,11 @@ module MarkdownTableFormatter
116
135
  format_table__hs(**kwargs).map(&:decorate)
117
136
  end
118
137
 
119
- def format_table__hs(lines:, column_count:, decorate: nil)
138
+ def format_table__hs(
139
+ lines:, column_count:, decorate: nil,
140
+ table_width: nil,
141
+ truncate: true
142
+ )
120
143
  unless column_count.positive?
121
144
  return lines.map do |line|
122
145
  HierarchyString.new([{ text: line }])
@@ -129,7 +152,23 @@ module MarkdownTableFormatter
129
152
  alignment_indicators, column_widths =
130
153
  calculate_column_alignment_and_widths(rows, column_count)
131
154
 
132
- format_rows__hs(rows, alignment_indicators, column_widths, decorate)
155
+ # ww0 'table_width', table_width
156
+ # ww0 'truncate', truncate
157
+
158
+ unless table_width.nil?
159
+ sum_column_widths = column_widths.sum
160
+ if sum_column_widths > table_width
161
+ ratio = table_width.to_f / sum_column_widths
162
+ column_widths.each_with_index do |width, i|
163
+ column_widths[i] = (width * ratio).to_i
164
+ end
165
+ end
166
+ end
167
+
168
+ format_rows__hs(
169
+ rows, alignment_indicators, column_widths, decorate,
170
+ truncate: truncate
171
+ ).tap { |ret| binding.irb if ret.class == TrackedString }
133
172
  end
134
173
 
135
174
  def insert_every_other(array, obj)
@@ -188,7 +227,6 @@ end
188
227
  return if $PROGRAM_NAME != __FILE__
189
228
 
190
229
  require 'minitest/autorun'
191
- require_relative 'colorize'
192
230
 
193
231
  class TestMarkdownTableFormatter < Minitest::Test
194
232
  def setup