mdless 2.0.15 → 2.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mdless/console.rb +110 -35
- data/lib/mdless/converter.rb +19 -1
- data/lib/mdless/string.rb +49 -0
- data/lib/mdless/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c2164454fac4fd82af1ef1594166585de749e87cca73c7c83c25c38c3288dd9
|
4
|
+
data.tar.gz: 7b2008f35bd4ddc66fac4438fda186964a538ef0715739410b0b4c429323d96b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e119669e34faaa577b8956eb5817f3b391887108e425b0cb5fcb630f14ea5aa6ffa3282c531c7602fc07912c7a75299bd10169d9ba95375485c664226f30a930
|
7
|
+
data.tar.gz: caae8bb09f9c48e25ad144b401ff74a58a379bb5b10b63ffa66c3afef707ccd39af6699a7301c3467ba180395d8e4ab025cd9a10900d44ae7dfafadde2954fa3
|
data/lib/mdless/console.rb
CHANGED
@@ -105,14 +105,14 @@ module Redcarpet
|
|
105
105
|
[
|
106
106
|
xc,
|
107
107
|
color('code_block border'),
|
108
|
-
'-' *
|
108
|
+
'-' * 20,
|
109
109
|
xc,
|
110
110
|
"\n",
|
111
111
|
color('code_block color'),
|
112
112
|
hilite.chomp,
|
113
113
|
"\n",
|
114
114
|
color('code_block border'),
|
115
|
-
'-' *
|
115
|
+
'-' * 20,
|
116
116
|
xc
|
117
117
|
].join
|
118
118
|
end
|
@@ -204,33 +204,6 @@ module Redcarpet
|
|
204
204
|
"\n\n#{color('hr color')}#{'_' * @cols}#{xc}\n\n"
|
205
205
|
end
|
206
206
|
|
207
|
-
def list(contents, list_type)
|
208
|
-
@@listitemid = 0
|
209
|
-
@@listid += 1
|
210
|
-
"<<list#{@@listid}>>#{contents}<</list#{@@listid}>>"
|
211
|
-
end
|
212
|
-
|
213
|
-
def list_item(text, list_type)
|
214
|
-
case list_type
|
215
|
-
when :unordered
|
216
|
-
[
|
217
|
-
"#{color('list bullet')}• ",
|
218
|
-
color('list color'),
|
219
|
-
text,
|
220
|
-
xc
|
221
|
-
].join('')
|
222
|
-
when :ordered
|
223
|
-
@@listitemid += 1
|
224
|
-
[
|
225
|
-
color('list number'),
|
226
|
-
"#{@@listitemid}. ",
|
227
|
-
color('list color'),
|
228
|
-
text,
|
229
|
-
xc
|
230
|
-
].join('')
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
207
|
def paragraph(text)
|
235
208
|
"#{xc}#{text}#{xc}#{x}\n\n"
|
236
209
|
end
|
@@ -510,16 +483,118 @@ module Redcarpet
|
|
510
483
|
end.join("\n")
|
511
484
|
end
|
512
485
|
|
513
|
-
def
|
514
|
-
|
486
|
+
def list(contents, list_type)
|
487
|
+
@@listid += 1
|
488
|
+
"<<list#{@@listid}-#{list_type}>>#{contents}<</list#{@@listid}>>"
|
489
|
+
end
|
490
|
+
|
491
|
+
def list_item(text, list_type)
|
492
|
+
@@listitemid += 1
|
493
|
+
case list_type
|
494
|
+
when :unordered
|
495
|
+
"<<listitem#{@@listitemid}-#{list_type}>>#{text.strip}<</listitem#{@@listitemid}>>\n"
|
496
|
+
when :ordered
|
497
|
+
"<<listitem#{@@listitemid}-#{list_type}>>#{text.strip}<</listitem#{@@listitemid}>>\n"
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
def indent_lines(input, spaces)
|
502
|
+
return nil if input.nil?
|
503
|
+
|
504
|
+
indent = spaces.scan(/ /).count
|
505
|
+
|
506
|
+
lines = input.split(/\n/)
|
507
|
+
line1 = lines.shift
|
508
|
+
body = lines.map { |l| "#{' ' * (indent + 1)}#{l}" }.join("\n")
|
509
|
+
"#{line1}\n#{body}"
|
510
|
+
end
|
511
|
+
|
512
|
+
def color_list_item(indent, content, type, counter)
|
513
|
+
case type
|
514
|
+
when :unordered
|
515
|
+
[
|
516
|
+
indent,
|
517
|
+
color('list bullet'),
|
518
|
+
"* ",
|
519
|
+
color('list color'),
|
520
|
+
indent_lines(content, indent).strip,
|
521
|
+
xc
|
522
|
+
].join
|
523
|
+
when :ordered
|
524
|
+
[
|
525
|
+
indent,
|
526
|
+
color('list number'),
|
527
|
+
"#{counter}. ",
|
528
|
+
color('list color'),
|
529
|
+
indent_lines(content, indent).strip,
|
530
|
+
xc
|
531
|
+
].join
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
def fix_lists(input)
|
536
|
+
input = nest_lists(input)
|
537
|
+
input = fix_list_spacing(input)
|
538
|
+
fix_list_items(input)
|
539
|
+
end
|
540
|
+
|
541
|
+
def fix_list_spacing(input)
|
542
|
+
input.gsub(/( *\n)+( *)<<listitem/, "\n\\2<<listitem").gsub(/\n{2,}/, "\n\n")
|
543
|
+
end
|
544
|
+
|
545
|
+
def nest_lists(input, indent = 0)
|
546
|
+
input.gsub!(%r{<<list(?<id>\d+)-(?<type>.*?)>>(?<content>.*?)<</list\k<id>>>}m) do
|
515
547
|
m = Regexp.last_match
|
516
|
-
|
548
|
+
lines = m['content'].split(/\n/)
|
549
|
+
list = nest_lists(lines.map do |l|
|
517
550
|
outdent = l.scan(%r{<</list\d+>>}).count
|
518
|
-
indent += l.scan(/<<list\d
|
551
|
+
indent += l.scan(/<<list\d+-.*?>>/).count
|
519
552
|
indent -= outdent
|
520
553
|
"#{' ' * indent}#{l}"
|
521
554
|
end.join("\n"), indent)
|
522
|
-
|
555
|
+
next if list.nil?
|
556
|
+
|
557
|
+
"<<main#{m['id']}>>#{list}<</main#{m['id']}>>"
|
558
|
+
end
|
559
|
+
|
560
|
+
input.gsub(/^(?<indent> +)<<main(?<id>\d+)>>(?<content>.*?)<<\/main\k<id>>>/m) do
|
561
|
+
m = Regexp.last_match
|
562
|
+
"#{m['indent']}#{m['content']}"
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
def normalize_indentation(line)
|
567
|
+
line.gsub(/^([ \t]+)/) do |pre|
|
568
|
+
pre.gsub(/\t/, ' ')
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
def fix_items(content, last_indent = 0, levels = [0])
|
573
|
+
content.gsub(%r{^(?<indent> *)<<listitem(?<id>\d+)-(?<type>(?:un)?ordered)>>(?<content>.*?)<</listitem\k<id>>>}m) do
|
574
|
+
m = Regexp.last_match
|
575
|
+
indent = m['indent'].length
|
576
|
+
if indent == last_indent
|
577
|
+
levels[indent] ||= 0
|
578
|
+
levels[indent] += 1
|
579
|
+
elsif indent < last_indent
|
580
|
+
levels[last_indent] = 0
|
581
|
+
levels[indent] += 1
|
582
|
+
last_indent = indent
|
583
|
+
else
|
584
|
+
levels[indent] = 1
|
585
|
+
last_indent = indent
|
586
|
+
end
|
587
|
+
|
588
|
+
content = m['content'] =~/<<listitem/ ? fix_items(m['content'], indent, levels) : m['content']
|
589
|
+
color_list_item(' ' * indent, content, m['type'].to_sym, levels[indent])
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
def fix_list_items(input)
|
594
|
+
input.gsub(%r{<<main(?<id>\d+)>>(?<content>.*?)<</main\k<id>>>}m) do
|
595
|
+
m = Regexp.last_match
|
596
|
+
fix_items(m['content'])
|
597
|
+
end
|
523
598
|
end
|
524
599
|
|
525
600
|
def get_headers(input)
|
@@ -897,7 +972,7 @@ module Redcarpet
|
|
897
972
|
# format links
|
898
973
|
input = reference_links(input) if @options[:links] == :reference || @options[:links] == :paragraph
|
899
974
|
# lists
|
900
|
-
input = fix_lists(input
|
975
|
+
input = fix_lists(input)
|
901
976
|
input = render_images(input) if @options[:local_images]
|
902
977
|
input = highlight_tags(input) if @options[:at_tags] || @options[:taskpaper]
|
903
978
|
fix_colors(input)
|
data/lib/mdless/converter.rb
CHANGED
@@ -233,11 +233,29 @@ module CLIMarkdown
|
|
233
233
|
|
234
234
|
input.scrub!
|
235
235
|
input.gsub!(/\r?\n/, "\n")
|
236
|
+
|
236
237
|
if @options[:list]
|
237
238
|
puts list_headers(input)
|
238
239
|
Process.exit 0
|
239
240
|
else
|
240
|
-
@
|
241
|
+
if @options[:taskpaper] == :auto
|
242
|
+
@options[:taskpaper] = if file =~ /\.taskpaper/
|
243
|
+
@log.info('TaskPaper extension detected')
|
244
|
+
true
|
245
|
+
elsif CLIMarkdown::TaskPaper.is_taskpaper?(input)
|
246
|
+
@log.info('TaskPaper document detected')
|
247
|
+
true
|
248
|
+
else
|
249
|
+
false
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
if @options[:taskpaper]
|
254
|
+
input = CLIMarkdown::TaskPaper.highlight(input, @theme)
|
255
|
+
@output = input.highlight_tags(@theme, @log)
|
256
|
+
else
|
257
|
+
@output = markdown.render(input)
|
258
|
+
end
|
241
259
|
end
|
242
260
|
end
|
243
261
|
printout
|
data/lib/mdless/string.rb
CHANGED
@@ -2,6 +2,55 @@
|
|
2
2
|
|
3
3
|
# String helpers
|
4
4
|
class ::String
|
5
|
+
include CLIMarkdown::Colors
|
6
|
+
|
7
|
+
def color(key, theme, log)
|
8
|
+
val = nil
|
9
|
+
keys = key.split(/[ ,>]/)
|
10
|
+
if theme.key?(keys[0])
|
11
|
+
val = theme[keys.shift]
|
12
|
+
else
|
13
|
+
log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
|
14
|
+
return c([:reset])
|
15
|
+
end
|
16
|
+
keys.each do |k|
|
17
|
+
if val.key?(k)
|
18
|
+
val = val[k]
|
19
|
+
else
|
20
|
+
log.error("Invalid theme key: #{k}")
|
21
|
+
return c([:reset])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
if val.is_a? String
|
25
|
+
val = "x #{val}"
|
26
|
+
res = val.split(/ /).map(&:to_sym)
|
27
|
+
c(res)
|
28
|
+
else
|
29
|
+
c([:reset])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def highlight_tags(theme, log)
|
34
|
+
tag_color = color('at_tags tag', theme, log)
|
35
|
+
value_color = color('at_tags value', theme, log)
|
36
|
+
gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("']+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
|
37
|
+
m = Regexp.last_match
|
38
|
+
last_color = m.pre_match.last_color_code
|
39
|
+
[
|
40
|
+
m['pre'],
|
41
|
+
tag_color,
|
42
|
+
m['tag'],
|
43
|
+
m['lparen'],
|
44
|
+
value_color,
|
45
|
+
m['value'],
|
46
|
+
tag_color,
|
47
|
+
m['rparen'],
|
48
|
+
xc,
|
49
|
+
last_color
|
50
|
+
].join
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
5
54
|
def scrub
|
6
55
|
encode('utf-16', invalid: :replace).encode('utf-8')
|
7
56
|
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.0.
|
4
|
+
version: 2.0.16
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.2.
|
117
|
+
rubygems_version: 3.2.15
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: A pager like less, but for Markdown files
|