mdless 2.1.7 → 2.1.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a7d200fbf2d90da97cf6ae65beecac52643ec377d2a60f7d8503ca2411694ea
4
- data.tar.gz: f35b88bdf439f3436ddf2e6cf0b835e8a23d5d5553721b0c35d75954af43013e
3
+ metadata.gz: 7b6335a8f0eb1e43af37924810a1e8e6b94f5b2da35b745824f3ce735536777d
4
+ data.tar.gz: 54643d669cfef096d92405e4b1ed2a216c749a67c3fb2f03dc32ad91e7a5f98a
5
5
  SHA512:
6
- metadata.gz: 906870b0032f1cba0a1c90be6ac2cb80f82c1abcb331470f75b02598d05d965996b2d2eb0a076b2651e32e9ae567334b693a9dffd702b517e15c5b8048f2e172
7
- data.tar.gz: e1874c241362b44607a357ec4e125bdc463ae3b3ab906bdf7237e1b782a6122b6f90d664210cf7dd1b964bf843adb1056adbacdd93b816f0bb31db4d92ad1cf5
6
+ metadata.gz: 8a3d3fc7ee471da0cd3b882deba060a19728492a2493c06cca461029ce7d664940e8e0f602a324c71ede7d8e0b617365e7375cb4702cd7b19a91d440fda32a24
7
+ data.tar.gz: be3fc65aca571dcc96af250f8bc0faf0e5c8be3a7ed1a2b30229fd5fd501e6087a8990bcc43f5d8f60b21599167833f55381a759a54e7765a3be4db729e16de4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ 2.1.9
2
+ : Code block prefix configurable, can be left empty to make more copyable code blocks
3
+ : Remove empty lines from block quotes
4
+ : Infinite loop when calculating ANSI emphasis
5
+ : Don't accept colors or semicolons inside of @tag names
6
+
7
+ 2.1.8
8
+ : --update-theme option to add any missing keys to your theme file
9
+ : Strip ul_char of any spaces before inserting
10
+
1
11
  2.1.7
2
12
  : Dedup and remove empty escape codes before output
3
13
  : Tables losing column alignment
data/lib/mdless/colors.rb CHANGED
@@ -92,6 +92,7 @@ module CLIMarkdown
92
92
  bg = nil
93
93
  rgbb = c
94
94
  else
95
+ em = []
95
96
  c.split(/;/).each do |i|
96
97
  x = i.to_i
97
98
  if x <= 9
@@ -113,10 +114,13 @@ module CLIMarkdown
113
114
  end
114
115
  end
115
116
 
116
- escape = "\e[#{em.join(';')}m"
117
+ escape = ''
118
+ escape += "\e[#{em.join(';')}m" unless em.empty?
117
119
  escape += "\e[#{rgbb}m" if rgbb
118
120
  escape += "\e[#{rgbf}m" if rgbf
119
- escape + "\e[#{[fg, bg].delete_if(&:nil?).join(';')}m"
121
+ fg_bg = [fg, bg].delete_if(&:nil?).join(';')
122
+ escape += "\e[#{fg_bg}m" unless fg_bg.empty?
123
+ escape
120
124
  end
121
125
 
122
126
  def blackout(bgcolor)
@@ -133,25 +137,23 @@ module CLIMarkdown
133
137
  self.uncolor.size
134
138
  end
135
139
 
136
- def wrap(width=78,foreground=:x)
137
- if self.uncolor =~ /(^([%~] |\s*>)| +[=\-]{5,})/
138
- return self
139
- end
140
+ def wrap(width=78, foreground=:x)
141
+ return self if uncolor =~ /(^([%~] |\s*>)| +[=-]{5,})/
140
142
 
141
143
  visible_width = 0
142
144
  lines = []
143
145
  line = ''
144
146
  last_ansi = ''
145
147
 
146
- line += self.match(/^\s*/)[0].gsub(/\t/,' ')
147
- input = self.dup # .gsub(/(\w-)(\w)/,'\1 \2')
148
+ line += match(/^\s*/)[0].gsub(/\t/, ' ')
149
+ input = dup # .gsub(/(\w-)(\w)/,'\1 \2')
148
150
  # input.gsub!(/\[.*?\]\(.*?\)/) do |link|
149
151
  # link.gsub(/ /, "\u00A0")
150
152
  # end
151
153
  input.split(/\s+/).each do |word|
152
- last_ansi = line.scan(/\e\[[\d;]+m/)[-1] || ''
154
+ last_ansi = line.last_color_code
153
155
  if visible_width + word.size_clean >= width
154
- lines << line + xc(foreground)
156
+ lines << line + xc
155
157
  visible_width = word.size_clean
156
158
  line = last_ansi + word
157
159
  elsif line.empty?
@@ -162,7 +164,7 @@ module CLIMarkdown
162
164
  line << ' ' << last_ansi + word
163
165
  end
164
166
  end
165
- lines << line + match(/\s*$/)[0] + xc(foreground) if line
167
+ lines << line + match(/\s*$/)[0] + xc if line
166
168
  lines.map!.with_index do |l, i|
167
169
  (i.positive? ? l[i - 1].last_color_code : '') + l
168
170
  end
@@ -97,8 +97,8 @@ module Redcarpet
97
97
  hilite = xc + hilite.split(/\n/).map do |l|
98
98
  [
99
99
  color('code_block marker'),
100
- '> ',
101
- "#{color('code_block bg')}#{l.strip}#{xc}"
100
+ MDLess.theme['code_block']['character'],
101
+ "#{color('code_block bg')}#{l.rstrip}#{xc}"
102
102
  ].join
103
103
  end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
104
104
  end
@@ -110,7 +110,7 @@ module Redcarpet
110
110
  hilite = code_block.split(/\n/).map do |line|
111
111
  [
112
112
  color('code_block marker'),
113
- '> ',
113
+ MDLess.theme['code_block']['character'],
114
114
  color('code_block color'),
115
115
  line,
116
116
  xc
@@ -172,7 +172,7 @@ module Redcarpet
172
172
 
173
173
  def block_quote(quote)
174
174
  ret = "\n\n"
175
- quote.wrap(MDLess.cols, color('blockquote color')).split(/\n/).each do |line|
175
+ quote.strip.wrap(MDLess.cols, color('blockquote color')).split(/\n/).each do |line|
176
176
  ret += [
177
177
  color('blockquote marker color'),
178
178
  MDLess.theme['blockquote']['marker']['character'],
@@ -555,7 +555,7 @@ module Redcarpet
555
555
  [
556
556
  indent,
557
557
  color('list bullet'),
558
- MDLess.theme['list']['ul_char'],
558
+ MDLess.theme['list']['ul_char'].strip,
559
559
  ' ',
560
560
  color('list color'),
561
561
  indent_lines(content, indent).strip,
@@ -941,7 +941,7 @@ module Redcarpet
941
941
  def highlight_tags(input)
942
942
  tag_color = color('at_tags tag')
943
943
  value_color = color('at_tags value')
944
- input.gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("']+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
944
+ input.gsub(/(?<pre>\s|m)(?<tag>@[^ \]:;.?!,("'\n]+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
945
945
  m = Regexp.last_match
946
946
  last_color = m.pre_match.last_color_code
947
947
  [
@@ -146,6 +146,7 @@ module CLIMarkdown
146
146
  theme = File.expand_path("~/.config/mdless/#{theme}.theme")
147
147
  File.open(theme, 'w') { |f| f.puts(YAML.dump(MDLess.theme)) } unless File.exist?(theme)
148
148
  `#{ENV['EDITOR']} '#{theme}'`
149
+ Process.exit 0
149
150
  end
150
151
 
151
152
  default(:inline_footnotes, false)
@@ -212,10 +213,15 @@ module CLIMarkdown
212
213
  end
213
214
 
214
215
  default(:update_config, false)
215
- opts.on('--update_config', 'Update the configuration file with new keys and current command line options') do
216
+ opts.on('--update-config', '--update_config', 'Update the configuration file with new keys and current command line options') do
216
217
  MDLess.options[:update_config] = true
217
218
  end
218
219
 
220
+ default(:update_theme, false)
221
+ opts.on('--update-theme', 'Update the current theme file with all available keys') do
222
+ MDLess.options[:update_theme] = true
223
+ end
224
+
219
225
  default(:wiki_links, false)
220
226
  opts.on('--[no-]wiki-links', 'Highlight [[wiki links]]') do |opt|
221
227
  MDLess.options[:wiki_links] = opt
@@ -229,6 +235,17 @@ module CLIMarkdown
229
235
  exit 1
230
236
  end
231
237
 
238
+ if MDLess.options[:update_theme]
239
+ FileUtils.mkdir_p(File.dirname(config))
240
+
241
+ theme = MDLess.options[:theme] =~ /default/ ? 'mdless' : MDLess.options[:theme]
242
+ theme = File.join(File.dirname(config), "#{theme}.theme")
243
+ contents = YAML.dump(MDLess.theme)
244
+
245
+ File.open(theme, 'w') { |f| f.puts contents }
246
+ Process.exit 0
247
+ end
248
+
232
249
  if !File.exist?(config) || MDLess.options[:update_config]
233
250
  FileUtils.mkdir_p(File.dirname(config))
234
251
  File.open(config, 'w') do |f|
@@ -236,6 +253,7 @@ module CLIMarkdown
236
253
  opts.delete(:list)
237
254
  opts.delete(:section)
238
255
  opts.delete(:update_config)
256
+ opts.delete(:update_theme)
239
257
  opts = opts.keys.map(&:to_s).sort.map { |k| [k.to_sym, opts[k.to_sym]] }.to_h
240
258
  f.puts YAML.dump(opts)
241
259
  warn "Config file saved to #{config}"
data/lib/mdless/hash.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module CLIMarkdown
2
+ # Hash helpers
2
3
  class ::Hash
3
- def deep_merge(second)
4
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
5
- self.merge(second.to_h, &merger)
6
- end
4
+ def deep_merge(second)
5
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
6
+ self.merge(second ? second.to_h : second, &merger)
7
+ end
7
8
  end
8
9
  end
data/lib/mdless/string.rb CHANGED
@@ -107,7 +107,7 @@ class ::String
107
107
  log = MDLess.log
108
108
  tag_color = color('at_tags tag')
109
109
  value_color = color('at_tags value')
110
- gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("'\n]+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
110
+ gsub(/(?<pre>\s|m)(?<tag>@[^ \]:;.?!,("'\n]+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?(?=[ ;!,.?]|$)/) do
111
111
  m = Regexp.last_match
112
112
  last_color = m.pre_match.last_color_code
113
113
  [
data/lib/mdless/theme.rb CHANGED
@@ -66,6 +66,7 @@ module CLIMarkdown
66
66
  },
67
67
  'code_block' => {
68
68
  'marker' => 'intense_black',
69
+ 'character' => '>',
69
70
  'bg' => 'on_black',
70
71
  'color' => 'white on_black',
71
72
  'border' => 'blue',
@@ -118,16 +119,21 @@ module CLIMarkdown
118
119
  }
119
120
 
120
121
  def load_theme_file(theme_file)
121
- new_theme = YAML.load(IO.read(theme_file))
122
+ raise "Theme #{theme_file} doesn't exist" unless File.exist?(theme_file)
123
+
122
124
  begin
125
+ theme_contents = IO.read(theme_file)
126
+ new_theme = YAML.load(theme_contents)
123
127
  theme = THEME_DEFAULTS.deep_merge(new_theme)
124
128
  # # write merged theme back in case there are new keys since
125
129
  # # last updated
126
130
  # File.open(theme_file,'w') {|f|
127
131
  # f.puts theme.to_yaml
128
132
  # }
129
- rescue StandardError
133
+ rescue StandardError => e
130
134
  @log.warn('Error merging user theme')
135
+ warn e
136
+ warn e.backtrace
131
137
  theme = THEME_DEFAULTS
132
138
  if File.basename(theme_file) =~ /mdless\.theme/
133
139
  FileUtils.rm(theme_file)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.1.7'
4
+ VERSION = '2.1.9'
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.7
4
+ version: 2.1.9
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-12-01 00:00:00.000000000 Z
11
+ date: 2023-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet