mdless 2.1.10 → 2.1.11

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: 4dc58e8318fcc9ffc8a4b148f902a71bc5ef7179098b2b58f210cb1f2e4e0bc3
4
- data.tar.gz: 0c57011d06d423819b0766b77813134af58c85d539fcd177eb5eff08c55ea635
3
+ metadata.gz: e103adb25eb7f60ff660cae6071863165cc8248d0d22a2aa673c240bc470f680
4
+ data.tar.gz: 4ec87e6815250971fbd3b536776137be756ccf324fac5dda2abac16ca786fb22
5
5
  SHA512:
6
- metadata.gz: 6161f939a995dde611d4c8ce6dbdf75a97a4c42f051f24c2486812e994b74c5eaf67548c4f308c5b01f64df9b00cc6c1ba2699928e788817e5a8f38c5c09772e
7
- data.tar.gz: b63230e50bf1c9b8e4e502282928c3d3d56867269a1c61abe73a0e0b3c3ad2b6b174f7767a046c858210a606084d3c41f6dda15852ede26f58ae97a8026b1b13
6
+ metadata.gz: d45d4d1c865a9c00bc710739cf208c300c7e421ccc785d633715fe7350af81928fe79b28effe050be39cba6c33f4c64f472424e4c103c9e5225bd8dfd1b85fba
7
+ data.tar.gz: 29062adc822df60367956d417fb5e9851c03d149e81aec7cb439e3e8586c55fe9df5733d8774f587b8acae4ea91ebfff246b91734ea26473bd2f43859261228d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 2.1.11
2
+ : Better regex for highlighting raw HTML
3
+ : Indentation in highlighted code blocks
4
+ : HTML Tag highlighting breaking pre/post color conversion
5
+
1
6
  2.1.10
2
7
  : Spinner while processing to indicate working
3
8
  : Image links can now be converted to reference format, with correct coloring
data/lib/mdless/colors.rb CHANGED
@@ -150,9 +150,11 @@ module CLIMarkdown
150
150
  # input.gsub!(/\[.*?\]\(.*?\)/) do |link|
151
151
  # link.gsub(/ /, "\u00A0")
152
152
  # end
153
- input.split(/\s+/).each do |word|
153
+ input.split(/\s/).each do |word|
154
154
  last_ansi = line.last_color_code
155
- if visible_width + word.size_clean >= width
155
+ if word =~ /[\s\t]/
156
+ line << word
157
+ elsif visible_width + word.size_clean >= width
156
158
  lines << line + xc
157
159
  visible_width = word.size_clean
158
160
  line = last_ansi + word
@@ -66,14 +66,41 @@ module Redcarpet
66
66
  end
67
67
 
68
68
  def hilite_code(code_block, language)
69
+ longest_line = code_block.uncolor.split(/\n/).longest_element.length + 4
70
+ longest_line = longest_line > MDLess.cols ? MDLess.cols : longest_line
71
+
72
+ # if MDLess.options[:syntax_higlight]
73
+ # formatter = Rouge::Formatters::Terminal256
74
+ # lexer = if language
75
+ # Object.const_get("Rouge::Lexers::#{language.capitalize}") rescue Rouge::Lexer.guess(source: code_block)
76
+ # else
77
+ # Rouge::Lexer.guess(source: code_block)
78
+ # end
79
+ # hilite = formatter.format(lexer.lex(code_block))
80
+ # hilite = xc + hilite.split(/\n/).map do |l|
81
+ # [
82
+ # color('code_block marker'),
83
+ # MDLess.theme['code_block']['character'],
84
+ # "#{color('code_block bg')}#{l.rstrip}#{xc}"
85
+ # ].join
86
+ # end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
87
+ # else
88
+ # hilite = code_block.split(/\n/).map do |line|
89
+ # [
90
+ # color('code_block marker'),
91
+ # MDLess.theme['code_block']['character'],
92
+ # color('code_block color'),
93
+ # line,
94
+ # xc
95
+ # ].join
96
+ # end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
97
+ # end
98
+
69
99
  if MDLess.options[:syntax_higlight] && !exec_available('pygmentize')
70
100
  MDLess.log.error('Syntax highlighting requested by pygmentize is not available')
71
101
  MDLess.options[:syntax_higlight] = false
72
102
  end
73
103
 
74
- longest_line = code_block.uncolor.split(/\n/).longest_element.length + 4
75
- longest_line = longest_line > MDLess.cols ? MDLess.cols : longest_line
76
-
77
104
  if MDLess.options[:syntax_higlight]
78
105
  pyg = TTY::Which.which('pygmentize')
79
106
  lexer = language&.valid_lexer? ? "-l #{language}" : '-g'
@@ -93,15 +120,17 @@ module Redcarpet
93
120
  ].join(' ')
94
121
  hilite, s = Open3.capture2(cmd,
95
122
  stdin_data: code_block)
123
+
96
124
  if s.success?
97
125
  hilite = xc + hilite.split(/\n/).map do |l|
98
126
  [
99
127
  color('code_block marker'),
100
128
  MDLess.theme['code_block']['character'],
101
- "#{color('code_block bg')}#{l.rstrip}#{xc}"
129
+ "#{color('code_block bg')}#{l}#{xc}"
102
130
  ].join
103
131
  end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
104
132
  end
133
+
105
134
  rescue StandardError => e
106
135
  MDLess.log.error(e)
107
136
  hilite = code_block
@@ -123,7 +152,6 @@ module Redcarpet
123
152
  else
124
153
  "--[ #{language} ]#{'-' * (longest_line - 6 - language.length)}"
125
154
  end
126
-
127
155
  [
128
156
  xc,
129
157
  color('code_block border'),
@@ -234,10 +262,15 @@ module Redcarpet
234
262
  end
235
263
 
236
264
  def paragraph(text)
237
- if MDLess.options[:preserve_linebreaks]
238
- "#{xc}#{text.gsub(/ +/, ' ').strip}#{xc}#{x}\n\n"
265
+ out = if MDLess.options[:preserve_linebreaks]
266
+ "#{xc}#{text.gsub(/ +/, ' ').strip}#{xc}#{x}\n\n"
267
+ else
268
+ "#{xc}#{text.gsub(/ +/, ' ').gsub(/\n+(?![:-])/, ' ').strip}#{xc}#{x}\n\n"
269
+ end
270
+ if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
271
+ highlight_tags(out)
239
272
  else
240
- "#{xc}#{text.gsub(/ +/, ' ').gsub(/\n+(?![:-])/, ' ').strip}#{xc}#{x}\n\n"
273
+ out
241
274
  end
242
275
  end
243
276
 
@@ -481,7 +514,7 @@ module Redcarpet
481
514
  end
482
515
 
483
516
  def color_tags(html)
484
- html.gsub(%r{(<\S+( [^>]+)?>)}, "#{color('html brackets')}\\1#{xc}")
517
+ html.gsub(%r{((?!<)</?\w+( [^>]+)?>)}, "#{color('html brackets')}\\1#{xc}")
485
518
  end
486
519
 
487
520
  def raw_html(raw_html)
@@ -580,26 +613,31 @@ module Redcarpet
580
613
  end
581
614
 
582
615
  def color_list_item(indent, content, type, counter)
583
- case type
584
- when :unordered
585
- [
586
- indent,
587
- color('list bullet'),
588
- MDLess.theme['list']['ul_char'].strip,
589
- ' ',
590
- color('list color'),
591
- indent_lines(content, indent).strip,
592
- xc
593
- ].join
594
- when :ordered
595
- [
596
- indent,
597
- color('list number'),
598
- "#{counter}. ",
599
- color('list color'),
600
- indent_lines(content, indent).strip,
601
- xc
602
- ].join
616
+ out = case type
617
+ when :unordered
618
+ [
619
+ indent,
620
+ color('list bullet'),
621
+ MDLess.theme['list']['ul_char'].strip,
622
+ ' ',
623
+ color('list color'),
624
+ indent_lines(content, indent).strip,
625
+ xc
626
+ ].join
627
+ when :ordered
628
+ [
629
+ indent,
630
+ color('list number'),
631
+ "#{counter}. ",
632
+ color('list color'),
633
+ indent_lines(content, indent).strip,
634
+ xc
635
+ ].join
636
+ end
637
+ if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
638
+ color_tags(out)
639
+ else
640
+ out
603
641
  end
604
642
  end
605
643
 
@@ -1035,7 +1073,6 @@ module Redcarpet
1035
1073
  input = reference_links(input) if MDLess.options[:links] == :reference || MDLess.options[:links] == :paragraph
1036
1074
  # lists
1037
1075
  input = fix_lists(input)
1038
- input = highlight_tags(input) if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
1039
1076
  fix_colors(input)
1040
1077
  end
1041
1078
  end
@@ -105,8 +105,8 @@ module CLIMarkdown
105
105
  end
106
106
 
107
107
  default(:at_tags, false)
108
- opts.on('-@', '--at_tags', 'Highlight @tags and values in the document') do
109
- MDLess.options[:at_tags] = true
108
+ opts.on('-@', '--[no-]at-tags', 'Highlight @tags and values in the document') do |opt|
109
+ MDLess.options[:at_tags] = opt
110
110
  end
111
111
 
112
112
  opts.on('-v', '--version', 'Display version number') do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.1.10'
4
+ VERSION = '2.1.11'
5
5
  end
data/lib/mdless.rb CHANGED
@@ -6,6 +6,7 @@ require 'logger'
6
6
  require 'tty-which'
7
7
  require 'tty-screen'
8
8
  require 'tty-spinner'
9
+ require 'rouge'
9
10
  require 'mdless/version.rb'
10
11
  require 'mdless/colors'
11
12
  require 'mdless/tables'
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.1.10
4
+ version: 2.1.11
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-12-02 00:00:00.000000000 Z
11
+ date: 2023-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rouge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement