mdless 1.0.7 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b79330028da2d98251af174cfb9f0ae60294efa6e24de4cff88d245c351340f3
4
- data.tar.gz: 22c669286e9486f739badc7e74819e1989fb00fc1f415c9e3fd371e60b1a6026
3
+ metadata.gz: 1d6da924affdfcd0e5be75373d3e8be870fe4300a63c7a462d8fb35fed5d9c1d
4
+ data.tar.gz: 9ac90ee12218b43104728cdffdff67c265f53d0f6cc4ac92a7adf1eaa59e8397
5
5
  SHA512:
6
- metadata.gz: 719d4170904c7fd9bc21e5cc4f19ca1a9f5a197d891e211bb29bfd1eecb94cf7d1b9af22943dc253bae4a2ffa0baa91233aae84005752bc5b5f1660ff539dcfa
7
- data.tar.gz: e69bbfb47daf84166fe3cf930601a5fbbaedbd57453c9361547c3b1c6c9cdfb170b4c4a641793a497f23547a3781097e47100a3a8272a8820f4faeb6d4f4de8a
6
+ metadata.gz: 19c6121272e4975a75acc7e7e60a5cd00f842341a560fb795faa125ec5ebcfad794470d44932d142620a60c8d5627a127c7e95c057e5f2904ac821ed40041dc5
7
+ data.tar.gz: 4e6eeeb8179b8981675153ac389e90e532c33939c4df4d1f00d5a773c4c547533519bfaf4a32a7e87ea0f0425ab9431d96a3aae9afb0cc19b96cc6c8cb798589
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
 
@@ -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
@@ -928,9 +938,13 @@ module CLIMarkdown
928
938
  end
929
939
  end
930
940
 
931
- read_io.close
932
- write_io.write(text)
933
- 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
934
948
 
935
949
  _, status = Process.waitpid2(pid)
936
950
  status.success?
@@ -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',
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.13'
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.7
4
+ version: 1.0.13
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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '13'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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