marked-conductor 1.0.24 → 1.0.26

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: 69dbd324dd85fed4c343563e7431920138a99d4968b8aa8af99ba7fcd5c82087
4
- data.tar.gz: ae2eb1f5251187fb67498139dae2d73b6fbce62778f2ef0197a01cb57561fe2c
3
+ metadata.gz: 580473330204caa4600148bf8ed0a29662b82b75f47443f71430d374eaff3b37
4
+ data.tar.gz: cb938a20bdd2e13cb001961b45f32a3003a323853867d880826a8cc7a4eaf48c
5
5
  SHA512:
6
- metadata.gz: 055a623d15c8bb843b97d6f1931342cab64ec596564f812ffb1b473a85dba9547f7091149619952baacc2d5c9b17e44597f9625aa5b7f2818b72c10760b51a66
7
- data.tar.gz: 4f998b8b19bca44f0f08ded4ad89f043802f62e4770d692b9b779c93aa8a52e6cd519fc675716f7b7c1dabaff66fbdbf4eea6611f224ac5db7cc61d7e22d704c
6
+ metadata.gz: c19b9f0b8485847b1ebc00d7e295c6344aeed0b1ba098e6d66742ad57118e6072d37e796a2ee6cd3b25715a74d1da026738e79874cd62cdbb7f68229cb985259
7
+ data.tar.gz: 9da479816110281f22948875946f12beb2f7883311c702a41bce6133eea877fa26751c321ac6a9c1aaa80c43e78338733d4366af656d7dc59f2d31ab243854fe
data/.irbrc CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "irb/completion"
4
- require_relative "lib/conductor"
3
+ IRB.conf[:AUTO_INDENT] = true
5
4
 
6
- include Conductor # standard:disable all
5
+ require "irb/completion"
6
+ # require_relative "lib/conductor"
7
7
 
8
- IRB.conf[:AUTO_INDENT] = true
8
+ # include Conductor # standard:disable all
9
9
 
10
10
  require "awesome_print"
11
11
  AwesomePrint.irb!
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ### 1.0.26
2
+
3
+ 2024-07-24 13:49
4
+
5
+ #### FIXED
6
+
7
+ - Don't recognize YAML closing line as settext header
8
+
9
+ ### 1.0.25
10
+
11
+ 2024-07-22 12:36
12
+
13
+ #### NEW
14
+
15
+ - `includes contains [file|path]` testing against included files
16
+
17
+ #### IMPROVED
18
+
19
+ - Better env variable handling
20
+
21
+ #### FIXED
22
+
23
+ - Inserting comment when YAML exists breaks YAML
24
+ - Ensure newline after MMD metadata
25
+ - Error in ensure_h1 if no headers exist
26
+
1
27
  ### 1.0.24
2
28
 
3
29
  2024-07-18 11:32
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- marked-conductor (1.0.8)
4
+ marked-conductor (1.0.25)
5
5
  chronic (~> 0.10.2)
6
6
  tty-which (~> 0.5.0)
7
7
 
@@ -83,6 +83,7 @@ GEM
83
83
 
84
84
  PLATFORMS
85
85
  arm64-darwin-20
86
+ x86_64-darwin-20
86
87
 
87
88
  DEPENDENCIES
88
89
  awesome_print (~> 1.9.2)
data/README.md CHANGED
@@ -104,6 +104,9 @@ Available conditions are:
104
104
  - If both the YAML key value and the test value are numbers, you can use operators `greater than` (`>`), `less than` (`<`), `equal`/`is` (`=`/`==`), and `is not equal`/`not equals` (`!=`/`!==`). Numbers will be interpreted as floats.
105
105
  - If the YAML value is a boolean, you can test with `is true` or `is not true` (or `is false`)
106
106
  - `mmd` or `meta` will test for MultiMarkdown metadata using the same formatting as `yaml` above.
107
+ - `includes` are files included in the document with special syntax (Marked, IA Writer, etc.)
108
+ - `includes contain file` or `includes not contains file` will test all included files for filename matches
109
+ - `includes contain path` or `includes not contains path` will test all included files for fragment matches anywhere in the path
107
110
  - The following keywords act as a catchall and can be used as the last track in the config to act on any documents that aren't matched by preceding rules:
108
111
  - `any`
109
112
  - `else`
data/bin/conductor CHANGED
@@ -130,6 +130,7 @@ end
130
130
 
131
131
  if res.nil?
132
132
  warn "No conditions satisfied"
133
+ # puts Conductor::Env
133
134
  puts "NOCUSTOM"
134
135
  else
135
136
  if res == Conductor.original_input
@@ -8,4 +8,30 @@ class ::Array
8
8
  def symbolize_keys
9
9
  map { |h| h.symbolize_keys }
10
10
  end
11
+
12
+ def shell_join
13
+ map { |p| Shellwords.join(p) }
14
+ end
15
+
16
+ def includes_file?(filename)
17
+ inc = false
18
+ each do |path|
19
+ if path.join =~ /#{Regexp.escape(filename)}$/i
20
+ inc = true
21
+ break
22
+ end
23
+ end
24
+ inc
25
+ end
26
+
27
+ def includes_frag?(frag)
28
+ inc = false
29
+ each do |path|
30
+ if path.join =~ /#{Regexp.escape(frag)}/i
31
+ inc = true
32
+ break
33
+ end
34
+ end
35
+ inc
36
+ end
11
37
  end
@@ -111,8 +111,9 @@ module Conductor
111
111
  return ["#{type}#{m[3]}", nil, op]
112
112
  end
113
113
 
114
- res = condition.match(/^(?<val1>.*?)(?:(?: +(?<op>(?:is|does)(?: not)?(?: an?|type(?: of)?|equals?(?: to))?|!?==?|[gl]t|(?:greater|less)(?: than)?|<|>|(?:starts|ends) with|(?:ha(?:s|ve) )?(?:prefix|suffix)|has|contains?|includes?) +)(?<val2>.*?))?$/i)
115
- [res["val1"], res["val2"], operator_to_symbol(res["op"])]
114
+ res = condition.match(/(?i)^(?<val1>.*?)(?:(?:\s+(?<bool>(?:is|does)?\s*(?:not)?\s*)(?<op>(?:an?|type(?:\sof)?|equals?(?:\sto))?|[!*$]?==?|[gl]t|(?:greater|less)(?:\sthan)?|<|>|(?:starts|ends) with|(?:ha(?:s|ve)\s)?(?:prefix|suffix)|(?:contains?|includes?)\s+(?:file|path)|has|contains?|includes?|match(?:es)?)\s+)(?<val2>.*?))?$/)
115
+ operator = res["bool"] ? "#{res["bool"]}#{res["op"]}" : res["op"]
116
+ [res["val1"], res["val2"], operator_to_symbol(operator)]
116
117
  end
117
118
 
118
119
  ##
@@ -140,6 +141,28 @@ module Conductor
140
141
  operator == :type_of ? res : !res
141
142
  end
142
143
 
144
+ ##
145
+ ## Test for includes
146
+ ##
147
+ ## @param includes [Array] array of included files
148
+ ## @param val value to test against
149
+ ## @param operator The operator
150
+ ##
151
+ def test_includes(includes, val, operator)
152
+ case operator
153
+ when :not_includes_file
154
+ !includes.includes_file?(val)
155
+ when :not_includes_path
156
+ !includes.includes_frag?(val)
157
+ when :includes_file
158
+ includes.includes_file?(val)
159
+ when :includes_path
160
+ includes.includes_frag?(val)
161
+ else
162
+ false
163
+ end
164
+ end
165
+
143
166
  ##
144
167
  ## Compare a string based on operator
145
168
  ##
@@ -353,6 +376,8 @@ module Conductor
353
376
  end
354
377
 
355
378
  case type
379
+ when /^include/i
380
+ test_includes(@env[:includes], value, operator) ? true : false
356
381
  when /^ext/i
357
382
  test_string(@env[:ext], value, operator) ? true : false
358
383
  when /^tree/i
@@ -386,6 +411,16 @@ module Conductor
386
411
  :gt
387
412
  when /(lt|less( than)?|<|(?:is )?before)/i
388
413
  :lt
414
+ when /not (ha(?:s|ve)|contains?|includes?) +file/i
415
+ :not_includes_file
416
+ when /not (ha(?:s|ve)|contains?|includes?) +path/i
417
+ :not_includes_path
418
+ when /(ha(?:s|ve)|contains?|includes?|\*=) +file/i
419
+ :includes_file
420
+ when /(ha(?:s|ve)|contains?|includes?|\*=) +path/i
421
+ :includes_path
422
+ when /(ha(?:s|ve)|contains|includes|match(es)?|\*=)/i
423
+ :contains
389
424
  when /not (ha(?:s|ve)|contains|includes|match(es)?)/i
390
425
  :not_contains
391
426
  when /(ha(?:s|ve)|contains|includes|match(es)?|\*=)/i
data/lib/conductor/env.rb CHANGED
@@ -14,7 +14,7 @@ module Conductor
14
14
  home: ENV["HOME"],
15
15
  css_path: ENV["MARKED_CSS_PATH"],
16
16
  ext: ENV["MARKED_EXT"],
17
- includes: Shellwords.shellsplit(ENV["MARKED_INCLUDES"]),
17
+ includes: ENV["MARKED_INCLUDES"].split(/,/).map { |s| Shellwords.shellsplit(s) },
18
18
  origin: ENV["MARKED_ORIGIN"],
19
19
  filepath: ENV["MARKED_PATH"],
20
20
  filename: File.basename(ENV["MARKED_PATH"]),
@@ -56,7 +56,7 @@ module Conductor
56
56
  "MARKED_CSS_PATH" => @env[:css_path],
57
57
  "MARKED_EXT" => @env[:ext],
58
58
  "MARKED_ORIGIN" => @env[:origin],
59
- "MARKED_INCLUDES" => Shellwords.join(@env[:includes]),
59
+ "MARKED_INCLUDES" => @env[:includes].shell_join.join(","),
60
60
  "MARKED_PATH" => @env[:filepath],
61
61
  "MARKED_PHASE" => @env[:phase],
62
62
  "OUTLINE" => @env[:outline],
@@ -205,6 +205,8 @@ class ::String
205
205
  inject_after_meta(out)
206
206
  when :h1
207
207
  split(/\n/).insert(first_h1 + 1, out).join("\n")
208
+ when :h2
209
+ split(/\n/).insert(first_h2 + 1, out).join("\n")
208
210
  else
209
211
  "#{self}\n#{out}"
210
212
  end
@@ -300,18 +302,22 @@ class ::String
300
302
  when :yaml
301
303
  add_yaml(key, value)
302
304
  when :mmd
303
- add_mmd(key, value)
305
+ add_mmd(key, value).ensure_mmd_meta_newline
304
306
  else # comment or none
305
307
  add_comment(key, value)
306
308
  end
307
309
  end
308
310
 
311
+ def ensure_mmd_meta_newline
312
+ split(/\n/).insert(meta_insert_point, "\n\n").join("\n")
313
+ end
314
+
309
315
  def add_yaml(key, value)
310
316
  sub(/^---.*?\n(---|\.\.\.)/m) do
311
317
  m = Regexp.last_match
312
318
  yaml = YAML.load(m[0])
313
- yaml[key] = value
314
- "#{YAML.dump(yaml)}\n---\n"
319
+ yaml[key.gsub(/ /, "_")] = value
320
+ "#{YAML.dump(yaml)}---\n"
315
321
  end
316
322
  end
317
323
 
@@ -330,7 +336,7 @@ class ::String
330
336
  else
331
337
  lines = split(/\n/)
332
338
  lines.insert(meta_insert_point, "#{key}: #{value}")
333
- lines.join("\n")
339
+ lines.join("\n") + "\n"
334
340
  end
335
341
  end
336
342
 
@@ -347,7 +353,7 @@ class ::String
347
353
  sub(/ *#{key}: .*?$/, "#{key}: #{value}")
348
354
  else
349
355
  lines = split(/\n/)
350
- lines.insert(meta_insert_point, "<!--\n#{key}: #{value}\n-->")
356
+ lines.insert(meta_insert_point + 1, "<!--\n#{key}: #{value}\n-->")
351
357
  lines.join("\n")
352
358
  end
353
359
  end
@@ -399,7 +405,7 @@ class ::String
399
405
  ## @return [String] content with headers updated
400
406
  ##
401
407
  def normalize_headers
402
- gsub(/^(\S.*)\n([=-]+)\n/) do
408
+ gsub(/^(?<=\n\n)(\S.*)\n([=-]+)\n/) do
403
409
  m = Regexp.last_match
404
410
  case m[2]
405
411
  when /\=/
@@ -426,6 +432,8 @@ class ::String
426
432
  return self if headers.select { |h| h[1].chars == 1 }.count.positive?
427
433
 
428
434
  lowest_header = headers.min_by { |h| h[1].chars }
435
+ return self if lowest_header.nil?
436
+
429
437
  level = lowest_header[1].chars
430
438
 
431
439
  sub(/#{Regexp.escape(lowest_header[0])}/, "# #{lowest_header[2].strip}").decrease_headers(level)
@@ -11,12 +11,18 @@ class ::String
11
11
  split(/(\W)/).map(&:capitalize).join
12
12
  end
13
13
 
14
+ def split_list
15
+ split(/,/).map { |s| Shellwords.shellsplit(s) }
16
+ end
17
+
14
18
  def normalize_position
15
19
  case self
16
20
  when /^(be|s|t)/
17
21
  :start
18
22
  when /h1/
19
23
  :h1
24
+ when /h2/
25
+ :h2
20
26
  else
21
27
  :end
22
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conductor
4
- VERSION = '1.0.24'
4
+ VERSION = '1.0.26'
5
5
  end
data/src/_README.md CHANGED
@@ -104,6 +104,9 @@ Available conditions are:
104
104
  - If both the YAML key value and the test value are numbers, you can use operators `greater than` (`>`), `less than` (`<`), `equal`/`is` (`=`/`==`), and `is not equal`/`not equals` (`!=`/`!==`). Numbers will be interpreted as floats.
105
105
  - If the YAML value is a boolean, you can test with `is true` or `is not true` (or `is false`)
106
106
  - `mmd` or `meta` will test for MultiMarkdown metadata using the same formatting as `yaml` above.
107
+ - `includes` are files included in the document with special syntax (Marked, IA Writer, etc.)
108
+ - `includes contain file` or `includes not contains file` will test all included files for filename matches
109
+ - `includes contain path` or `includes not contains path` will test all included files for fragment matches anywhere in the path
107
110
  - The following keywords act as a catchall and can be used as the last track in the config to act on any documents that aren't matched by preceding rules:
108
111
  - `any`
109
112
  - `else`
data/test.sh CHANGED
@@ -67,7 +67,7 @@ export MARKED_EXT="$EXTENSION"
67
67
  export MARKED_CSS_PATH="/Applications/Marked 2.app/Contents/Resources/swiss.css"
68
68
  export PATH="$PATH:$(dirname "$FILE")"
69
69
  export MARKED_PATH="$FILE"
70
- export MARKED_INCLUDES="/Applications/Marked 2.app/Contents/Resources/tocstyle.css"
70
+ export MARKED_INCLUDES='"/Applications/Marked 2.app/Contents/Resources/tocstyle.css","/Applications/Marked 2.app/Contents/Resources/javascript/main.js"'
71
71
  export MARKED_PHASE="$PHASE"
72
72
 
73
73
  if [[ $STD =~ ^(STD)?E ]]; then
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.24
4
+ version: 1.0.26
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-18 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print