mdless 1.0.32 → 1.0.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mdless/converter.rb +43 -40
- 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: 124d704b9e69d3c7afbba30442cc2e3f3b9ebd92edc16b345c3a5489b64a5823
|
4
|
+
data.tar.gz: 0e257d07a7c684441140ad2d526711c41127f97af37ae798311d9f04e5f832fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 621d98dd881546000fdff38ad51e691d1c729fce4a87f96dc19b5041b9fefefd826245ed9b865db272165b591a0d300b6d1c5dca71d2612b611bc9549dce3181
|
7
|
+
data.tar.gz: 33287f2fd78bdc15fd9bc15003a30df2396688475864063e012d96418c8e390a2c2e6c67c746831608a40e4bea0ee594540e209dbcc6806d3e7950c870406785
|
data/lib/mdless/converter.rb
CHANGED
@@ -22,11 +22,11 @@ module CLIMarkdown
|
|
22
22
|
opts.banner = "#{version} by Brett Terpstra\n\n> Usage: #{CLIMarkdown::EXECUTABLE_NAME} [options] [path]\n\n"
|
23
23
|
|
24
24
|
@options[:color] = true
|
25
|
-
opts.on(
|
25
|
+
opts.on('-c', '--[no-]color', 'Colorize output (default on)') do |c|
|
26
26
|
@options[:color] = c
|
27
27
|
end
|
28
28
|
|
29
|
-
opts.on(
|
29
|
+
opts.on('-d', '--debug LEVEL', 'Level of debug messages to output') do |level|
|
30
30
|
if level.to_i > 0 && level.to_i < 5
|
31
31
|
@log.level = 5 - level.to_i
|
32
32
|
else
|
@@ -35,7 +35,7 @@ module CLIMarkdown
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
opts.on(
|
38
|
+
opts.on('-h', '--help', 'Display this screen') do
|
39
39
|
puts opts
|
40
40
|
exit
|
41
41
|
end
|
@@ -54,8 +54,8 @@ module CLIMarkdown
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)'
|
58
|
-
if exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
|
57
|
+
opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)') do
|
58
|
+
if exec_available('imgcat') || exec_available('chafa') # && ENV['TERM_PROGRAM'] == 'iTerm.app'
|
59
59
|
@options[:local_images] = true
|
60
60
|
@options[:remote_images] = true
|
61
61
|
else
|
@@ -64,51 +64,51 @@ module CLIMarkdown
|
|
64
64
|
end
|
65
65
|
|
66
66
|
@options[:links] = :inline
|
67
|
-
opts.on(
|
67
|
+
opts.on('--links=FORMAT', 'Link style ([inline, reference], default inline) [NOT CURRENTLY IMPLEMENTED]') do |format|
|
68
68
|
if format =~ /^r/i
|
69
69
|
@options[:links] = :reference
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
@options[:list] = false
|
74
|
-
opts.on(
|
74
|
+
opts.on('-l', '--list', 'List headers in document and exit' ) do
|
75
75
|
@options[:list] = true
|
76
76
|
end
|
77
77
|
|
78
78
|
@options[:pager] = true
|
79
|
-
opts.on(
|
79
|
+
opts.on('-p', '--[no-]pager', 'Formatted output to pager (default on)') do |p|
|
80
80
|
@options[:pager] = p
|
81
81
|
end
|
82
82
|
|
83
|
-
opts.on(
|
83
|
+
opts.on('-P', 'Disable pager (same as --no-pager)') do
|
84
84
|
@options[:pager] = false
|
85
85
|
end
|
86
86
|
|
87
87
|
@options[:section] = nil
|
88
|
-
opts.on(
|
89
|
-
@options[:section] = section.to_i
|
88
|
+
opts.on('-s', '--section=NUMBER[,NUMBER]', 'Output only a headline-based section of the input (numeric from --list)') do |section|
|
89
|
+
@options[:section] = section.split(/ *, */).map(&:strip).map(&:to_i)
|
90
90
|
end
|
91
91
|
|
92
92
|
@options[:theme] = 'default'
|
93
|
-
opts.on(
|
93
|
+
opts.on('-t', '--theme=THEME_NAME', 'Specify an alternate color theme to load') do |theme|
|
94
94
|
@options[:theme] = theme
|
95
95
|
end
|
96
96
|
|
97
|
-
opts.on(
|
97
|
+
opts.on('-v', '--version', 'Display version number') do
|
98
98
|
puts version
|
99
99
|
exit
|
100
100
|
end
|
101
101
|
|
102
|
-
@options[:width] =
|
103
|
-
opts.on(
|
102
|
+
@options[:width] = `tput cols`.strip.to_i
|
103
|
+
opts.on('-w', '--width=COLUMNS', 'Column width to format for (default: terminal width)') do |columns|
|
104
104
|
@options[:width] = columns.to_i
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
begin
|
109
109
|
optparse.parse!
|
110
|
-
rescue OptionParser::ParseError =>
|
111
|
-
|
110
|
+
rescue OptionParser::ParseError => e
|
111
|
+
warn "error: #{e.message}"
|
112
112
|
exit 1
|
113
113
|
end
|
114
114
|
|
@@ -122,7 +122,7 @@ module CLIMarkdown
|
|
122
122
|
@ref_links = {}
|
123
123
|
@footnotes = {}
|
124
124
|
|
125
|
-
if args.
|
125
|
+
if !args.empty?
|
126
126
|
files = args.delete_if { |f| !File.exist?(f) }
|
127
127
|
files.each do |file|
|
128
128
|
@log.info(%(Processing "#{file}"))
|
@@ -488,6 +488,10 @@ module CLIMarkdown
|
|
488
488
|
end
|
489
489
|
|
490
490
|
def convert_markdown(input)
|
491
|
+
## Replace setex headers with ATX
|
492
|
+
input.gsub!(/^([^\n]+)\n={3,}\s*$/m, "# \\1\n")
|
493
|
+
input.gsub!(/^([^\n]+?)\n-{3,}\s*$/m, "## \\1\n")
|
494
|
+
|
491
495
|
@headers = get_headers(input)
|
492
496
|
input += "\n\n@@@"
|
493
497
|
# yaml/MMD headers
|
@@ -527,7 +531,6 @@ module CLIMarkdown
|
|
527
531
|
|
528
532
|
end
|
529
533
|
|
530
|
-
|
531
534
|
# Gather reference links
|
532
535
|
input.gsub!(/^\s{,3}(?<![\e*])\[\b(.+)\b\]: +(.+)/) do |m|
|
533
536
|
match = Regexp.last_match
|
@@ -544,34 +547,34 @@ module CLIMarkdown
|
|
544
547
|
end
|
545
548
|
|
546
549
|
if @options[:section]
|
547
|
-
in_section = false
|
548
|
-
top_level = 1
|
549
550
|
new_content = []
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
551
|
+
@options[:section].each do |sect|
|
552
|
+
in_section = false
|
553
|
+
top_level = 1
|
554
|
+
input.split(/\n/).each do |graf|
|
555
|
+
if graf =~ /^(#+) *(.*?)( *#+)?$/
|
556
|
+
m = Regexp.last_match
|
557
|
+
level = m[1].length
|
558
|
+
title = m[2]
|
559
|
+
if in_section
|
560
|
+
if level >= top_level
|
561
|
+
new_content.push(graf)
|
562
|
+
else
|
563
|
+
in_section = false
|
564
|
+
break
|
565
|
+
end
|
566
|
+
elsif title.downcase == @headers[sect - 1][1].downcase
|
567
|
+
in_section = true
|
568
|
+
top_level = level + 1
|
558
569
|
new_content.push(graf)
|
559
570
|
else
|
560
|
-
|
561
|
-
break
|
571
|
+
next
|
562
572
|
end
|
563
|
-
elsif
|
564
|
-
in_section = true
|
565
|
-
top_level = level + 1
|
573
|
+
elsif in_section
|
566
574
|
new_content.push(graf)
|
567
|
-
else
|
568
|
-
next
|
569
575
|
end
|
570
|
-
elsif in_section
|
571
|
-
new_content.push(graf)
|
572
576
|
end
|
573
|
-
|
574
|
-
|
577
|
+
end
|
575
578
|
input = new_content.join("\n")
|
576
579
|
end
|
577
580
|
|
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: 1.0.
|
4
|
+
version: 1.0.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|