mdless 2.1.3 → 2.1.6
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/CHANGELOG.md +15 -0
- data/README.md +16 -1
- data/lib/mdless/colors.rb +31 -19
- data/lib/mdless/console.rb +16 -6
- 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: b310c064653d3fce972b3c3e91a134b9549d7595787ed9bd57efb8486780cbc5
|
4
|
+
data.tar.gz: 5379beea590a35d1a9fa8b034d008d3552d07b6fc1e3f56592ee9e38ae5a1b8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42cbc5c4366b3a7914f07409fcaf322741d3def2f23c578b956d1cad4683b905e9b02af7523bfd68988627feaaa314c6c772ada0f56b2b99b493838ec319a547
|
7
|
+
data.tar.gz: 15615f5222dae1e812a9cf252b7ba730a11ad06e19aac9397236768a4d396cd57ea307da0a0678ab5f2e3f5ceeea2b6f02a8de628b2cf168099165b8af787c72
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
2.1.6
|
2
|
+
: In addition to color names, you can now use 3 or 6-digit hex codes, prefix with "bg" or "on_" to affect background color
|
3
|
+
: Better highlighting of h1/h2 when header contains a link
|
4
|
+
: List items with multiple paragraphs incorrectly highlighted
|
5
|
+
|
6
|
+
2.1.5
|
7
|
+
: In addition to color names, you can now use 3 or 6-digit hex codes, prefix with "bg" or "on_" to affect background color
|
8
|
+
: Better highlighting of h1/h2 when header contains a link
|
9
|
+
: List items with multiple paragraphs incorrectly highlighted
|
10
|
+
|
11
|
+
2.1.4
|
12
|
+
: In addition to color names, you can now use 3 or 6-digit hex codes, prefix with "bg" or "on_" to affect background color
|
13
|
+
: Better highlighting of h1/h2 when header contains a link
|
14
|
+
: List items with multiple paragraphs incorrectly highlighted
|
15
|
+
|
1
16
|
2.1.3
|
2
17
|
: Respect :width setting in config
|
3
18
|
|
data/README.md
CHANGED
@@ -17,18 +17,29 @@ I often use iTerm2 in visor mode, so `qlmanage -p` is annoying. I still wanted a
|
|
17
17
|
- Normalize spacing and link formatting
|
18
18
|
- Display footnotes after each paragraph
|
19
19
|
- Inline image display (local, optionally remote) (with compatible tools like imgcat or chafa)
|
20
|
-
- Syntax highlighting when [Pygments](http://pygments.org/) is installed
|
20
|
+
- Syntax highlighting of code blocks when [Pygments](http://pygments.org/) is installed
|
21
21
|
- List headlines in document
|
22
22
|
- Display single section of the document based on headlines
|
23
|
+
- Configurable Markdown options
|
23
24
|
- Customizable colors
|
24
25
|
- Add iTerm marks for h1-3 navigation when pager is disabled
|
26
|
+
- TaskPaper syntax detection and highlighting
|
25
27
|
|
26
28
|
## Installation
|
27
29
|
|
30
|
+
### Gem install
|
31
|
+
|
28
32
|
gem install mdless
|
29
33
|
|
30
34
|
If you run into errors, try `gem install --user-install mdless`, or `sudo gem install mdless` (in that order).
|
31
35
|
|
36
|
+
### Homebrew
|
37
|
+
|
38
|
+
mdless is also available via Homebrew (directly).
|
39
|
+
|
40
|
+
brew install mdless
|
41
|
+
|
42
|
+
|
32
43
|
### Dependencies
|
33
44
|
|
34
45
|
To render images, you need `imgcat` or `chafa` installed (`brew install chafa`).
|
@@ -132,6 +143,8 @@ h1:
|
|
132
143
|
|
133
144
|
Font and color settings are set using a string of color names and modifiers. A typical string looks like `b red on_white`, which would give you a bold red font on a white background. In the YAML settings file there's no need for quotes, just put the string following the colon for the setting.
|
134
145
|
|
146
|
+
You can also use 3 or 6-digit hex codes in place of color names. These can be prefixed with `bg` or `on_` to affect background colors, e.g. `bgFF0ACC`. The codes are case-insensitive and can be combined with emphasis modifiers like `b` or `u`.
|
147
|
+
|
135
148
|
Some extra (non-color) settings are available for certain keys, e.g. `pad_char` to define the right padding character used on level 1 and 2 headlines. Note that you can change the [Pygments](http://pygments.org/) theme used for syntax highlighting with the code_block.pygments_theme setting. For a list of available styles (assuming you have Pygments installed), use `pygmentize -L styles`.
|
136
149
|
|
137
150
|
The display of characters around emphasis and code spans can be configured. By default, the surrounding character for bold is `**`, italic is `_`, and code span is \`. You can leave these keys empty to not display characters at all. For triple-emphasized text, the text will be surrounded by italic and bold characters, in that order.
|
@@ -199,6 +212,8 @@ mdless --taskpaper=auto -@ "${FILE_PATH}" && exit 5
|
|
199
212
|
;;
|
200
213
|
```
|
201
214
|
|
215
|
+
Thanks to Ralf Hülsmann for contributing!
|
216
|
+
|
202
217
|
### Gather
|
203
218
|
|
204
219
|
[Gather](https://brettterpstra.com/projects/gather-cli/) is a tool for converting web pages to Markdown. You can use it with mdless to create a Lynx-style web browser:
|
data/lib/mdless/colors.rb
CHANGED
@@ -70,7 +70,7 @@ module CLIMarkdown
|
|
70
70
|
def last_color_code
|
71
71
|
m = scan(ESCAPE_REGEX)
|
72
72
|
|
73
|
-
em = [
|
73
|
+
em = []
|
74
74
|
fg = nil
|
75
75
|
bg = nil
|
76
76
|
rgbf = nil
|
@@ -81,15 +81,12 @@ module CLIMarkdown
|
|
81
81
|
when '0'
|
82
82
|
em = ['0']
|
83
83
|
fg, bg, rgbf, rgbb = nil
|
84
|
-
when
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
bg = nil
|
91
|
-
rgbb = c
|
92
|
-
end
|
84
|
+
when /;38;/
|
85
|
+
fg = nil
|
86
|
+
rgbf = c
|
87
|
+
when /;48;/
|
88
|
+
bg = nil
|
89
|
+
rgbb = c
|
93
90
|
else
|
94
91
|
c.split(/;/).each do |i|
|
95
92
|
x = i.to_i
|
@@ -144,9 +141,9 @@ module CLIMarkdown
|
|
144
141
|
|
145
142
|
line += self.match(/^\s*/)[0].gsub(/\t/,' ')
|
146
143
|
input = self.dup # .gsub(/(\w-)(\w)/,'\1 \2')
|
147
|
-
input.gsub!(/\[.*?\]\(.*?\)/) do |link|
|
148
|
-
|
149
|
-
end
|
144
|
+
# input.gsub!(/\[.*?\]\(.*?\)/) do |link|
|
145
|
+
# link.gsub(/ /, "\u00A0")
|
146
|
+
# end
|
150
147
|
input.split(/\s+/).each do |word|
|
151
148
|
last_ansi = line.scan(/\e\[[\d;]+m/)[-1] || ''
|
152
149
|
if visible_width + word.size_clean >= width
|
@@ -170,14 +167,15 @@ module CLIMarkdown
|
|
170
167
|
def c(args)
|
171
168
|
out = []
|
172
169
|
|
173
|
-
args.each
|
174
|
-
if
|
170
|
+
args.each do |arg|
|
171
|
+
if arg.to_s =~ /^([bf]g|on_)?([a-f0-9]{3}|[a-f0-9]{6})$/i
|
172
|
+
out.concat(rgb(arg.to_s))
|
173
|
+
elsif COLORS.key? arg
|
175
174
|
out << COLORS[arg]
|
176
175
|
end
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
"\e[#{out.sort.join(';')}m"
|
176
|
+
end
|
177
|
+
if !out.empty?
|
178
|
+
"\e[#{out.join(';')}m"
|
181
179
|
else
|
182
180
|
''
|
183
181
|
end
|
@@ -185,6 +183,20 @@ module CLIMarkdown
|
|
185
183
|
|
186
184
|
private
|
187
185
|
|
186
|
+
def rgb(hex)
|
187
|
+
is_bg = hex.match(/^(bg|on_)/) ? true : false
|
188
|
+
hex_string = hex.sub(/^(bg|on_)?(.{3}|.{6})/, '\2')
|
189
|
+
hex_string.gsub!(/(.)/, '\1\1') if hex_string.length == 3
|
190
|
+
|
191
|
+
parts = hex_string.match(/(?<r>..)(?<g>..)(?<b>..)/)
|
192
|
+
t = []
|
193
|
+
%w[r g b].each do |e|
|
194
|
+
t << parts[e].hex
|
195
|
+
end
|
196
|
+
|
197
|
+
[is_bg ? 48 : 38, 2].concat(t)
|
198
|
+
end
|
199
|
+
|
188
200
|
def xc(foreground=:x)
|
189
201
|
c([foreground])
|
190
202
|
end
|
data/lib/mdless/console.rb
CHANGED
@@ -142,6 +142,7 @@ module Redcarpet
|
|
142
142
|
def color(key)
|
143
143
|
val = nil
|
144
144
|
keys = key.split(/[ ,>]/)
|
145
|
+
|
145
146
|
if MDLess.theme.key?(keys[0])
|
146
147
|
val = MDLess.theme[keys.shift]
|
147
148
|
else
|
@@ -192,17 +193,21 @@ module Redcarpet
|
|
192
193
|
pad = ''
|
193
194
|
ansi = ''
|
194
195
|
text.clean_header_ids!
|
196
|
+
uncolored = text.uncolor.gsub(/<<(pre|post)\d+>>/, '')
|
197
|
+
uncolored.sub!(/\[(.*?)\]\(.*?\)/, '[\1][xxx]') if MDLess.options[:links] != :inline
|
198
|
+
|
199
|
+
text_length = uncolored.length
|
195
200
|
case header_level
|
196
201
|
when 1
|
197
202
|
ansi = color('h1 color')
|
198
203
|
pad = color('h1 pad')
|
199
204
|
char = MDLess.theme['h1']['pad_char'] || '='
|
200
|
-
pad +=
|
205
|
+
pad += text_length + 2 > MDLess.cols ? char * text_length : char * (MDLess.cols - (text_length + 1))
|
201
206
|
when 2
|
202
207
|
ansi = color('h2 color')
|
203
208
|
pad = color('h2 pad')
|
204
209
|
char = MDLess.theme['h2']['pad_char'] || '-'
|
205
|
-
pad +=
|
210
|
+
pad += text_length + 2 > MDLess.cols ? char * text_length : char * (MDLess.cols - (text_length + 1))
|
206
211
|
when 3
|
207
212
|
ansi = color('h3 color')
|
208
213
|
when 4
|
@@ -236,6 +241,10 @@ module Redcarpet
|
|
236
241
|
end
|
237
242
|
end
|
238
243
|
|
244
|
+
def uncolor_grafs(text)
|
245
|
+
text.gsub(/#{Regexp.escape(color('text'))}/, color('list color'))
|
246
|
+
end
|
247
|
+
|
239
248
|
@table_cols = nil
|
240
249
|
|
241
250
|
def table_header_row
|
@@ -294,7 +303,7 @@ module Redcarpet
|
|
294
303
|
end
|
295
304
|
|
296
305
|
def codespan(code)
|
297
|
-
[
|
306
|
+
out = [
|
298
307
|
pre_element,
|
299
308
|
color('code_span marker'),
|
300
309
|
MDLess.theme['code_span']['character'],
|
@@ -304,7 +313,7 @@ module Redcarpet
|
|
304
313
|
MDLess.theme['code_span']['character'],
|
305
314
|
xc,
|
306
315
|
post_element
|
307
|
-
].join
|
316
|
+
].join
|
308
317
|
end
|
309
318
|
|
310
319
|
def double_emphasis(text)
|
@@ -617,7 +626,7 @@ module Redcarpet
|
|
617
626
|
end
|
618
627
|
|
619
628
|
content = m['content'] =~/<<listitem/ ? fix_items(m['content'], indent, levels) : m['content']
|
620
|
-
color_list_item(' ' * indent, content, m['type'].to_sym, levels[indent])
|
629
|
+
color_list_item(' ' * indent, uncolor_grafs(content), m['type'].to_sym, levels[indent])
|
621
630
|
end
|
622
631
|
end
|
623
632
|
|
@@ -822,8 +831,9 @@ module Redcarpet
|
|
822
831
|
def fix_colors(input)
|
823
832
|
input.gsub(/<<pre(?<id>\d+)>>(?<content>.*?)<<post\k<id>>>/m) do
|
824
833
|
m = Regexp.last_match
|
825
|
-
pre = m.pre_match
|
834
|
+
pre = m.pre_match.gsub(/<<pre(?<id>\d+)>>.*?<<post\k<id>>>/m, '')
|
826
835
|
last_color = pre.last_color_code
|
836
|
+
|
827
837
|
"#{fix_colors(m['content'])}#{last_color}"
|
828
838
|
end.gsub(/<<(pre|post)\d+>>/, '')
|
829
839
|
end
|
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: 2.1.
|
4
|
+
version: 2.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|