mdless 1.0.21 → 1.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6d1b744e285d103ea81159c8663b7158a26d8609cd7411ca47c6451cf896ea8
4
- data.tar.gz: 9b42221d8ed826e288067b56237af338c320c996fb57215784547ce57cc3b8f8
3
+ metadata.gz: ea19ef57c9cdd3b8800a854cc342e518c3c5acca0a2bfd6806f30970686e37e7
4
+ data.tar.gz: aaf0111e1b7777c06ddb149032985665184f92c6a34e4d5d6e7a5abecf691289
5
5
  SHA512:
6
- metadata.gz: 1e168c66bc6eaf8cf30303ac4e8e33469d1d43c38c546b081aaccf5dd9cc7888aecef892e315036fa4c73c8a3bb4fe2887b35ae40169c9d3d18d60a882738c07
7
- data.tar.gz: c57f891b278a448527a9ce432d5536ef09a1706132c233a27c62a44fdf273ccb6e030ca3227965f191634d3bfbc21fb4c1a4f80e28a3aed4f97e4f202178cf05
6
+ metadata.gz: 11e08991457fd1c94698666be37e40e38c59753b4437e94c01a45a0215d9fbf7fea00c6bedbbb5408451f8ea8402897dcf81d6a8f757950669c2c85f1371ba48
7
+ data.tar.gz: 997cbd5836733b2740ae15d344764c6e303d41d77ec760392a9bad6ccdc08f8aaa2457601f0385449964826d423e9f26036c5d843946e50a94ecb922f5ce4e3b
data/lib/mdless/colors.rb CHANGED
@@ -71,7 +71,7 @@ module CLIMarkdown
71
71
  self.uncolor.size
72
72
  end
73
73
 
74
- def wrap(width=78)
74
+ def wrap(width=78,foreground=:x)
75
75
 
76
76
  if self.uncolor =~ /(^([%~] |\s*>)| +[=\-]{5,})/
77
77
  return self
@@ -87,7 +87,7 @@ module CLIMarkdown
87
87
  input.split(/\s+/).each do |word|
88
88
  last_ansi = line.scan(/\e\[[\d;]+m/)[-1] || ''
89
89
  if visible_width + word.size_clean >= width
90
- lines << line + xc
90
+ lines << line + xc(foreground)
91
91
  visible_width = word.size_clean
92
92
  line = last_ansi + word
93
93
  elsif line.empty?
@@ -98,18 +98,11 @@ module CLIMarkdown
98
98
  line << " " << last_ansi + word
99
99
  end
100
100
  end
101
- lines << line + self.match(/\s*$/)[0] + xc if line
101
+ lines << line + self.match(/\s*$/)[0] + xc(foreground) if line
102
102
  return lines.join("\n") # .gsub(/\- (\S)/,'-\1')
103
103
  end
104
104
 
105
- def xc(count=0)
106
- c([:x,:white])
107
- end
108
-
109
105
  def c(args)
110
-
111
-
112
-
113
106
  out = []
114
107
 
115
108
  args.each {|arg|
@@ -124,6 +117,12 @@ module CLIMarkdown
124
117
  ''
125
118
  end
126
119
  end
120
+
121
+ private
122
+
123
+ def xc(foreground=:x)
124
+ c([foreground])
125
+ end
127
126
  end
128
127
  end
129
128
 
@@ -169,7 +169,7 @@ module CLIMarkdown
169
169
  if @theme.key?(keys[0])
170
170
  val = @theme[keys.shift]
171
171
  else
172
- @log.error("Invalid theme key: #{key}")
172
+ @log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
173
173
  return c([:reset])
174
174
  end
175
175
  keys.each {|k|
@@ -360,7 +360,7 @@ module CLIMarkdown
360
360
  end
361
361
  end
362
362
 
363
- def find_color(line,nullable=false)
363
+ def find_color(line, nullable = false)
364
364
  return line if line.nil?
365
365
  colors = line.scan(/\e\[[\d;]+m/)
366
366
  if colors && colors.size > 0
@@ -473,13 +473,14 @@ module CLIMarkdown
473
473
  color('code_block border'),
474
474
  '--[ ',
475
475
  color('code_block title'),
476
- leader,
476
+ leader.chomp,
477
477
  color('code_block border'),
478
478
  ' ]',
479
- '-'*(@cols-new_indent-leader.size+1),
479
+ '-'*(@cols-new_indent-leader.size-2),
480
480
  xc,
481
481
  "\n",
482
- hilite,
482
+ hilite.chomp,
483
+ "\n",
483
484
  " "*(new_indent),
484
485
  color('code_block border'),
485
486
  '-'*(@cols-new_indent),
@@ -581,6 +582,44 @@ module CLIMarkdown
581
582
  # match = Regexp.last_match
582
583
  # "#" * (match[1].length - h_adjust)
583
584
  # end
585
+ #
586
+ # Headlines
587
+ @headers.each {|h|
588
+ input.sub!(/^#{Regexp.escape(h[2])}/m) do |m|
589
+ pad = ''
590
+ ansi = ''
591
+ case h[0].length
592
+ when 1
593
+ ansi = color('h1 color')
594
+ pad = color('h1 pad')
595
+ char = @theme['h1']['pad_char'] || "="
596
+ pad += h[1].length + 2 > @cols ? char*h[1].length : char*(@cols - (h[1].length + 1))
597
+ when 2
598
+ ansi = color('h2 color')
599
+ pad = color('h2 pad')
600
+ char = @theme['h2']['pad_char'] || "-"
601
+ pad += h[1].length + 2 > @cols ? char*h[1].length : char*(@cols - (h[1].length + 1))
602
+ when 3
603
+ ansi = color('h3 color')
604
+ when 4
605
+ ansi = color('h4 color')
606
+ when 5
607
+ ansi = color('h5 color')
608
+ else
609
+ ansi = color('h6 color')
610
+ end
611
+
612
+ # If we're in iTerm and not paginating, add
613
+ # iTerm Marks for navigation on h1-3
614
+ if h[0].length < 4 &&
615
+ ENV['TERM_PROGRAM'] =~ /^iterm/i &&
616
+ @options[:pager] == false
617
+ ansi = "\e]1337;SetMark\a" + ansi
618
+ end
619
+
620
+ "\n#{xc}#{ansi}#{h[1]} #{pad}#{xc}\n"
621
+ end
622
+ }
584
623
 
585
624
  # code block parsing
586
625
  input.gsub!(/(?i-m)(^[ \t]*[`~]{3,})([\s\S]*?)\n([\s\S]*?)\1/m) do
@@ -637,11 +676,41 @@ module CLIMarkdown
637
676
  # previous_indent = indent
638
677
  # end
639
678
  else
679
+ # list items
680
+ # TODO: Fix ordered list numbering, pad numbers based on total number of list items
681
+ line.gsub!(/^(\s*)([*\-+]|\d+\.) /) do |m|
682
+ match = Regexp.last_match
683
+ last = find_color(match.pre_match)
684
+ mcolor = match[2] =~ /^\d+\./ ? 'list number' : 'list bullet'
685
+ indent = match[1] || ''
686
+ [
687
+ indent,
688
+ color(mcolor),
689
+ match[2], " ",
690
+ color('list color')
691
+ ].join
692
+ end
693
+
694
+ # definition lists
695
+ line.gsub!(/^(:\s*)(.*?)/) do |m|
696
+ match = Regexp.last_match
697
+ [
698
+ color('dd marker'),
699
+ match[1],
700
+ " ",
701
+ color('dd color'),
702
+ match[2],
703
+ xc
704
+ ].join
705
+ end
706
+
640
707
  # place footnotes under paragraphs that reference them
641
708
  if line =~ /\[(?:\e\[[\d;]+m)*\^(?:\e\[[\d;]+m)*(\S+)(?:\e\[[\d;]+m)*\]/
642
- key = $1.uncolor
709
+ match = Regexp.last_match
710
+ key = match[1].uncolor
643
711
  if @footnotes.key? key
644
- line += "\n\n#{c(%i[b black on_black])}[#{c(%i[b cyan on_black])}^#{c(%i[x yellow on_black])}#{key}#{c(%i[b black on_black])}]: #{c(%i[u white on_black])}#{@footnotes[key]}#{xc}"
712
+ line = "#{xc}#{line}"
713
+ line += "\n\n#{color('footnote brackets')}[#{color('footnote caret')}^#{color('footnote title')}#{key}#{color('footnote brackets')}]: #{color('footnote note')}#{@footnotes[key]}#{xc}"
645
714
  @footnotes.delete(key)
646
715
  end
647
716
  end
@@ -655,7 +724,7 @@ module CLIMarkdown
655
724
  counter -= 1
656
725
  find_color(lines[counter])
657
726
  end
658
- "#{c(%i[b black])}[#{c(%i[b yellow])}^#{c(%i[x yellow])}#{match[1]}#{c(%i[b black])}]" + (last ? last : xc)
727
+ "#{color('footnote brackets')}[#{color('footnote caret')}^#{color('footnote title')}#{match[1]}#{color('footnote brackets')}]" + (last ? last : xc)
659
728
  end
660
729
 
661
730
  # blockquotes
@@ -671,7 +740,6 @@ module CLIMarkdown
671
740
  end
672
741
 
673
742
  # make reference links inline
674
-
675
743
  line.gsub!(/(?<![\e*])\[(\b.*?\b)?\]\[(\b.+?\b)?\]/) do |m|
676
744
  match = Regexp.last_match
677
745
  title = match[2] || ''
@@ -695,23 +763,6 @@ module CLIMarkdown
695
763
  color_link(match.pre_match, match[1], match[2])
696
764
  end
697
765
 
698
-
699
-
700
- # inline code
701
- line.gsub!(/`(.*?)`/) do |m|
702
- match = Regexp.last_match
703
- last = find_color(match.pre_match, true)
704
- [
705
- color('code_span marker'),
706
- '`',
707
- color('code_span color'),
708
- match[1],
709
- color('code_span marker'),
710
- '`',
711
- last ? last : xc
712
- ].join
713
- end
714
-
715
766
  # horizontal rules
716
767
  line.gsub!(/^ {,3}([\-*] ?){3,}$/) do |m|
717
768
  color('hr color') + '_'*@cols + xc
@@ -746,7 +797,7 @@ module CLIMarkdown
746
797
  end
747
798
 
748
799
  # equations
749
- line.gsub!(/((\\\\\[)(.*?)(\\\\\])|(\\\\\()(.*?)(\\\\\)))/) do |m|
800
+ line.gsub!(/((\\\\\[|\$\$)(.*?)(\\\\\]|\$\$)|(\\\\\(|\$)(.*?)(\\\\\)|\$))/) do |m|
750
801
  match = Regexp.last_match
751
802
  last = find_color(match.pre_match)
752
803
  if match[2]
@@ -759,34 +810,6 @@ module CLIMarkdown
759
810
  "#{c(%i[b black])}#{brackets[0]}#{xc}#{c(%i[b blue])}#{equat}#{c(%i[b black])}#{brackets[1]}" + (last ? last : xc)
760
811
  end
761
812
 
762
- # list items
763
- # TODO: Fix ordered list numbering, pad numbers based on total number of list items
764
- line.gsub!(/^(\s*)([*\-+]|\d+\.) /) do |m|
765
- match = Regexp.last_match
766
- last = find_color(match.pre_match)
767
- mcolor = match[2] =~ /^\d+\./ ? 'list number' : 'list bullet'
768
- indent = match[1] || ''
769
- [
770
- indent,
771
- color(mcolor),
772
- match[2], " ",
773
- color('list color')
774
- ].join
775
- end
776
-
777
- # definition lists
778
- line.gsub!(/^(:\s*)(.*?)/) do |m|
779
- match = Regexp.last_match
780
- [
781
- color('dd marker'),
782
- match[1],
783
- " ",
784
- color('dd color'),
785
- match[2],
786
- xc
787
- ].join
788
- end
789
-
790
813
  # misc html
791
814
  line.gsub!(/<br\/?>/, "\n")
792
815
  line.gsub!(/(?i-m)((<\/?)(\w+[\s\S]*?)(>))/) do |tag|
@@ -802,51 +825,33 @@ module CLIMarkdown
802
825
  last ? last : xc
803
826
  ].join
804
827
  end
828
+
829
+ # inline code spans
830
+ line.gsub!(/`(.*?)`/) do |m|
831
+ match = Regexp.last_match
832
+ last = find_color(match.pre_match, true)
833
+ [
834
+ color('code_span marker'),
835
+ '`',
836
+ color('code_span color'),
837
+ match[1],
838
+ color('code_span marker'),
839
+ '`',
840
+ last ? last : xc
841
+ ].join
842
+ end
805
843
  end
806
844
 
845
+ ## Should force a foreground color but doesn't...
846
+ # unless line =~ /^\s*\e\[[\d;]+m/
847
+ # line.sub!(/^(\s*)/, "\\1#{color('text')}")
848
+ # end
849
+
807
850
  line
808
851
  end
809
852
 
810
853
  input = lines.join("\n")
811
854
 
812
- # Headlines
813
- @headers.each {|h|
814
- input.sub!(/^#{Regexp.escape(h[2])}/m) do |m|
815
- pad = ''
816
- ansi = ''
817
- case h[0].length
818
- when 1
819
- ansi = color('h1 color')
820
- pad = color('h1 pad')
821
- char = @theme['h1']['pad_char'] || "="
822
- pad += h[1].length + 2 > @cols ? char*h[1].length : char*(@cols - (h[1].length + 1))
823
- when 2
824
- ansi = color('h2 color')
825
- pad = color('h2 pad')
826
- char = @theme['h2']['pad_char'] || "-"
827
- pad += h[1].length + 2 > @cols ? char*h[1].length : char*(@cols - (h[1].length + 1))
828
- when 3
829
- ansi = color('h3 color')
830
- when 4
831
- ansi = color('h4 color')
832
- when 5
833
- ansi = color('h5 color')
834
- else
835
- ansi = color('h6 color')
836
- end
837
-
838
- # If we're in iTerm and not paginating, add
839
- # iTerm Marks for navigation on h1-3
840
- if h[0].length < 4 &&
841
- ENV['TERM_PROGRAM'] =~ /^iterm/i &&
842
- @options[:pager] == false
843
- ansi = "\e]1337;SetMark\a" + ansi
844
- end
845
-
846
- "\n#{xc}#{ansi}#{h[1]} #{pad}#{xc}\n"
847
- end
848
- }
849
-
850
855
  # images
851
856
  input.gsub!(/^(.*?)!\[(.*)?\]\((.*?\.(?:png|gif|jpg))( +.*)?\)/) do |m|
852
857
  match = Regexp.last_match
@@ -985,7 +990,7 @@ module CLIMarkdown
985
990
 
986
991
  def printout
987
992
  out = @output.rstrip.split(/\n/).map {|p|
988
- p.wrap(@cols)
993
+ p.wrap(@cols, color('text'))
989
994
  }.join("\n")
990
995
 
991
996
 
@@ -1048,5 +1053,9 @@ module CLIMarkdown
1048
1053
 
1049
1054
  [pg, args]
1050
1055
  end
1056
+
1057
+ def xc
1058
+ color('text')
1059
+ end
1051
1060
  end
1052
1061
  end
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.21'
2
+ VERSION = '1.0.22'
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: 1.0.21
4
+ version: 1.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-02 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake