marked-conductor 1.0.32 → 1.0.35

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: 7db6a6044dabe2b2487ae53119d385822269ef5a188727e37976310e5b47e54e
4
- data.tar.gz: 6d054087984dcd36038705e7ae7fd4b9fc94cc2194899a9e3eb01903ee44f93f
3
+ metadata.gz: 31042fe7c5635982e15c551493cf380e0d3aabae92051871144172e5890e2328
4
+ data.tar.gz: 8ea8a81fb13a5342332e5c3ac779fea2dced77b34318f1e43210d1d5c388dd54
5
5
  SHA512:
6
- metadata.gz: acd13153ea7b8401fd2e602f3935178eceee61359d8a32e1f228f1adbb4459b76330a4d98440511dca85cd92ae7ff731725102a39e56cd68327f9c756904cc62
7
- data.tar.gz: 60c139677c180c043c5aaeddf9cfe6df338e9f62e6eb8ef0384c15accc1f666763259b3f94abd5374b86a60fa486f67b821ddd484edc1112e78fa3f9c05a553e
6
+ metadata.gz: d8bea2c1c42bf3bf95819b1371368ad73a810860725fc2e86ccf2803c11de5de826740cd32723c5b67ccf2423e7bebb15442888e163c1fe5188924988c9b15f3
7
+ data.tar.gz: b8a3881c29831dae7b37b7eeafb31acf5c34ccaf79c99e9b2bed2252a71f82575417dfe8941ba9c2d6629fad6c10511dacff6d40dd05a5022c91804720568c96
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ### 1.0.35
2
+
3
+ 2024-08-22 10:14
4
+
5
+ #### IMPROVED
6
+
7
+ - Code cleanup
8
+ - Cleaner UTF-8 string encoding
9
+
10
+ ### 1.0.34
11
+
12
+ 2024-08-22 10:13
13
+
14
+ #### IMPROVED
15
+
16
+ - Code cleanup
17
+ - Cleaner UTF-8 string encoding
18
+
19
+ ### 1.0.33
20
+
21
+ 2024-08-22 06:35
22
+
23
+ #### IMPROVED
24
+
25
+ - Clean up string encoding in filters
26
+
1
27
  ### 1.0.32
2
28
 
3
29
  2024-07-31 11:12
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- marked-conductor (1.0.28)
4
+ marked-conductor (1.0.33)
5
5
  chronic (~> 0.10.2)
6
6
  tty-which (~> 0.5.0)
7
7
 
data/bin/conductor CHANGED
@@ -1,65 +1,29 @@
1
- #!/usr/bin/env ruby -W1
1
+ #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../lib/conductor"
5
- require "optparse"
6
-
7
- options = {
8
- config_file: nil
9
- }
10
-
11
- optparse = OptionParser.new do |opts|
12
- opts.banner = "Called from Marked 2 as a Custom Pre/Processor"
13
-
14
- opts.on("-c", "--config", "Specify alternate config file") do |file|
15
- config = File.expand_path(file)
16
- raise "Config file not found" unless File.exist?(config)
17
-
18
- options[:config_file] = file
19
- end
20
-
21
- opts.on("-v", "--version", "Show version number") do
22
- puts "conductor v#{Conductor::VERSION}"
23
- Process.exit 0
24
- end
25
-
26
- opts.on("-h", "--help", "Display this screen") do
27
- puts opts
28
- exit
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'conductor' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
29
23
  end
30
24
  end
31
25
 
32
- optparse.parse!
26
+ require "rubygems"
27
+ require "bundler/setup"
33
28
 
34
- config = Conductor::Config.new
35
- config.config_file = options[:config_file] if options[:config_file]
36
- res = config.configure
37
-
38
- Process.exit 0 unless res
39
-
40
- Conductor.stdin
41
- Conductor.original_input = Conductor.stdin
42
-
43
- tracks = config.tracks
44
- res, condition = Conductor.conduct(tracks)
45
-
46
- ##
47
- ## Clean up conditions for output
48
- ##
49
- ## @param condition The condition
50
- ##
51
- def clean_condition(condition)
52
- condition.join("").sub(/ *(->|,) *$/, "")
53
- end
54
-
55
- if res.nil?
56
- warn "No conditions satisfied"
57
- # puts Conductor::Env
58
- puts "NOCUSTOM"
59
- elsif res == Conductor.original_input
60
- warn "No change in output"
61
- puts "NOCUSTOM"
62
- else
63
- warn "Met condition: #{clean_condition(condition)}"
64
- puts res
65
- end
29
+ load Gem.bin_path("marked-conductor", "conductor")
@@ -67,7 +67,7 @@ module Conductor
67
67
  end
68
68
 
69
69
  if use_stdin
70
- `echo #{Shellwords.escape(stdin.force_encoding("utf-8"))} | #{Env} #{path} #{args}`
70
+ `echo #{Shellwords.escape(stdin.utf8)} | #{Env} #{path} #{args}`
71
71
  else
72
72
  `#{Env} #{path} #{args}`
73
73
  end
@@ -42,7 +42,7 @@ class ::String
42
42
  ## @return [Symbol] metadata type
43
43
  ##
44
44
  def meta_type
45
- lines = split(/\n/)
45
+ lines = utf8.split(/\n/)
46
46
  case lines[0]
47
47
  when /^--- *$/
48
48
  :yaml
@@ -65,7 +65,7 @@ class ::String
65
65
 
66
66
  case meta_type
67
67
  when :yaml
68
- lines = split(/\n/)
68
+ lines = utf8.split(/\n/)
69
69
  lines.shift
70
70
  lines.each_with_index do |line, idx|
71
71
  next unless line =~ /^(\.\.\.|---) *$/
@@ -74,7 +74,7 @@ class ::String
74
74
  break
75
75
  end
76
76
  when :mmd
77
- lines = split(/\n/)
77
+ lines = utf8.split(/\n/)
78
78
  lines.each_with_index do |line, idx|
79
79
  next if line =~ /^ *[ \w]+: +\S+/
80
80
 
@@ -82,7 +82,7 @@ class ::String
82
82
  break
83
83
  end
84
84
  when :pandoc
85
- lines = split(/\n/)
85
+ lines = utf8.split(/\n/)
86
86
  lines.each_with_index do |line, idx|
87
87
  next if line =~ /^% +\S/
88
88
 
@@ -101,7 +101,7 @@ class ::String
101
101
  ##
102
102
  def first_h1
103
103
  first = nil
104
- split(/\n/).each_with_index do |line, idx|
104
+ utf8.split(/\n/).each_with_index do |line, idx|
105
105
  if line =~ /^(# *[^#]|={2,} *$)/
106
106
  first = idx
107
107
  break
@@ -118,7 +118,7 @@ class ::String
118
118
  def first_h2
119
119
  first = nil
120
120
  meta_end = meta_insert_point
121
- split(/\n/).each_with_index do |line, idx|
121
+ utf8.split(/\n/).each_with_index do |line, idx|
122
122
  next if idx <= meta_end
123
123
 
124
124
  if line =~ /^(## *[^#]|-{2,} *$)/
@@ -177,7 +177,7 @@ class ::String
177
177
  ## @return [String] content with TOC tag added
178
178
  ##
179
179
  def insert_toc(max = nil, after = :h1)
180
- lines = split(/\n/)
180
+ lines = utf8.split(/\n/)
181
181
  max = max.to_i&.positive? ? " max#{max}" : ""
182
182
  line = case after.to_sym
183
183
  when :h2
@@ -238,7 +238,7 @@ class ::String
238
238
  if File.exist?(path)
239
239
  content = IO.read(path)
240
240
  yui = YuiCompressor::Yui.new
241
- content = yui.compress(content.force_encoding('utf-8'))
241
+ content = yui.compress(content.utf8)
242
242
  inject_after_meta(content.wrap_style)
243
243
  else
244
244
  warn "File not found (#{path})"
@@ -254,7 +254,7 @@ class ::String
254
254
  ## @return [String] string with content injected
255
255
  ##
256
256
  def inject_after_meta(content)
257
- lines = split(/\n/)
257
+ lines = utf8.split(/\n/)
258
258
  insert_point = meta_insert_point
259
259
  insert_at = insert_point.positive? ? insert_point + 1 : 0
260
260
  lines.insert(insert_at, "#{content}\n\n")
@@ -294,10 +294,10 @@ class ::String
294
294
  inject_after_meta(out)
295
295
  when :h1
296
296
  h1 = first_h1.nil? ? 0 : first_h1 + 1
297
- split(/\n/).insert(h1, out).join("\n")
297
+ utf8.split(/\n/).insert(h1, out).join("\n")
298
298
  when :h2
299
299
  h2 = first_h2.nil? ? 0 : first_h2 + 1
300
- split(/\n/).insert(h2, out).join("\n")
300
+ utf8.split(/\n/).insert(h2, out).join("\n")
301
301
  else
302
302
  "#{self}\n#{out}"
303
303
  end
@@ -393,7 +393,7 @@ class ::String
393
393
  yaml = YAML.load(m[0])
394
394
  title = yaml["title"]
395
395
  when :mmd
396
- split(/\n/).each do |line|
396
+ utf8.split(/\n/).each do |line|
397
397
  if line =~ /^ *title: *(\S.*?)$/i
398
398
  title = Regexp.last_match(1)
399
399
  break
@@ -401,7 +401,7 @@ class ::String
401
401
  end
402
402
  when :pandoc
403
403
  title = nil
404
- split(/\n/).each do |line|
404
+ utf8.split(/\n/).each do |line|
405
405
  if line =~ /^% +(.*?)$/
406
406
  title = Regexp.last_match(1)
407
407
  break
@@ -419,7 +419,7 @@ class ::String
419
419
  end
420
420
 
421
421
  def insert_title(shift: 0)
422
- content = dup
422
+ content = dup.utf8
423
423
  title = read_title
424
424
  content.increase_headers!(shift) if shift.positive?
425
425
  lines = content.split(/\n/)
@@ -441,7 +441,7 @@ class ::String
441
441
  end
442
442
 
443
443
  def ensure_mmd_meta_newline
444
- split(/\n/).insert(meta_insert_point, "\n\n").join("\n")
444
+ utf8.split(/\n/).insert(meta_insert_point, "\n\n").join("\n")
445
445
  end
446
446
 
447
447
  def add_yaml(key, value)
@@ -466,7 +466,7 @@ class ::String
466
466
  if match(/(\A|\n) *#{key}: *\S+/i)
467
467
  sub(/^ *#{key}:.*?\n/i, "#{key}: #{value}\n")
468
468
  else
469
- lines = split(/\n/)
469
+ lines = utf8.split(/\n/)
470
470
  lines.insert(meta_insert_point, "#{key}: #{value}")
471
471
  "#{lines.join("\n")}\n"
472
472
  end
@@ -484,7 +484,7 @@ class ::String
484
484
  if comment?(key)
485
485
  sub(/ *#{key}: .*?$/, "#{key}: #{value}")
486
486
  else
487
- lines = split(/\n/)
487
+ lines = utf8.split(/\n/)
488
488
  lines.insert(meta_insert_point + 1, "\n<!--\n#{key}: #{value}\n-->")
489
489
  lines.join("\n")
490
490
  end
@@ -506,10 +506,10 @@ class ::String
506
506
  when :yaml
507
507
  sub(/^---.*?(---|\.\.\.)/m, "")
508
508
  when :mmd
509
- lines = split(/\n/)
509
+ lines = utf8.split(/\n/)
510
510
  lines[meta_insert_point..].join("\n")
511
511
  when :pandoc
512
- lines = split(/\n/)
512
+ lines = utf8.split(/\n/)
513
513
  lines[meta_insert_point..].join("\n")
514
514
  else
515
515
  gsub(/(\n|^)<!--\n[\w\d\s]+: ([\w\d\s]+)\n-->\n/m, '')
@@ -574,7 +574,7 @@ class ::String
574
574
  ##
575
575
  def ensure_h1
576
576
  headers = to_enum(:scan, /(\#{1,6})([^#].*?)$/m).map { Regexp.last_match }
577
- return self if headers.select { |h| h[1].size == 1 }.count.positive?
577
+ return self unless headers.select { |h| h[1].size == 1 }.empty?
578
578
 
579
579
  lowest_header = headers.min_by { |h| h[1].size }
580
580
  return self if lowest_header.nil?
@@ -72,7 +72,7 @@ module Conductor
72
72
  end
73
73
 
74
74
  if use_stdin
75
- `echo #{Shellwords.escape(stdin.force_encoding("utf-8"))} | #{Env} #{@path} #{@args}`
75
+ `echo #{Shellwords.escape(stdin.utf8)} | #{Env} #{@path} #{@args}`
76
76
  else
77
77
  `#{Env} #{@path} #{@args}`
78
78
  end
@@ -199,4 +199,40 @@ class ::String
199
199
  def to_pattern
200
200
  gsub(/\$(\d+)/, '\\\\\1').gsub(/(^["']|["']$)/, "")
201
201
  end
202
+
203
+ ##
204
+ ## Discard invalid characters and output a UTF-8 String
205
+ ##
206
+ ## @return [String] UTF-8 encoded string
207
+ ##
208
+ def utf8
209
+ encode('utf-16', invalid: :replace).encode('utf-8')
210
+ end
211
+
212
+ ##
213
+ ## Destructive version of #utf8
214
+ ##
215
+ ## @return [String] UTF-8 encoded string, in place
216
+ ##
217
+ def utf8!
218
+ replace scrub
219
+ end
220
+
221
+ ##
222
+ ## Get a clean UTF-8 string by forcing an ISO encoding and then re-encoding
223
+ ##
224
+ ## @return [String] UTF-8 string
225
+ ##
226
+ def clean_encode
227
+ force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
228
+ end
229
+
230
+ ##
231
+ ## Destructive version of #clean_encode
232
+ ##
233
+ ## @return [String] UTF-8 string, in place
234
+ ##
235
+ def clean_encode!
236
+ replace clean_encode
237
+ end
202
238
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conductor
4
- VERSION = '1.0.32'
4
+ VERSION = '1.0.35'
5
5
  end
@@ -137,7 +137,7 @@ module YuiCompressor
137
137
  ##
138
138
  ## @return [String] css text with strings replaced
139
139
  def process_comments_and_strings(css_text)
140
- css = css_text.dup.force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
140
+ css = css_text.dup.clean_encode
141
141
 
142
142
  start_index = 0
143
143
  token = ""
@@ -155,7 +155,7 @@ module YuiCompressor
155
155
  end
156
156
 
157
157
  # preserve strings so their content doesn't get accidentally minified
158
- css.gsub!(/("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')/) do |match|
158
+ css = css.gsub(/("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')/) do |match|
159
159
  quote = match[0, 1]
160
160
  string = match.slice(1..-2)
161
161
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marked-conductor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.32
4
+ version: 1.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  - !ruby/object:Gem::Version
245
245
  version: '0'
246
246
  requirements: []
247
- rubygems_version: 3.2.15
247
+ rubygems_version: 3.2.16
248
248
  signing_key:
249
249
  specification_version: 4
250
250
  summary: A custom processor manager for Marked 2 (Mac)