mdless 0.0.12 → 0.0.13
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 +38 -24
- 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: 571d64e2a21dcfe0c1673a038cbb90977a4ca1aa36992ecef63bc5f7d94ee8bd
|
4
|
+
data.tar.gz: 972c19e2023a96d9c3905bd0ded7984d2a0d36ac15846ddfc1a303acdea4eba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cce597c475876b429a603b5619f837cbb709af2e44e021a5ec63b09b4cfe3ef5a1d69a96980dd37164c5df5ca3eda3722da85ba2daa55362c33c362b88c8f1
|
7
|
+
data.tar.gz: efd3b25c653f16fbdbd2d32fb9e60d998a712caf4cd5cf1b7abba42eef18f42fbcb75ad4089d7e0c259fa412d4988717433c2f96d07276fcd777cb404d39a006
|
data/lib/mdless/converter.rb
CHANGED
@@ -327,7 +327,7 @@ module CLIMarkdown
|
|
327
327
|
new_code_line.gsub!(/ /, "#{c(%i[x white on_black])} ")
|
328
328
|
|
329
329
|
[
|
330
|
-
"#{c(%i[x black])}
|
330
|
+
"#{c(%i[x black])} ~#{c(%i[x white on_black])} ",
|
331
331
|
new_code_line,
|
332
332
|
c(%i[x white on_black]),
|
333
333
|
' ' * [@cols - orig_length, 0].max,
|
@@ -336,7 +336,7 @@ module CLIMarkdown
|
|
336
336
|
end.join("\n")
|
337
337
|
end
|
338
338
|
|
339
|
-
"#{c(%i[x magenta])}#{leader}\n#{hilite}#{xc}"
|
339
|
+
"#{c(%i[x blue]) + '--[ '}#{c(%i[x magenta])}#{leader}#{c(%i[x blue]) + ' ]' + '-'*(@cols-6-leader.size) + xc}\n#{hilite}\n#{c(%i[x blue]) + '--[ '}#{c(%i[x magenta])}END #{leader}#{c(%i[x blue]) + ' ]' + '-'*(@cols-10-leader.size) + xc}"
|
340
340
|
end
|
341
341
|
|
342
342
|
def convert_markdown(input)
|
@@ -434,27 +434,40 @@ module CLIMarkdown
|
|
434
434
|
end
|
435
435
|
|
436
436
|
# code block parsing
|
437
|
-
input.gsub!(/(?i-m)([`~]{3,})([\s\S]*?)\n([\s\S]*?)\1/
|
437
|
+
input.gsub!(/(?i-m)([`~]{3,})([\s\S]*?)\n([\s\S]*?)\1/) do
|
438
438
|
m = Regexp.last_match
|
439
|
-
if m.
|
439
|
+
if m[2].strip !~ /^\s*$/
|
440
|
+
language = m[2].split(/ /)[0].downcase
|
441
|
+
code_block = m[3].to_s.strip
|
442
|
+
leader = language ? language.upcase : 'CODE'
|
443
|
+
else
|
444
|
+
first_line = m[3].to_s.split(/\n/)[0]
|
445
|
+
|
446
|
+
if first_line =~ /^#!/
|
440
447
|
@log.warn('Code block contains Shebang')
|
441
|
-
shebang =
|
448
|
+
shebang = first_line.match(/^(#!.*\/(?:env )?)([^\/]+)$/)
|
442
449
|
language = shebang[2]
|
443
|
-
|
444
|
-
leader = shebang[2] ? shebang[2].upcase
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
450
|
+
code_block = m[3].to_s.strip
|
451
|
+
leader = shebang[2] ? shebang[2].upcase : 'CODE'
|
452
|
+
else
|
453
|
+
code_block = m[3].to_s.split(/\n/).map do |l|
|
454
|
+
new_code_line = l.gsub(/\t/, ' ')
|
455
|
+
orig_length = new_code_line.size + 4
|
456
|
+
new_code_line.gsub!(/ /, "#{c(%i[x white on_black])} ")
|
457
|
+
pad_count = [@cols - orig_length, 0].max
|
458
|
+
[
|
459
|
+
"#{c(%i[x black])}~ #{c(%i[x white on_black])} ",
|
460
|
+
new_code_line,
|
461
|
+
c(%i[x white on_black]),
|
462
|
+
' ' * pad_count,
|
463
|
+
xc
|
464
|
+
].join
|
465
|
+
end.join("\n")
|
466
|
+
leader = language ? language.upcase : 'CODE'
|
467
|
+
end
|
455
468
|
end
|
456
469
|
leader += xc
|
457
|
-
hiliteCode(language,
|
470
|
+
hiliteCode(language, code_block, leader, m[0])
|
458
471
|
end
|
459
472
|
|
460
473
|
# remove empty links
|
@@ -581,15 +594,16 @@ module CLIMarkdown
|
|
581
594
|
end
|
582
595
|
|
583
596
|
# bold, bold/italic
|
584
|
-
line.gsub!(/(
|
597
|
+
line.gsub!(/(?<pre>^|\s)(?<open>[\*_]{2,3})(?<content>[^\*_\s][^\*_]+?[^\*_\s])[\*_]{2,3}/) do |m|
|
585
598
|
match = Regexp.last_match
|
586
599
|
last = find_color(match.pre_match, true)
|
587
600
|
counter = i
|
588
601
|
while last.nil? && counter > 0
|
589
602
|
counter -= 1
|
590
|
-
find_color(lines[counter])
|
603
|
+
last = find_color(lines[counter])
|
591
604
|
end
|
592
|
-
|
605
|
+
emph = match['open'].length == 2 ? c([:b]) : c(%i[b u i])
|
606
|
+
"#{match['pre']}#{emph}#{match['content']}" + (last ? last : xc)
|
593
607
|
end
|
594
608
|
|
595
609
|
# italic
|
@@ -599,9 +613,9 @@ module CLIMarkdown
|
|
599
613
|
counter = i
|
600
614
|
while last.nil? && counter > 0
|
601
615
|
counter -= 1
|
602
|
-
find_color(lines[counter])
|
616
|
+
last = find_color(lines[counter])
|
603
617
|
end
|
604
|
-
"#{match[1]}#{c([
|
618
|
+
"#{match[1]}#{c(%i[u i])}#{match[2]}" + (last ? last : xc)
|
605
619
|
end
|
606
620
|
|
607
621
|
# equations
|
@@ -638,7 +652,7 @@ module CLIMarkdown
|
|
638
652
|
line.gsub!(/(?i-m)((<\/?)(\w+[\s\S]*?)(>))/) do |tag|
|
639
653
|
match = Regexp.last_match
|
640
654
|
last = find_color(match.pre_match)
|
641
|
-
"#{c([:d,:
|
655
|
+
"#{c([:d,:yellow,:on_black])}#{match[2]}#{match[3]}#{match[4]}" + (last ? last : xc)
|
642
656
|
end
|
643
657
|
end
|
644
658
|
|
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: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|