mdless 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/mdless/converter.rb +47 -32
- data/lib/mdless/version.rb +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618302eecf35ed202db845ca4ddd45fcb6f7df8c
|
4
|
+
data.tar.gz: 9413e7e0106c478d120d475efd4d62bde3075d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dba40280383d15349c27b69c91cb536ec2f63cdb787cba3da251738957a41e4e3b2a7a38bdf25d333d5cb452042e4d9b8516fe8983a8f17a0f31bd9151fa0ece
|
7
|
+
data.tar.gz: ecdd1dbdf0b44d29d4c34e74435ca38da3861c92df9d634ac2f90144f806c26313f46bf84cfe4fe51a6254479b26f062421c104825c806690a05fe07dbcc3928
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ I often use iTerm2 in visor mode, so `qlmanage -p` is annoying. I still wanted a
|
|
18
18
|
- Inline image display (local, optionally remote) if using iTerm2 2.9+
|
19
19
|
- Syntax highlighting when `pygmentize` is available
|
20
20
|
- List headlines in document
|
21
|
-
- Display section of the document
|
21
|
+
- Display single section of the document based on headlines
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -41,7 +41,7 @@ The pager used is determined by system configuration in this order of preference
|
|
41
41
|
### Options
|
42
42
|
|
43
43
|
-s, --section=TITLE Output only a headline-based section of
|
44
|
-
the input
|
44
|
+
the input (numeric based on --list output)
|
45
45
|
-w, --width=COLUMNS Column width to format for (default terminal width)
|
46
46
|
-p, --[no-]pager Formatted output to pager (default on)
|
47
47
|
-P Disable pager (same as --no-pager)
|
data/lib/mdless/converter.rb
CHANGED
@@ -17,8 +17,8 @@ module CLIMarkdown
|
|
17
17
|
opts.banner = "#{version} by Brett Terpstra\n\n> Usage: #{CLIMarkdown::EXECUTABLE_NAME} [options] path\n\n"
|
18
18
|
|
19
19
|
@options[:section] = nil
|
20
|
-
opts.on( '-s', '--section=TITLE', 'Output only a headline-based section of the input' ) do |section|
|
21
|
-
@options[:section] = section
|
20
|
+
opts.on( '-s', '--section=TITLE', 'Output only a headline-based section of the input (numeric from -l)' ) do |section|
|
21
|
+
@options[:section] = section.to_i
|
22
22
|
end
|
23
23
|
|
24
24
|
@options[:width] = %x{tput cols}.strip.to_i
|
@@ -95,6 +95,7 @@ module CLIMarkdown
|
|
95
95
|
|
96
96
|
@cols = @options[:width]
|
97
97
|
@output = ''
|
98
|
+
@header_arr = []
|
98
99
|
|
99
100
|
input = ''
|
100
101
|
@ref_links = {}
|
@@ -138,6 +139,14 @@ module CLIMarkdown
|
|
138
139
|
end
|
139
140
|
end
|
140
141
|
|
142
|
+
def get_headers(input)
|
143
|
+
unless @headers && @headers.length > 0
|
144
|
+
@headers = input.scan(/^(#+)\s*(.*?)( #+)?\s*$/)
|
145
|
+
end
|
146
|
+
@headers
|
147
|
+
end
|
148
|
+
|
149
|
+
|
141
150
|
def list_headers(input)
|
142
151
|
h_adjust = highest_header(input) - 1
|
143
152
|
input.gsub!(/^(#+)/) do |m|
|
@@ -150,35 +159,36 @@ module CLIMarkdown
|
|
150
159
|
end
|
151
160
|
end
|
152
161
|
|
153
|
-
headers =
|
162
|
+
@headers = get_headers(input)
|
154
163
|
last_level = 0
|
155
|
-
|
156
|
-
|
157
|
-
level = $1.size - 1
|
158
|
-
title = $2
|
164
|
+
headers_out = []
|
165
|
+
@headers.each_with_index do |h,idx|
|
159
166
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
subdoc = case level
|
166
|
-
when 0
|
167
|
-
' '
|
168
|
-
when 1
|
169
|
-
'- '
|
170
|
-
when 2
|
171
|
-
'+ '
|
172
|
-
when 3
|
173
|
-
'* '
|
174
|
-
else
|
175
|
-
' '
|
176
|
-
end
|
177
|
-
headers.push((" "*level) + (c([:x, :yellow]) + subdoc + title.strip + xc))
|
167
|
+
level = h[0].length - 1
|
168
|
+
title = h[1]
|
169
|
+
|
170
|
+
if level - 1 > last_level
|
171
|
+
level = last_level + 1
|
178
172
|
end
|
173
|
+
last_level = level
|
174
|
+
|
175
|
+
subdoc = case level
|
176
|
+
when 0
|
177
|
+
''
|
178
|
+
when 1
|
179
|
+
'- '
|
180
|
+
when 2
|
181
|
+
'+ '
|
182
|
+
when 3
|
183
|
+
'* '
|
184
|
+
else
|
185
|
+
' '
|
186
|
+
end
|
187
|
+
line_no = '%2d: ' % (idx + 1)
|
188
|
+
headers_out.push(%Q{#{line_no}#{c([:x, :black])}#{".."*level}#{c([:x, :yellow])}#{subdoc}#{title.strip}#{xc}}.strip)
|
179
189
|
end
|
180
190
|
|
181
|
-
@output +=
|
191
|
+
@output += headers_out.join("\n")
|
182
192
|
end
|
183
193
|
|
184
194
|
def highest_header(input)
|
@@ -298,7 +308,7 @@ module CLIMarkdown
|
|
298
308
|
end
|
299
309
|
|
300
310
|
def convert_markdown(input)
|
301
|
-
|
311
|
+
@headers = get_headers(input)
|
302
312
|
# yaml/MMD headers
|
303
313
|
in_yaml = false
|
304
314
|
if input.split("\n")[0] =~ /(?i-m)^---[ \t]*?(\n|$)/
|
@@ -364,14 +374,15 @@ module CLIMarkdown
|
|
364
374
|
title = $2
|
365
375
|
|
366
376
|
if in_section
|
367
|
-
if level
|
377
|
+
if level >= top_level
|
368
378
|
new_content.push(graf)
|
369
379
|
else
|
380
|
+
in_section = false
|
370
381
|
break
|
371
382
|
end
|
372
|
-
elsif title.downcase
|
383
|
+
elsif title.downcase == "#{@headers[@options[:section] - 1][1].downcase}"
|
373
384
|
in_section = true
|
374
|
-
top_level = level
|
385
|
+
top_level = level + 1
|
375
386
|
new_content.push(graf)
|
376
387
|
else
|
377
388
|
next
|
@@ -669,7 +680,7 @@ module CLIMarkdown
|
|
669
680
|
if File.exists?(File.expand_path(cli))
|
670
681
|
File.executable?(File.expand_path(cli))
|
671
682
|
else
|
672
|
-
system "which #{cli}
|
683
|
+
system "which #{cli}", :out => File::NULL
|
673
684
|
end
|
674
685
|
end
|
675
686
|
|
@@ -735,7 +746,11 @@ module CLIMarkdown
|
|
735
746
|
'less', 'more', 'cat', 'pager']
|
736
747
|
pagers.select! do |f|
|
737
748
|
if f
|
738
|
-
|
749
|
+
if f.strip =~ /[ |]/
|
750
|
+
f
|
751
|
+
else
|
752
|
+
system "which #{f}", :out => File::NULL
|
753
|
+
end
|
739
754
|
else
|
740
755
|
false
|
741
756
|
end
|
data/lib/mdless/version.rb
CHANGED
metadata
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
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: 2018-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
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
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '4.1'
|
34
|
-
- -
|
34
|
+
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 4.1.1
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '4.1'
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 4.1.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: aruba
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ~>
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
description: A CLI that provides a formatted and highlighted view of Markdown files
|
@@ -80,29 +80,29 @@ licenses:
|
|
80
80
|
metadata: {}
|
81
81
|
post_install_message:
|
82
82
|
rdoc_options:
|
83
|
-
- --title
|
83
|
+
- "--title"
|
84
84
|
- mdless
|
85
|
-
- --main
|
85
|
+
- "--main"
|
86
86
|
- README.md
|
87
|
-
- --markup
|
87
|
+
- "--markup"
|
88
88
|
- markdown
|
89
|
-
- -ri
|
89
|
+
- "-ri"
|
90
90
|
require_paths:
|
91
91
|
- lib
|
92
92
|
- lib
|
93
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.6.13
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: A pager like less, but for Markdown files
|