mdless 1.0.3 → 1.0.5

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: 47c92338d7793e3f3e394164c31eaae071933aaca4b468f09e507835ceb41512
4
- data.tar.gz: fb290c4a11f812e06bfb48699b903c91565c8c57e437a6689430ed98dd7bf6ad
3
+ metadata.gz: ba3a539eeaf6b41eecbea5e64740e1be0300e20ab0d3045bfb214a3888b830e3
4
+ data.tar.gz: 64b656423e3be62f758f41d275efb8ee14a4592460e24888987ee19912f106b2
5
5
  SHA512:
6
- metadata.gz: 8d9a492f4f485aa43e19315f5526d3dba15b30b2e81420ff24f8e2dbd3bdb1a8335370c02e6c7d535d0a2b6c0f3904c21ad85fa4f81ca0aab8dc0713ac201863
7
- data.tar.gz: 34c641d25c5b277e1cb9c0109df760cb1f9c179982447feeaafcaac1ada440b4e2cfc742f203176b20c09a1700c4a4c2d351f66b670f48748ae22b2de98d280a
6
+ metadata.gz: 5990467acef82ddd12dce2106f4b7c6eda57fe1f88fe27d3b2a1d59c3ed80ac33a82a0df14b7a51d36dd6736abae598debc1b755dcac836b43ef7fe0c108aa0a
7
+ data.tar.gz: 6d9984c780ec1a38254006aaf3695492932fa2e9d87dbb793f6e67d1dfbaeb6889b453d6d0098acfa42971e04bf5ba753e6fc8c00177a4d57ea45253f19dc8a2
data/README.md CHANGED
@@ -43,23 +43,23 @@ The pager used is determined by system configuration in this order of preference
43
43
 
44
44
  ### Options
45
45
 
46
- -s, --section=NUMBER Output only a headline-based section of
47
- the input (numeric based on --list output)
48
- -w, --width=COLUMNS Column width to format for (default terminal width)
49
- -p, --[no-]pager Formatted output to pager (default on)
50
- -P Disable pager (same as --no-pager)
51
46
  -c, --[no-]color Colorize output (default on)
52
- -l, --list List headers in document and exit
53
- -i, --images=TYPE Include [local|remote (both)] images in
54
- output (requires imgcat and iTerm2,
55
- default NONE)
56
- -I, --all-images Include local and remote images in output
47
+ -d, --debug LEVEL Level of debug messages to output
57
48
  -h, --help Display this screen
49
+ -i, --images=TYPE Include [local|remote (both)] images in output (requires imgcat and iTerm2, default NONE)
50
+ -I, --all-images Include local and remote images in output (requires imgcat and iTerm2)
51
+ --links=FORMAT Link style ([inline, reference], default inline) [NOT CURRENTLY IMPLEMENTED]
52
+ -l, --list List headers in document and exit
53
+ -p, --[no-]pager Formatted output to pager (default on)
54
+ -P Disable pager (same as --no-pager)
55
+ -s, --section=NUMBER Output only a headline-based section of the input (numeric from --list)
56
+ -t, --theme=THEME_NAME Specify an alternate color theme to load
58
57
  -v, --version Display version number
58
+ -w, --width=COLUMNS Column width to format for (default terminal width)
59
59
 
60
60
  ## Customization
61
61
 
62
- On first run a default theme file will be placed in `~/.config/mdless/mdless.theme`. You can edit this file to modify the colors mdless uses when highlighting your files.
62
+ On first run a default theme file will be placed in `~/.config/mdless/mdless.theme`. You can edit this file to modify the colors mdless uses when highlighting your files. You can copy this file and create multiple theme options which can be specified with the `-t NAME` option. For example, create `~/.config/mdless/brett.theme` and then call `mdless -t brett filename.md`.
63
63
 
64
64
  Colors are limited to basic ANSI codes, with support for bold, underline, italics (if available for the terminal/font), dark and bright, and foreground and background colors.
65
65
 
@@ -0,0 +1,8 @@
1
+ module CLIMarkdown
2
+ class ::Hash
3
+ def deep_merge(second)
4
+ 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 }
5
+ self.merge(second.to_h, &merger)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,138 @@
1
+ module CLIMarkdown
2
+ module Theme
3
+
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 black on_intense_blue'
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
+ },
85
+ 'html' => {
86
+ 'brackets' => 'd yellow on_black',
87
+ 'color' => 'yellow on_black'
88
+ }
89
+ }
90
+
91
+ def load_theme_file(theme_file)
92
+ new_theme = YAML.load(IO.read(theme_file))
93
+ begin
94
+ theme = THEME_DEFAULTS.deep_merge(new_theme)
95
+ # write merged theme back in case there are new keys since
96
+ # last updated
97
+ File.open(theme_file,'w') {|f|
98
+ f.puts theme.to_yaml
99
+ }
100
+ rescue
101
+ @log.warn('Error merging user theme')
102
+ theme = THEME_DEFAULTS
103
+ end
104
+ theme
105
+ end
106
+
107
+ def load_theme(theme)
108
+ config_dir = File.expand_path('~/.config/mdless')
109
+ default_theme_file = File.join(config_dir,'mdless.theme')
110
+ if theme =~ /default/i || !theme
111
+ theme_file = default_theme_file
112
+ else
113
+ theme = theme.strip.sub(/(\.theme)?$/,'.theme')
114
+ theme_file = File.join(config_dir,theme)
115
+ end
116
+
117
+ unless File.directory?(config_dir)
118
+ @log.info("Creating config directory at #{config_dir}")
119
+ FileUtils.mkdir_p(config_dir)
120
+ end
121
+
122
+ unless File.exists?(theme_file)
123
+ unless File.exists?(default_theme_file)
124
+ @log.info("Writing fresh theme file to #{theme_file}")
125
+ File.open(theme_file,'w') {|f|
126
+ f.puts theme.to_yaml
127
+ }
128
+ theme = THEME_DEFAULTS
129
+ else
130
+ @log.info("Specified theme not found, using default")
131
+ theme_file = default_theme_file
132
+ end
133
+ end
134
+
135
+ load_theme_file(theme_file)
136
+ end
137
+ end
138
+ end
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -72,7 +72,9 @@ files:
72
72
  - lib/mdless.rb
73
73
  - lib/mdless/colors.rb
74
74
  - lib/mdless/converter.rb
75
+ - lib/mdless/hash.rb
75
76
  - lib/mdless/tables.rb
77
+ - lib/mdless/theme.rb
76
78
  - lib/mdless/version.rb
77
79
  homepage: http://brettterpstra.com/project/mdless/
78
80
  licenses: