mdless 1.0.31 → 1.0.32

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: 4e0a66c5ea1522d66b1cca9ad1e74e66b4e5dd301fd5b42eb9ff20d912074c02
4
- data.tar.gz: 75e46348a488ae50975f931b3164a127ae085d53b1eba3ebd1264ce19e5c6048
3
+ metadata.gz: fa89ffe14d9828b457116dde396a11bde06bbe58a258f721b5d0c0d2e5d381bf
4
+ data.tar.gz: 2b12d4353cf2f836b0dea6491f7671fae7d269e8b3617cfc92ba8f90e58da0ce
5
5
  SHA512:
6
- metadata.gz: 362da8ff8940e858a31a5c40a375454d54b0632bfef39ab50426257424887115f56dfe92909ba00e365a6953c7c4381db34a3bb4b78995702c2e9668d82506c7
7
- data.tar.gz: 0e1df0694ecfc053517aa22cd0430e554dc06742a3443d37648f15cd2db82f97b5de697f18ab2982d9511d30d68a4165c813c23a8cfc33363bba92170cd539c3
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-->![mdless screenshot](screenshots/mdless.png)<!--END GITHUB-->
9
- <!--JEKYLL {% gif /uploads/2015/08/mdless.gif %} -->
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. `\`\`\`python`) will be highlighted
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
- # coding: utf-8
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
- return klass.is_a?(Class)
8
+ klass.is_a?(Class)
8
9
  rescue NameError
9
- return false
10
+ false
10
11
  end
11
12
 
12
13
  if class_exists? 'Encoding'
@@ -123,32 +123,32 @@ module CLIMarkdown
123
123
  @footnotes = {}
124
124
 
125
125
  if args.length > 0
126
- files = args.delete_if { |f| !File.exists?(f) }
127
- files.each {|file|
128
- @log.info(%Q{Processing "#{file}"})
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 ! STDIN.tty?
144
+ elsif !$stdin.isatty
145
145
  @file = nil
146
146
  begin
147
- input = STDIN.read.force_encoding('utf-8')
148
- rescue
149
- input = STDIN.read
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
- $stderr.puts "No input"
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 {|k|
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.kind_of? String
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 && @headers.length > 0
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
- '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'
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.exists?(theme_file)
131
- unless File.exists?(default_theme_file)
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
 
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.31'
2
+ VERSION = '1.0.32'
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.31
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-02 00:00:00.000000000 Z
11
+ date: 2022-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake