mdless 0.0.12 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfcee3f2aa45bb9582ae159a7eb7633a002ab6ebc4ff26785f7ed6fa04e4d2aa
4
- data.tar.gz: ff9bb80e0c4b3cbfe8951f8bae3f82150b561c77523dda0f93451119a94dd185
3
+ metadata.gz: 571d64e2a21dcfe0c1673a038cbb90977a4ca1aa36992ecef63bc5f7d94ee8bd
4
+ data.tar.gz: 972c19e2023a96d9c3905bd0ded7984d2a0d36ac15846ddfc1a303acdea4eba3
5
5
  SHA512:
6
- metadata.gz: '08248246829c7fd58677f2456a4d4ded712d2905c249f298e3fc2e98ee6eee17f4cd24e46a3376262dab5a1312a7c2d8d6342c7cea412bef63900d51c45a0068'
7
- data.tar.gz: 84f9faa5f08157313d9dc0b8d91a661c401b4bc52c0e2f4db68cd9025b11bf9f7d5be5e84423c7bfe52c30f91388ce54db70a6299715c23c30e02a5f0aecb22a
6
+ metadata.gz: 74cce597c475876b429a603b5619f837cbb709af2e44e021a5ec63b09b4cfe3ef5a1d69a96980dd37164c5df5ca3eda3722da85ba2daa55362c33c362b88c8f1
7
+ data.tar.gz: efd3b25c653f16fbdbd2d32fb9e60d998a712caf4cd5cf1b7abba42eef18f42fbcb75ad4089d7e0c259fa412d4988717433c2f96d07276fcd777cb404d39a006
@@ -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])}~ #{c(%i[x white on_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/ ) do |cb|
437
+ input.gsub!(/(?i-m)([`~]{3,})([\s\S]*?)\n([\s\S]*?)\1/) do
438
438
  m = Regexp.last_match
439
- if m.to_s.include? '#!'
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 = m.to_s.match(/(#!(?:\/)?)([a-z]\w*)/)
448
+ shebang = first_line.match(/^(#!.*\/(?:env )?)([^\/]+)$/)
442
449
  language = shebang[2]
443
- codeBlock = m[3].to_s.gsub(shebang[1]+shebang[2], '').strip
444
- leader = shebang[2] ? shebang[2].upcase + ':' : 'CODE:'
445
- else
446
- # Ignore leading spaces, and use only first word
447
- hilite = m[3].split(/\n/).map{|l|
448
- new_code_line = l.gsub(/\t/,' ')
449
- orig_length = new_code_line.size + 3
450
- new_code_line.gsub!(/ /,"#{c([:x,:white,:on_black])} ")
451
- pad_count = [@cols - orig_length, 0].max
452
- "#{c([:x,:black])}~ #{c([:x,:white,:on_black])} " + new_code_line + c([:x,:white,:on_black]) + " "*pad_count + xc
453
- }.join("\n")
454
- leader = language ? language.upcase + ":" : 'CODE:'
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, codeBlock, leader, m[0])
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!(/(^|\s)[\*_]{2,3}([^\*_\s][^\*_]+?[^\*_\s])[\*_]{2,3}/) do |m|
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
- "#{match[1]}#{c([:b])}#{match[2]}" + (last ? last : xc)
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([:u])}#{match[2]}" + (last ? last : xc)
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,:black])}#{match[2]}#{c([:b,:black])}#{match[3]}#{c([:d,:black])}#{match[4]}" + (last ? last : xc)
655
+ "#{c([:d,:yellow,:on_black])}#{match[2]}#{match[3]}#{match[4]}" + (last ? last : xc)
642
656
  end
643
657
  end
644
658
 
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '0.0.12'
2
+ VERSION = '0.0.13'
3
3
  end
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.12
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-05-20 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake