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 +4 -4
- data/README.md +1 -0
- data/lib/mdless/converter.rb +24 -10
- data/lib/mdless/tables.rb +22 -6
- data/lib/mdless/theme.rb +2 -1
- data/lib/mdless/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d6da924affdfcd0e5be75373d3e8be870fe4300a63c7a462d8fb35fed5d9c1d
|
4
|
+
data.tar.gz: 9ac90ee12218b43104728cdffdff67c265f53d0f6cc4ac92a7adf1eaa59e8397
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/mdless/converter.rb
CHANGED
@@ -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
|
-
|
273
|
-
|
274
|
-
|
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!(/([
|
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")
|
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
|
-
|
932
|
-
|
933
|
-
|
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?
|
data/lib/mdless/tables.rb
CHANGED
@@ -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.
|
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
|
data/lib/mdless/theme.rb
CHANGED
data/lib/mdless/version.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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.
|
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
|