mdless 1.0.31 → 1.0.32
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 +4 -4
- data/README.md +4 -2
- data/bin/mdless +4 -3
- data/lib/mdless/converter.rb +17 -21
- data/lib/mdless/theme.rb +96 -100
- data/lib/mdless/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa89ffe14d9828b457116dde396a11bde06bbe58a258f721b5d0c0d2e5d381bf
|
4
|
+
data.tar.gz: 2b12d4353cf2f836b0dea6491f7671fae7d269e8b3617cfc92ba8f90e58da0ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a0731cd6e4a7febf475f253406938726deebb1e1cbb5808e2048789ab5f695ba9e234656ce40316978eb12e7da2d08b4bed3b42d27614a89fd8ed2ceffa725
|
7
|
+
data.tar.gz: 9d74ae761471b840e816e4b15ceb81697bbccdf7331d5431a0845727599967383c361c890008bc795312f91374f243a0f6696b953e6c38b197377913a64b6b86
|
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# mdless
|
2
2
|
|
3
3
|
<!--README-->
|
4
|
+
|
4
5
|
`mdless` is a utility that provides a formatted and highlighted view of Markdown files in Terminal.
|
5
6
|
|
6
7
|
I often use iTerm2 in visor mode, so `qlmanage -p` is annoying. I still wanted a way to view Markdown files quickly and without cruft.
|
7
8
|
|
8
9
|
<!--GITHUB--><!--END GITHUB-->
|
9
|
-
<!--JEKYLL
|
10
|
+
<!--JEKYLL{% gif /uploads/2015/08/mdless.gif %}-->
|
10
11
|
|
11
12
|
## Features
|
12
13
|
|
@@ -17,7 +18,7 @@ I often use iTerm2 in visor mode, so `qlmanage -p` is annoying. I still wanted a
|
|
17
18
|
- Display footnotes after each paragraph
|
18
19
|
- Inline image display (local, optionally remote) if using iTerm2 2.9+
|
19
20
|
- Syntax highlighting when [Pygments](http://pygments.org/) is installed
|
20
|
-
- Only fenced code with a language defined (e.g.
|
21
|
+
- Only fenced code with a language defined (e.g. `python`) will be highlighted
|
21
22
|
- Languages can also be determined by hashbang in the code block
|
22
23
|
- List headlines in document
|
23
24
|
- Display single section of the document based on headlines
|
@@ -114,4 +115,5 @@ Use 'r' to reverse foreground and background colors. `r white on_black` would di
|
|
114
115
|
To set a background color, use `on_[color]` with one of the 8 colors. This can be used with foreground colors in the same setting, e.g. `white on_black`.
|
115
116
|
|
116
117
|
Use 'd' (dark) to indicate the darker version of a foreground color. On macOS (and possibly other systems) you can use the brighter version of a color by prefixing with "intense", e.g. `intense_red` or `on_intense_black`.
|
118
|
+
|
117
119
|
<!--END README-->
|
data/bin/mdless
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
3
4
|
require 'mdless'
|
4
5
|
|
5
6
|
def class_exists?(class_name)
|
6
7
|
klass = Module.const_get(class_name)
|
7
|
-
|
8
|
+
klass.is_a?(Class)
|
8
9
|
rescue NameError
|
9
|
-
|
10
|
+
false
|
10
11
|
end
|
11
12
|
|
12
13
|
if class_exists? 'Encoding'
|
data/lib/mdless/converter.rb
CHANGED
@@ -123,32 +123,32 @@ module CLIMarkdown
|
|
123
123
|
@footnotes = {}
|
124
124
|
|
125
125
|
if args.length > 0
|
126
|
-
files = args.delete_if { |f| !File.
|
127
|
-
files.each
|
128
|
-
@log.info(%
|
126
|
+
files = args.delete_if { |f| !File.exist?(f) }
|
127
|
+
files.each do |file|
|
128
|
+
@log.info(%(Processing "#{file}"))
|
129
129
|
@file = file
|
130
130
|
begin
|
131
131
|
input = IO.read(file).force_encoding('utf-8')
|
132
|
-
rescue
|
132
|
+
rescue StandardError
|
133
133
|
input = IO.read(file)
|
134
134
|
end
|
135
|
-
input.gsub!(/\r?\n/,"\n")
|
135
|
+
input.gsub!(/\r?\n/, "\n")
|
136
136
|
if @options[:list]
|
137
137
|
puts list_headers(input)
|
138
138
|
Process.exit 0
|
139
139
|
else
|
140
140
|
convert_markdown(input)
|
141
141
|
end
|
142
|
-
|
142
|
+
end
|
143
143
|
printout
|
144
|
-
elsif
|
144
|
+
elsif !$stdin.isatty
|
145
145
|
@file = nil
|
146
146
|
begin
|
147
|
-
input =
|
148
|
-
rescue
|
149
|
-
input =
|
147
|
+
input = $stdin.read.force_encoding('utf-8')
|
148
|
+
rescue StandardError
|
149
|
+
input = $stdin.read
|
150
150
|
end
|
151
|
-
input.gsub!(/\r?\n/,"\n")
|
151
|
+
input.gsub!(/\r?\n/, "\n")
|
152
152
|
if @options[:list]
|
153
153
|
puts list_headers(input)
|
154
154
|
Process.exit 0
|
@@ -157,7 +157,7 @@ module CLIMarkdown
|
|
157
157
|
end
|
158
158
|
printout
|
159
159
|
else
|
160
|
-
|
160
|
+
warn 'No input'
|
161
161
|
Process.exit 1
|
162
162
|
end
|
163
163
|
|
@@ -172,19 +172,17 @@ module CLIMarkdown
|
|
172
172
|
@log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
|
173
173
|
return c([:reset])
|
174
174
|
end
|
175
|
-
keys.each
|
175
|
+
keys.each do |k|
|
176
176
|
if val.key?(k)
|
177
177
|
val = val[k]
|
178
178
|
else
|
179
179
|
@log.error("Invalid theme key: #{k}")
|
180
180
|
return c([:reset])
|
181
181
|
end
|
182
|
-
|
183
|
-
if val.
|
182
|
+
end
|
183
|
+
if val.is_a? String
|
184
184
|
val = "x #{val}"
|
185
|
-
res = val.split(/ /).map {|k|
|
186
|
-
k.to_sym
|
187
|
-
}
|
185
|
+
res = val.split(/ /).map { |k| k.to_sym }
|
188
186
|
c(res)
|
189
187
|
else
|
190
188
|
c([:reset])
|
@@ -192,7 +190,7 @@ module CLIMarkdown
|
|
192
190
|
end
|
193
191
|
|
194
192
|
def get_headers(input)
|
195
|
-
unless @headers &&
|
193
|
+
unless @headers && !@headers.empty?
|
196
194
|
@headers = []
|
197
195
|
headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?\s*|(\S.+)\n([=-]+))$/i)
|
198
196
|
|
@@ -1042,8 +1040,6 @@ module CLIMarkdown
|
|
1042
1040
|
args = case pg
|
1043
1041
|
when 'delta'
|
1044
1042
|
' --pager="less -Xr"'
|
1045
|
-
when 'more'
|
1046
|
-
' -r'
|
1047
1043
|
when 'less'
|
1048
1044
|
' -Xr'
|
1049
1045
|
when 'bat'
|
data/lib/mdless/theme.rb
CHANGED
@@ -2,92 +2,92 @@ module CLIMarkdown
|
|
2
2
|
module Theme
|
3
3
|
|
4
4
|
THEME_DEFAULTS = {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
5
|
+
'metadata' => {
|
6
|
+
'border' => 'd blue on_black',
|
7
|
+
'marker' => 'd black on_black',
|
8
|
+
'color' => 'd white on_black'
|
9
|
+
},
|
10
|
+
'emphasis' => {
|
11
|
+
'bold' => 'b',
|
12
|
+
'italic' => 'u i',
|
13
|
+
'bold-italic' => 'b u i'
|
14
|
+
},
|
15
|
+
'h1' => {
|
16
|
+
'color' => 'b intense_black on_white',
|
17
|
+
'pad' => 'd black on_white',
|
18
|
+
'pad_char' => '='
|
19
|
+
},
|
20
|
+
'h2' => {
|
21
|
+
'color' => 'b white on_intense_black',
|
22
|
+
'pad' => 'd white on_intense_black',
|
23
|
+
'pad_char' => '-'
|
24
|
+
},
|
25
|
+
'h3' => {
|
26
|
+
'color' => 'u b yellow'
|
27
|
+
},
|
28
|
+
'h4' => {
|
29
|
+
'color' => 'u yellow'
|
30
|
+
},
|
31
|
+
'h5' => {
|
32
|
+
'color' => 'b white'
|
33
|
+
},
|
34
|
+
'h6' => {
|
35
|
+
'color' => 'b white'
|
36
|
+
},
|
37
|
+
'link' => {
|
38
|
+
'brackets' => 'b black',
|
39
|
+
'text' => 'u b blue',
|
40
|
+
'url' => 'cyan'
|
41
|
+
},
|
42
|
+
'image' => {
|
43
|
+
'bang' => 'red',
|
44
|
+
'brackets' => 'b black',
|
45
|
+
'title' => 'cyan',
|
46
|
+
'url' => 'u yellow'
|
47
|
+
},
|
48
|
+
'list' => {
|
49
|
+
'bullet' => 'b intense_red',
|
50
|
+
'number' => 'b intense_blue',
|
51
|
+
'color' => 'intense_white'
|
52
|
+
},
|
53
|
+
'footnote' => {
|
54
|
+
'brackets' => 'b black on_black',
|
55
|
+
'caret' => 'b yellow on_black',
|
56
|
+
'title' => 'x yellow on_black',
|
57
|
+
'note' => 'u white on_black'
|
58
|
+
},
|
59
|
+
'code_span' => {
|
60
|
+
'marker' => 'b white',
|
61
|
+
'color' => 'b white on_intense_black'
|
62
|
+
},
|
63
|
+
'code_block' => {
|
64
|
+
'marker' => 'intense_black',
|
65
|
+
'bg' => 'on_black',
|
66
|
+
'color' => 'white on_black',
|
67
|
+
'border' => 'blue',
|
68
|
+
'title' => 'magenta',
|
69
|
+
'eol' => 'intense_black on_black',
|
70
|
+
'pygments_theme' => 'monokai'
|
71
|
+
},
|
72
|
+
'dd' => {
|
73
|
+
'marker' => 'd red',
|
74
|
+
'color' => 'b white'
|
75
|
+
},
|
76
|
+
'hr' => {
|
77
|
+
'color' => 'd white'
|
78
|
+
},
|
79
|
+
'table' => {
|
80
|
+
'border' => 'd black',
|
81
|
+
'header' => 'yellow',
|
82
|
+
'divider' => 'b black',
|
83
|
+
'color' => 'white',
|
84
|
+
'bg' => 'on_black'
|
85
|
+
},
|
86
|
+
'html' => {
|
87
|
+
'brackets' => 'd yellow on_black',
|
88
|
+
'color' => 'yellow on_black'
|
90
89
|
}
|
90
|
+
}
|
91
91
|
|
92
92
|
def load_theme_file(theme_file)
|
93
93
|
new_theme = YAML.load(IO.read(theme_file))
|
@@ -98,15 +98,13 @@ module CLIMarkdown
|
|
98
98
|
# File.open(theme_file,'w') {|f|
|
99
99
|
# f.puts theme.to_yaml
|
100
100
|
# }
|
101
|
-
rescue
|
101
|
+
rescue StandardError
|
102
102
|
@log.warn('Error merging user theme')
|
103
103
|
theme = THEME_DEFAULTS
|
104
104
|
if File.basename(theme_file) =~ /mdless\.theme/
|
105
105
|
FileUtils.rm(theme_file)
|
106
106
|
@log.info("Rewriting default theme file to #{theme_file}")
|
107
|
-
File.open(theme_file,'w') {|f|
|
108
|
-
f.puts theme.to_yaml
|
109
|
-
}
|
107
|
+
File.open(theme_file, 'w') { |f| f.puts theme.to_yaml }
|
110
108
|
end
|
111
109
|
end
|
112
110
|
theme
|
@@ -114,12 +112,12 @@ module CLIMarkdown
|
|
114
112
|
|
115
113
|
def load_theme(theme)
|
116
114
|
config_dir = File.expand_path('~/.config/mdless')
|
117
|
-
default_theme_file = File.join(config_dir,'mdless.theme')
|
115
|
+
default_theme_file = File.join(config_dir, 'mdless.theme')
|
118
116
|
if theme =~ /default/i || !theme
|
119
117
|
theme_file = default_theme_file
|
120
118
|
else
|
121
|
-
theme = theme.strip.sub(/(\.theme)?$/,'.theme')
|
122
|
-
theme_file = File.join(config_dir,theme)
|
119
|
+
theme = theme.strip.sub(/(\.theme)?$/, '.theme')
|
120
|
+
theme_file = File.join(config_dir, theme)
|
123
121
|
end
|
124
122
|
|
125
123
|
unless File.directory?(config_dir)
|
@@ -127,16 +125,14 @@ module CLIMarkdown
|
|
127
125
|
FileUtils.mkdir_p(config_dir)
|
128
126
|
end
|
129
127
|
|
130
|
-
unless File.
|
131
|
-
|
128
|
+
unless File.exist?(theme_file)
|
129
|
+
if File.exist?(default_theme_file)
|
130
|
+
@log.info('Specified theme not found, using default')
|
131
|
+
theme_file = default_theme_file
|
132
|
+
else
|
132
133
|
theme = THEME_DEFAULTS
|
133
134
|
@log.info("Writing fresh theme file to #{theme_file}")
|
134
|
-
File.open(theme_file,'w') {|f|
|
135
|
-
f.puts theme.to_yaml
|
136
|
-
}
|
137
|
-
else
|
138
|
-
@log.info("Specified theme not found, using default")
|
139
|
-
theme_file = default_theme_file
|
135
|
+
File.open(theme_file, 'w') { |f| f.puts theme.to_yaml }
|
140
136
|
end
|
141
137
|
end
|
142
138
|
|
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.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|