mdless 1.0.6 → 1.0.12

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: 838d2a736014669c73bd615bffdb9336fed0cfb761a2999cd1a00edb429b7178
4
- data.tar.gz: 581e295c6e40b55ad424a4211e5475428ed492247f2ddb63015ba1060011a8a6
3
+ metadata.gz: 29be6a1b5ddb07f00761ef4ecba63116f6b0d3bbe78545536afb5382aa660a53
4
+ data.tar.gz: d5d08419668aab7a534a2c67ccb27e0a3a8d7d0b10e1793c6b4a087c591312ec
5
5
  SHA512:
6
- metadata.gz: 3c5c4260f4912d22d0c5c053d30d81222b5865a481f7985439041696a4174c87f018e272bf094910325e1ce533f22ed8b0f250ea2894aadcfbe4799d55e80909
7
- data.tar.gz: 234cee6e1ab695ff44c5202d0afb6a770166946bb6019e1f26caf770caefc9ffe4c979276e77f89a152ae9cef0a335668e60db9c9f127e6313ccdeb6ed144aaf
6
+ metadata.gz: a76b8fc03d9300c13bc58f73f80db23226cb01a6bf3141718c3cd96c7d947a4db02fcd36b8666ada394749677f2debbebf591e682418ce637ddf3df67d899ff1
7
+ data.tar.gz: 31485111a1836fcc4105a2d33addf4f18ac3180ce0ba7c35f6cf7b85a1d10d46666537478de913672548186f9d25048743340bf86747bd811ba52817172f21a5
data/README.md CHANGED
@@ -21,6 +21,7 @@ I often use iTerm2 in visor mode, so `qlmanage -p` is annoying. I still wanted a
21
21
  - List headlines in document
22
22
  - Display single section of the document based on headlines
23
23
  - Customizable colors
24
+ - Add iTerm marks for h1-3 navigation when pager is disabled
24
25
 
25
26
  ## Installation
26
27
 
@@ -41,7 +41,7 @@ module CLIMarkdown
41
41
 
42
42
  @options[:local_images] = false
43
43
  @options[:remote_images] = false
44
- opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires imgcat and iTerm2, default NONE)' ) do |type|
44
+ opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires imgcat and iTerm2, default NONE). Does not work with pagers, use with -P' ) do |type|
45
45
  unless exec_available('imgcat')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
46
46
  @log.warn('images turned on but imgcat not found')
47
47
  else
@@ -154,6 +154,7 @@ module CLIMarkdown
154
154
  $stderr.puts "No input"
155
155
  Process.exit 1
156
156
  end
157
+
157
158
  end
158
159
 
159
160
  def color(key)
@@ -209,6 +210,7 @@ module CLIMarkdown
209
210
  ]
210
211
  }
211
212
  end
213
+
212
214
  @headers
213
215
  end
214
216
 
@@ -269,11 +271,15 @@ module CLIMarkdown
269
271
  first = true
270
272
  input.split(/\n/).map{|line|
271
273
  if first
272
- first = false
273
- line.gsub!(/\|/, "#{color('table border')}|#{color('table header')}")
274
- elsif line.strip =~ /^[|:\- ]+$/
274
+ if line =~ /^\+-+/
275
+ line.gsub!(/^/, color('table border'))
276
+ else
277
+ first = false
278
+ line.gsub!(/\|/, "#{color('table border')}|#{color('table header')}")
279
+ end
280
+ elsif line.strip =~ /^[|:\- +]+$/
275
281
  line.gsub!(/^(.*)$/, "#{color('table border')}\\1#{color('table color')}")
276
- line.gsub!(/([:\-]+)/,"#{color('table divider')}\\1#{color('table border')}")
282
+ line.gsub!(/([:\-+]+)/,"#{color('table divider')}\\1#{color('table border')}")
277
283
  else
278
284
  line.gsub!(/\|/, "#{color('table border')}|#{color('table color')}")
279
285
  end
@@ -281,6 +287,7 @@ module CLIMarkdown
281
287
  end
282
288
 
283
289
  def cleanup_tables(input)
290
+
284
291
  in_table = false
285
292
  header_row = false
286
293
  all_content = []
@@ -307,6 +314,7 @@ module CLIMarkdown
307
314
  end
308
315
 
309
316
  table = this_table.join("\n").strip
317
+
310
318
  begin
311
319
  formatted = MDTableCleanup.new(table)
312
320
  res = formatted.to_md
@@ -331,6 +339,7 @@ module CLIMarkdown
331
339
 
332
340
  def clean_markers(input)
333
341
  input.gsub!(/^(\e\[[\d;]+m)?[%~] ?/,'\1')
342
+ input.gsub!(/(\e\[[\d;]+m)?@@@(\e\[[\d;]+m)?$/,'')
334
343
  input
335
344
  end
336
345
 
@@ -446,7 +455,7 @@ module CLIMarkdown
446
455
  new_code_line,
447
456
  xc
448
457
  ].join
449
- end.join("\n") + "\n"
458
+ end.join("\n")
450
459
  end
451
460
 
452
461
  [
@@ -473,6 +482,7 @@ module CLIMarkdown
473
482
 
474
483
  def convert_markdown(input)
475
484
  @headers = get_headers(input)
485
+ input += "\n\n@@@"
476
486
  # yaml/MMD headers
477
487
  in_yaml = false
478
488
  if input.split("\n")[0] =~ /(?i-m)^---[ \t]*?(\n|$)/
@@ -793,8 +803,8 @@ module CLIMarkdown
793
803
 
794
804
  # Headlines
795
805
  @headers.each {|h|
796
- input.sub!(/^#{h[2]}/) do |m|
797
- pad = ""
806
+ input.sub!(/^#{Regexp.escape(h[2])}/m) do |m|
807
+ pad = ''
798
808
  ansi = ''
799
809
  case h[0].length
800
810
  when 1
@@ -817,6 +827,14 @@ module CLIMarkdown
817
827
  ansi = color('h6 color')
818
828
  end
819
829
 
830
+ # If we're in iTerm and not paginating, add
831
+ # iTerm Marks for navigation on h1-3
832
+ if h[0].length < 4 &&
833
+ ENV['TERM_PROGRAM'] =~ /^iterm/i &&
834
+ @options[:pager] == false
835
+ ansi = "\e]1337;SetMark\a" + ansi
836
+ end
837
+
820
838
  "\n#{xc}#{ansi}#{h[1]} #{pad}#{xc}\n"
821
839
  end
822
840
  }
@@ -920,9 +938,13 @@ module CLIMarkdown
920
938
  end
921
939
  end
922
940
 
923
- read_io.close
924
- write_io.write(text)
925
- write_io.close
941
+ begin
942
+ read_io.close
943
+ write_io.write(text)
944
+ write_io.close
945
+ rescue SystemCallError => e
946
+ exit 1
947
+ end
926
948
 
927
949
  _, status = Process.waitpid2(pid)
928
950
  status.success?
@@ -941,7 +963,7 @@ module CLIMarkdown
941
963
 
942
964
  out = cleanup_tables(out)
943
965
  out = clean_markers(out)
944
- out = out.gsub(/\n+{2,}/m,"\n\n") + "\n#{xc}\n\n"
966
+ out = out.gsub(/\n+{2,}/m,"\n\n") + "\n#{xc}\n"
945
967
 
946
968
  unless @options[:color]
947
969
  out.uncolor!
@@ -1,6 +1,8 @@
1
1
  module CLIMarkdown
2
2
  class MDTableCleanup
3
3
 
4
+ PAD_CHAR = '⎕'
5
+
4
6
  def initialize(input)
5
7
  @string = input
6
8
  @format_row = []
@@ -25,10 +27,11 @@ module CLIMarkdown
25
27
  end
26
28
 
27
29
  format.each_with_index {|cell, i|
30
+ cell.strip!
28
31
  f = 'left'
29
32
  if cell =~ /^:.*?:$/
30
33
  f = 'center'
31
- elsif cell =~ /:$/
34
+ elsif cell =~ /[^:]+:$/
32
35
  f = 'right'
33
36
  else
34
37
  f = 'just'
@@ -81,13 +84,13 @@ module CLIMarkdown
81
84
  def pad(string,type,length)
82
85
  string.strip!
83
86
  if type == 'center'
84
- string.center(length, ' ')
87
+ string.center(length, PAD_CHAR)
85
88
  elsif type == 'right'
86
- string.rjust(length, ' ')
89
+ string.rjust(length, PAD_CHAR)
87
90
  elsif type == 'left'
88
- string.ljust(length, ' ')
91
+ string.ljust(length, PAD_CHAR)
89
92
  else
90
- string.ljust(length, ' ')
93
+ string.ljust(length, PAD_CHAR)
91
94
  end
92
95
  end
93
96
 
@@ -114,6 +117,14 @@ module CLIMarkdown
114
117
  "|#{output.join('|')}|"
115
118
  end
116
119
 
120
+ def table_border
121
+ output = []
122
+ @format_row.each_with_index do |column, i|
123
+ output.push separator(column_width(i), column)
124
+ end
125
+ "+#{output.join('+').gsub(/:/,'-')}+"
126
+ end
127
+
117
128
  def to_md
118
129
  output = []
119
130
  t = table.clone
@@ -123,7 +134,12 @@ module CLIMarkdown
123
134
  output.push("| #{row.join(' | ').lstrip} |")
124
135
  end
125
136
  output.insert(1, header_separator_row)
126
- output.join("\n")
137
+ output.insert(0, table_border)
138
+ output.push(table_border)
139
+
140
+ output.join("\n").gsub(/((?<=\| )#{PAD_CHAR}+|#{PAD_CHAR}+(?= \|))/) {|m|
141
+ " "*m.length
142
+ }
127
143
  end
128
144
  end
129
145
  end
@@ -80,7 +80,8 @@ module CLIMarkdown
80
80
  'border' => 'd black',
81
81
  'header' => 'yellow',
82
82
  'divider' => 'b black',
83
- 'color' => 'white'
83
+ 'color' => 'white',
84
+ 'bg' => 'on_black'
84
85
  },
85
86
  'html' => {
86
87
  'brackets' => 'd yellow on_black',
@@ -100,6 +101,13 @@ module CLIMarkdown
100
101
  rescue
101
102
  @log.warn('Error merging user theme')
102
103
  theme = THEME_DEFAULTS
104
+ if File.basename(theme_file) =~ /mdless\.theme/
105
+ FileUtils.rm(theme_file)
106
+ @log.info("Rewriting default theme file to #{theme_file}")
107
+ File.open(theme_file,'w') {|f|
108
+ f.puts theme.to_yaml
109
+ }
110
+ end
103
111
  end
104
112
  theme
105
113
  end
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.12'
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.6
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.6
106
+ rubygems_version: 3.0.3
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A pager like less, but for Markdown files