mdless 1.0.2 → 1.0.3

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: 60b3541746585a41e0cdd5ef8d078b7c64c3afa7024710f5a0af7d22b33e8722
4
- data.tar.gz: 5e877c78b1924f7d34b1b13225702d6c236c75c0055cd7c3c2aea78c1dc802d8
3
+ metadata.gz: 47c92338d7793e3f3e394164c31eaae071933aaca4b468f09e507835ceb41512
4
+ data.tar.gz: fb290c4a11f812e06bfb48699b903c91565c8c57e437a6689430ed98dd7bf6ad
5
5
  SHA512:
6
- metadata.gz: 60bffe2be11c62398ccba8e29c95f786b6eb9cdc0e86cf79dca7b3d29554426e75bf7221d01f6c52270075e8732fe26a554da2948e6a47598d7507dcfb928177
7
- data.tar.gz: 44cde0fea6749c4d71a29c044dcece8385663c65e2540a2cbbb24d758895e371917f6e710dd0f599b416412b709b22dd15dfad7a8866b119eb40599eefaa5dfe
6
+ metadata.gz: 8d9a492f4f485aa43e19315f5526d3dba15b30b2e81420ff24f8e2dbd3bdb1a8335370c02e6c7d535d0a2b6c0f3904c21ad85fa4f81ca0aab8dc0713ac201863
7
+ data.tar.gz: 34c641d25c5b277e1cb9c0109df760cb1f9c179982447feeaafcaac1ada440b4e2cfc742f203176b20c09a1700c4a4c2d351f66b670f48748ae22b2de98d280a
@@ -6,6 +6,8 @@ require 'logger'
6
6
  require 'mdless/version.rb'
7
7
  require 'mdless/colors'
8
8
  require 'mdless/tables'
9
+ require 'mdless/hash'
10
+ require 'mdless/theme'
9
11
  require 'mdless/converter'
10
12
 
11
13
  module CLIMarkdown
@@ -1,16 +1,10 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
3
 
4
- class ::Hash
5
- def deep_merge(second)
6
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
7
- self.merge(second.to_h, &merger)
8
- end
9
- end
10
-
11
4
  module CLIMarkdown
12
5
  class Converter
13
6
  include Colors
7
+ include Theme
14
8
 
15
9
  attr_reader :helpers, :log
16
10
 
@@ -22,167 +16,31 @@ module CLIMarkdown
22
16
  @log = Logger.new(STDERR)
23
17
  @log.level = Logger::ERROR
24
18
 
25
- config_dir = File.expand_path('~/.config/mdless')
26
- theme_file = File.join(config_dir,'mdless.theme')
27
-
28
- theme_defaults = {
29
- 'metadata' => {
30
- 'border' => 'd blue on_black',
31
- 'marker' => 'd black on_black',
32
- 'color' => 'd white on_black'
33
- },
34
- 'emphasis' => {
35
- 'bold' => 'b',
36
- 'italic' => 'u i',
37
- 'bold-italic' => 'b u i'
38
- },
39
- 'h1' => {
40
- 'color' => 'b intense_black on_white',
41
- 'pad' => 'd black on_white',
42
- 'pad_char' => '='
43
- },
44
- 'h2' => {
45
- 'color' => 'b white on_intense_black',
46
- 'pad' => 'd white on_intense_black',
47
- 'pad_char' => '-'
48
- },
49
- 'h3' => {
50
- 'color' => 'u b yellow'
51
- },
52
- 'h4' => {
53
- 'color' => 'u yellow'
54
- },
55
- 'h5' => {
56
- 'color' => 'b white'
57
- },
58
- 'h6' => {
59
- 'color' => 'b white'
60
- },
61
- 'link' => {
62
- 'brackets' => 'b black',
63
- 'text' => 'u b blue',
64
- 'url' => 'cyan'
65
- },
66
- 'image' => {
67
- 'bang' => 'red',
68
- 'brackets' => 'b black',
69
- 'title' => 'cyan',
70
- 'url' => 'u yellow'
71
- },
72
- 'list' => {
73
- 'bullet' => 'b intense_red',
74
- 'number' => 'b intense_blue',
75
- 'color' => 'intense_white'
76
- },
77
- 'footnote' => {
78
- 'brackets' => 'b black on_black',
79
- 'caret' => 'b yellow on_black',
80
- 'title' => 'x yellow on_black',
81
- 'note' => 'u white on_black'
82
- },
83
- 'code_span' => {
84
- 'marker' => 'b white',
85
- 'color' => 'b black on_intense_blue'
86
- },
87
- 'code_block' => {
88
- 'marker' => 'intense_black',
89
- 'bg' => 'on_black',
90
- 'color' => 'white on_black',
91
- 'border' => 'blue',
92
- 'title' => 'magenta',
93
- 'eol' => 'intense_black on_black',
94
- 'pygments_theme' => 'monokai'
95
- },
96
- 'dd' => {
97
- 'marker' => 'd red',
98
- 'color' => 'b white'
99
- },
100
- 'hr' => {
101
- 'color' => 'd white'
102
- },
103
- 'table' => {
104
- 'border' => 'd black',
105
- 'header' => 'yellow',
106
- 'divider' => 'b black',
107
- 'color' => 'white'
108
- },
109
- 'html' => {
110
- 'brackets' => 'd yellow on_black',
111
- 'color' => 'yellow on_black'
112
- }
113
- }
114
-
115
- unless File.directory?(config_dir)
116
- @log.info("Creating config directory at #{config_dir}")
117
- FileUtils.mkdir_p(config_dir)
118
- end
119
-
120
- unless File.exists?(theme_file)
121
- @log.info("Writing fresh theme file to #{theme_file}")
122
- File.open(theme_file,'w') {|f|
123
- f.puts @theme.to_yaml
124
- }
125
- @theme = theme_defaults
126
- else
127
- new_theme = YAML.load(IO.read(theme_file))
128
- begin
129
- @theme = theme_defaults.deep_merge(new_theme)
130
- # write merged theme back in case there are new keys since
131
- # last updated
132
- File.open(theme_file,'w') {|f|
133
- f.puts @theme.to_yaml
134
- }
135
- rescue
136
- @log.warn('Error merging user theme')
137
- @theme = theme_defaults
138
- end
139
- end
140
-
141
-
142
19
  @options = {}
143
20
  optparse = OptionParser.new do |opts|
144
21
  opts.banner = "#{version} by Brett Terpstra\n\n> Usage: #{CLIMarkdown::EXECUTABLE_NAME} [options] [path]\n\n"
145
22
 
146
- @options[:section] = nil
147
- opts.on( '-s', '--section=NUMBER', 'Output only a headline-based section of the input (numeric from --list)' ) do |section|
148
- @options[:section] = section.to_i
149
- end
150
-
151
- @options[:width] = %x{tput cols}.strip.to_i
152
- opts.on( '-w', '--width=COLUMNS', 'Column width to format for (default terminal width)' ) do |columns|
153
- @options[:width] = columns.to_i
154
- end
155
-
156
- @options[:pager] = true
157
- opts.on( '-p', '--[no-]pager', 'Formatted output to pager (default on)' ) do |p|
158
- @options[:pager] = p
159
- end
160
-
161
- opts.on( '-P', 'Disable pager (same as --no-pager)' ) do
162
- @options[:pager] = false
163
- end
164
-
165
23
  @options[:color] = true
166
24
  opts.on( '-c', '--[no-]color', 'Colorize output (default on)' ) do |c|
167
25
  @options[:color] = c
168
26
  end
169
27
 
170
- @options[:links] = :inline
171
- opts.on( '--links=FORMAT', 'Link style ([inline, reference], default inline) [NOT CURRENTLY IMPLEMENTED]' ) do |format|
172
- if format =~ /^r/i
173
- @options[:links] = :reference
28
+ opts.on( '-d', '--debug LEVEL', 'Level of debug messages to output' ) do |level|
29
+ if level.to_i > 0 && level.to_i < 5
30
+ @log.level = 5 - level.to_i
31
+ else
32
+ $stderr.puts "Error: Log level out of range (1-4)"
33
+ Process.exit 1
174
34
  end
175
35
  end
176
36
 
177
- @options[:list] = false
178
- opts.on( '-l', '--list', 'List headers in document and exit' ) do
179
- @options[:list] = true
37
+ opts.on( '-h', '--help', 'Display this screen' ) do
38
+ puts opts
39
+ exit
180
40
  end
181
41
 
182
42
  @options[:local_images] = false
183
43
  @options[:remote_images] = false
184
-
185
-
186
44
  opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires imgcat and iTerm2, default NONE)' ) do |type|
187
45
  unless exec_available('imgcat')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
188
46
  @log.warn('images turned on but imgcat not found')
@@ -204,29 +62,51 @@ module CLIMarkdown
204
62
  end
205
63
  end
206
64
 
207
-
208
- opts.on( '-d', '--debug LEVEL', 'Level of debug messages to output' ) do |level|
209
- if level.to_i > 0 && level.to_i < 5
210
- @log.level = 5 - level.to_i
211
- else
212
- $stderr.puts "Error: Log level out of range (1-4)"
213
- Process.exit 1
65
+ @options[:links] = :inline
66
+ opts.on( '--links=FORMAT', 'Link style ([inline, reference], default inline) [NOT CURRENTLY IMPLEMENTED]' ) do |format|
67
+ if format =~ /^r/i
68
+ @options[:links] = :reference
214
69
  end
215
70
  end
216
71
 
217
- opts.on( '-h', '--help', 'Display this screen' ) do
218
- puts opts
219
- exit
72
+ @options[:list] = false
73
+ opts.on( '-l', '--list', 'List headers in document and exit' ) do
74
+ @options[:list] = true
75
+ end
76
+
77
+ @options[:pager] = true
78
+ opts.on( '-p', '--[no-]pager', 'Formatted output to pager (default on)' ) do |p|
79
+ @options[:pager] = p
80
+ end
81
+
82
+ opts.on( '-P', 'Disable pager (same as --no-pager)' ) do
83
+ @options[:pager] = false
84
+ end
85
+
86
+ @options[:section] = nil
87
+ opts.on( '-s', '--section=NUMBER', 'Output only a headline-based section of the input (numeric from --list)' ) do |section|
88
+ @options[:section] = section.to_i
89
+ end
90
+
91
+ @options[:theme] = 'default'
92
+ opts.on( '-t', '--theme=THEME_NAME', 'Specify an alternate color theme to load' ) do |theme|
93
+ @options[:theme] = theme
220
94
  end
221
95
 
222
96
  opts.on( '-v', '--version', 'Display version number' ) do
223
97
  puts version
224
98
  exit
225
99
  end
100
+
101
+ @options[:width] = %x{tput cols}.strip.to_i
102
+ opts.on( '-w', '--width=COLUMNS', 'Column width to format for (default terminal width)' ) do |columns|
103
+ @options[:width] = columns.to_i
104
+ end
226
105
  end
227
106
 
228
107
  optparse.parse!
229
108
 
109
+ @theme = load_theme(@options[:theme])
230
110
  @cols = @options[:width]
231
111
  @output = ''
232
112
  @headers = []
@@ -678,11 +558,11 @@ module CLIMarkdown
678
558
  input = new_content.join("\n")
679
559
  end
680
560
 
681
- h_adjust = highest_header(input) - 1
682
- input.gsub!(/^(#+)/) do |m|
683
- match = Regexp.last_match
684
- "#" * (match[1].length - h_adjust)
685
- end
561
+ # h_adjust = highest_header(input) - 1
562
+ # input.gsub!(/^(#+)/) do |m|
563
+ # match = Regexp.last_match
564
+ # "#" * (match[1].length - h_adjust)
565
+ # end
686
566
 
687
567
  # code block parsing
688
568
  input.gsub!(/(?i-m)(^[ \t]*[`~]{3,})([\s\S]*?)\n([\s\S]*?)\1/m) do
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
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.2
4
+ version: 1.0.3
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-09-13 00:00:00.000000000 Z
11
+ date: 2019-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake