mdless 2.0.14 → 2.0.16
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/lib/mdless/console.rb +149 -50
- data/lib/mdless/converter.rb +28 -2
- data/lib/mdless/string.rb +49 -0
- data/lib/mdless/taskpaper.rb +6 -4
- 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: 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)
|
@@ -601,8 +676,27 @@ module Redcarpet
|
|
601
676
|
def preprocess(input)
|
602
677
|
in_yaml = false
|
603
678
|
|
679
|
+
if @options[:taskpaper] == :auto
|
680
|
+
@options[:taskpaper] = if @file =~ /\.taskpaper/
|
681
|
+
@log.info('TaskPaper extension detected')
|
682
|
+
true
|
683
|
+
elsif CLIMarkdown::TaskPaper.is_taskpaper?(input)
|
684
|
+
@log.info('TaskPaper document detected')
|
685
|
+
true
|
686
|
+
else
|
687
|
+
false
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
604
691
|
input = color_meta(input)
|
605
692
|
|
693
|
+
if @options[:taskpaper]
|
694
|
+
input = CLIMarkdown::TaskPaper.highlight(input, @theme)
|
695
|
+
input = highlight_tags(input)
|
696
|
+
return input
|
697
|
+
end
|
698
|
+
|
699
|
+
|
606
700
|
## Replace setex headers with ATX
|
607
701
|
input.gsub!(/^([^\n]+)\n={2,}\s*$/m, "# \\1\n")
|
608
702
|
input.gsub!(/^([^\n]+?)\n-{2,}\s*$/m, "## \\1\n")
|
@@ -647,20 +741,6 @@ module Redcarpet
|
|
647
741
|
"#{color('dd term')}#{m['term']}#{xc}#{color('dd color')}#{color_dd_def(m['def'])}"
|
648
742
|
end
|
649
743
|
|
650
|
-
if @options[:taskpaper] == :auto
|
651
|
-
@options[:taskpaper] = if @file =~ /\.taskpaper/
|
652
|
-
@log.info('TaskPaper extension detected')
|
653
|
-
true
|
654
|
-
elsif CLIMarkdown::TaskPaper.is_taskpaper?(input)
|
655
|
-
@log.info('TaskPaper document detected')
|
656
|
-
true
|
657
|
-
else
|
658
|
-
false
|
659
|
-
end
|
660
|
-
end
|
661
|
-
|
662
|
-
input = CLIMarkdown::TaskPaper.highlight(input, @theme) if @options[:taskpaper]
|
663
|
-
|
664
744
|
input
|
665
745
|
end
|
666
746
|
|
@@ -833,7 +913,7 @@ module Redcarpet
|
|
833
913
|
def highlight_tags(input)
|
834
914
|
tag_color = color('at_tags tag')
|
835
915
|
value_color = color('at_tags value')
|
836
|
-
input.gsub(/(?<pre>\s|m)(?<tag>@[^ ("']+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
|
916
|
+
input.gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("']+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
|
837
917
|
m = Regexp.last_match
|
838
918
|
last_color = m.pre_match.last_color_code
|
839
919
|
[
|
@@ -851,9 +931,28 @@ module Redcarpet
|
|
851
931
|
end
|
852
932
|
end
|
853
933
|
|
934
|
+
def highlight_wiki_links(input)
|
935
|
+
input.gsub(/\[\[(.*?)\]\]/) do
|
936
|
+
content = Regexp.last_match(1)
|
937
|
+
[
|
938
|
+
pre_element,
|
939
|
+
color('link brackets'),
|
940
|
+
'[[',
|
941
|
+
color('link text'),
|
942
|
+
content,
|
943
|
+
color('link brackets'),
|
944
|
+
']]',
|
945
|
+
xc,
|
946
|
+
post_element
|
947
|
+
].join
|
948
|
+
end
|
949
|
+
end
|
950
|
+
|
854
951
|
def postprocess(input)
|
855
952
|
input.scrub!
|
856
953
|
|
954
|
+
input = highlight_wiki_links(input) if @options[:wiki_links]
|
955
|
+
|
857
956
|
if @options[:inline_footnotes]
|
858
957
|
input = insert_footnotes(input)
|
859
958
|
else
|
@@ -873,7 +972,7 @@ module Redcarpet
|
|
873
972
|
# format links
|
874
973
|
input = reference_links(input) if @options[:links] == :reference || @options[:links] == :paragraph
|
875
974
|
# lists
|
876
|
-
input = fix_lists(input
|
975
|
+
input = fix_lists(input)
|
877
976
|
input = render_images(input) if @options[:local_images]
|
878
977
|
input = highlight_tags(input) if @options[:at_tags] || @options[:taskpaper]
|
879
978
|
fix_colors(input)
|
data/lib/mdless/converter.rb
CHANGED
@@ -146,6 +146,11 @@ module CLIMarkdown
|
|
146
146
|
@options[:at_tags] = true
|
147
147
|
end
|
148
148
|
|
149
|
+
@options[:wiki_links] ||= false
|
150
|
+
opts.on('--[no-]wiki-links', 'Highlight [[wiki links]]') do |opt|
|
151
|
+
@options[:wiki_links] = opt
|
152
|
+
end
|
153
|
+
|
149
154
|
opts.on('-v', '--version', 'Display version number') do
|
150
155
|
puts version
|
151
156
|
exit
|
@@ -224,12 +229,33 @@ module CLIMarkdown
|
|
224
229
|
rescue StandardError
|
225
230
|
input = IO.read(file)
|
226
231
|
end
|
227
|
-
input
|
232
|
+
raise 'Nil input' if input.nil?
|
233
|
+
|
234
|
+
input.scrub!
|
235
|
+
input.gsub!(/\r?\n/, "\n")
|
236
|
+
|
228
237
|
if @options[:list]
|
229
238
|
puts list_headers(input)
|
230
239
|
Process.exit 0
|
231
240
|
else
|
232
|
-
@
|
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
|
233
259
|
end
|
234
260
|
end
|
235
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/taskpaper.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module CLIMarkdown
|
4
4
|
module TaskPaper
|
5
|
-
TASK_RX = /^(?<indent>(?: |\t)
|
6
|
-
PROJECT_RX = /^(?<indent>(?: |\t)
|
5
|
+
TASK_RX = /^(?<indent>(?: |\t)*?)(?<marker>-)(?<task>\s+\S.*?)$/
|
6
|
+
PROJECT_RX = /^(?<indent>(?: |\t)*?)(?<project>[^- \t].*?:)(?<tags> @\S+)*$/
|
7
7
|
NOTE_RX = /^(?<indent>(?: |\t)+)(?<note>(?<!- ).*?(?!:))$/
|
8
8
|
|
9
9
|
class << self
|
@@ -39,8 +39,10 @@ module CLIMarkdown
|
|
39
39
|
def is_taskpaper?(input)
|
40
40
|
projects = input.split(PROJECT_RX)
|
41
41
|
tasks = 0
|
42
|
-
projects.
|
43
|
-
|
42
|
+
if projects.count > 1
|
43
|
+
projects.each do |proj|
|
44
|
+
tasks += proj.scan(TASK_RX).count
|
45
|
+
end
|
44
46
|
end
|
45
47
|
|
46
48
|
tasks >= 6
|
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
|