marked-conductor 1.0.6 → 1.0.7

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: 684cf7a82ae4cce7240617f832ce52572b0373e578aaff487fbc50b47e2f5afd
4
- data.tar.gz: a6c5a9db2ee07216abd703f9ca833e4f83110b19eeba0ad993327ad2ef963623
3
+ metadata.gz: 3b5faacd380f833b615f2f848ed6f0bcb54dd955082b71228ab4f49c9e2bf0ac
4
+ data.tar.gz: 7c513f2fc4f75094e99ea27c48cf545ca738abe366271ec3da216f92ff0a4a5e
5
5
  SHA512:
6
- metadata.gz: e47df55cfed559207ddf931b2c08b98cae32709534d2b612b6b94afd3bee3b79342a7c4dc558ca4eefc77a6e894c0e8d37bb09358275fa260c2ccaffac480235
7
- data.tar.gz: 077e24abc630b9588671e2eb8b3af7736f88299063e76b5176b84b681690c81eb89532057121a795ce2c50fcf34ad3c4356f298064186e156c778f2f9fdb7184
6
+ metadata.gz: c84b488b4cc93effd14039e59be3ea76ce4d8e0c5ab882ceb542e93d158fb82d11b5f46bfcd60d5942a265d6554107fa964bb8acafe2d9ced9e8302ea7eb10a6
7
+ data.tar.gz: 7e80a80708878d3ab4dbc515d5554c77af6bdd42b8ceb496c2b16bb48b054ea8696aa57351eeae0a35adb3de00ef2dce6c509e77c850aa8ebb4a71c2d672a4f2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 1.0.7
2
+
3
+ 2024-04-26 11:53
4
+
5
+ #### NEW
6
+
7
+ - Added test for MMD metadata, either for presence of meta or for specific keys or key values
8
+
9
+ #### FIXED
10
+
11
+ - Remove some debugging garbage
12
+
1
13
  ### 1.0.6
2
14
 
3
15
  2024-04-26 11:17
data/README.md CHANGED
@@ -82,6 +82,7 @@ Available conditions are:
82
82
  - If the YAML key is a date, it can be tested against with `before`, `after`, and `is`, and the value can be a natural language date, e.g. `yaml:date is after may 3, 2024`
83
83
  - 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.
84
84
  - If the YAML value is a boolean, you can test with `is true` or `is not true` (or `is false`)
85
+ - `mmd` or `meta` will test for MultiMarkdown metadata using the same formatting as `yaml`.
85
86
  - 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:
86
87
  - `any`
87
88
  - `else`
@@ -116,8 +117,9 @@ A script run by Conductor already knows it has the right type of file with the e
116
117
 
117
118
  ## Tips
118
119
 
120
+ - Config file must be valid YAML. Any value containing colons, brackets, or other special characters should be quoted, e.g. (`condition: "text contains my:text"`)
119
121
  - You can see what condition matched in Marked by opening <b>Help->Show Custom Processor Log</b> and checking the STDERR output.
120
- - To run [a custom processor for Bear](https://brettterpstra.com/2023/10/08/marked-and-bear/), use the condition `text contains /source: *bear/`
122
+ - To run [a custom processor for Bear](https://brettterpstra.com/2023/10/08/marked-and-bear/), use the condition `"text contains <!-- source: bear.app -->"`
121
123
  - To run a custom processor for Obsidian, use the condition `tree contains .obsidian`
122
124
 
123
125
  ## Testing
@@ -45,7 +45,6 @@ module Conductor
45
45
  if use_stdin
46
46
  `echo #{Shellwords.escape(stdin)} | #{Env} #{path} #{args}`
47
47
  else
48
- puts "#{Env} #{path} #{args}"
49
48
  `#{Env} #{path} #{args}`
50
49
  end
51
50
  end
@@ -159,6 +159,59 @@ module Conductor
159
159
  operator == :not_equal ? !res : res
160
160
  end
161
161
 
162
+ def test_yaml(content, value, key, operator)
163
+ yaml = YAML.safe_load(content.split(/^(?:---|\.\.\.)/)[1])
164
+
165
+ return operator == :not_equal ? true : false unless yaml
166
+
167
+ if key
168
+ value1 = yaml[key]
169
+ return operator == :not_equal ? true : false if value1.nil?
170
+
171
+ value1 = value1.join(',') if value1.is_a?(Array)
172
+ if %i[type_of not_type_of].include?(operator)
173
+ test_type(value1, value, operator)
174
+ elsif value1.bool?
175
+ test_truthy(value1, value, operator)
176
+ elsif value1.number? && value2.number? && %i[gt lt equal not_equal].include?(operator)
177
+ test_operator(value1, value, operator)
178
+ else
179
+ test_string(value1, value, operator)
180
+ end
181
+ else
182
+ res = value ? yaml.key?(value) : true
183
+ operator == :not_equal ? !res : res
184
+ end
185
+ end
186
+
187
+ def test_meta(content, value, key, operator)
188
+ headers = []
189
+ content.split(/\n/).each do |line|
190
+ break if line == /^ *\n$/ || line !~ /\w+: *\S/
191
+
192
+ headers << line
193
+ end
194
+
195
+ return operator == :not_equal if headers.empty?
196
+
197
+ return operator != :not_equal if value.nil?
198
+
199
+ meta = {}
200
+ headers.each do |h|
201
+ parts = h.split(/ *: */)
202
+ k = parts[0].strip.downcase.gsub(/ +/, '')
203
+ v = parts[1..].join(':').strip
204
+ meta[k] = v
205
+ end
206
+
207
+ if key
208
+ test_string(meta[key], value, operator)
209
+ else
210
+ res = value ? meta.key?(value) : true
211
+ operator == :not_equal ? !res : res
212
+ end
213
+ end
214
+
162
215
  def test_condition(condition)
163
216
  type, value, operator = split_condition(condition)
164
217
 
@@ -181,35 +234,23 @@ module Conductor
181
234
  when /^phase/i
182
235
  test_string(@env[:phase], value, :starts_with) ? true : false
183
236
  when /^text/i
184
- puts IO.read(@env[:filepath]).force_encoding('utf-8')
185
237
  test_string(IO.read(@env[:filepath]).force_encoding('utf-8'), value, operator) ? true : false
186
238
  when /^(yaml|headers|frontmatter)(?::(.*?))?$/i
187
239
  m = Regexp.last_match
240
+
241
+ key = m[2] || nil
242
+
188
243
  content = IO.read(@env[:filepath]).force_encoding('utf-8')
189
- return false unless content =~ /^---/m
190
244
 
191
- yaml = YAML.safe_load(content.split(/^(?:---|\.\.\.)/)[1])
245
+ content.yaml? ? test_yaml(content, value, key, operator) : false
246
+ when /^(mmd|meta(?:data)?)(?::(.*?))?$/i
247
+ m = Regexp.last_match
192
248
 
193
- return false unless yaml
249
+ key = m[2] || nil
194
250
 
195
- if m[2]
196
- value1 = yaml[m[2]]
197
- return false if value1.nil?
251
+ content = IO.read(@env[:filepath]).force_encoding('utf-8')
198
252
 
199
- value1 = value1.join(',') if value1.is_a?(Array)
200
- if %i[type_of not_type_of].include?(operator)
201
- test_type(value1, value, operator)
202
- elsif value1.bool?
203
- test_truthy(value1, value, operator)
204
- elsif value1.number? && value2.number? && %i[gt lt equal not_equal].include?(operator)
205
- test_operator(value1, value, operator)
206
- else
207
- test_string(value1, value, operator)
208
- end
209
- else
210
- res = value? ? yaml.key?(value) : true
211
- operator == :not_equal ? !res : res
212
- end
253
+ content.meta? ? test_meta(content, value, key, operator) : false
213
254
  else
214
255
  false
215
256
  end
@@ -42,6 +42,14 @@ class ::String
42
42
  dup.force_encoding('utf-8').match(/^(?:y(?:es)?|no?|t(?:rue)?|f(?:alse)?)$/) ? true : false
43
43
  end
44
44
 
45
+ def meta?
46
+ self =~ /^---/m
47
+ end
48
+
49
+ def yaml?
50
+ self =~ /^\w+: +\S+/m
51
+ end
52
+
45
53
  def to_bool!
46
54
  replace to_bool
47
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conductor
4
- VERSION = '1.0.6'
4
+ VERSION = '1.0.7'
5
5
  end
data/src/_README.md CHANGED
@@ -82,6 +82,7 @@ Available conditions are:
82
82
  - If the YAML key is a date, it can be tested against with `before`, `after`, and `is`, and the value can be a natural language date, e.g. `yaml:date is after may 3, 2024`
83
83
  - 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.
84
84
  - If the YAML value is a boolean, you can test with `is true` or `is not true` (or `is false`)
85
+ - `mmd` or `meta` will test for MultiMarkdown metadata using the same formatting as `yaml`.
85
86
  - 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:
86
87
  - `any`
87
88
  - `else`
@@ -116,8 +117,9 @@ A script run by Conductor already knows it has the right type of file with the e
116
117
 
117
118
  ## Tips
118
119
 
120
+ - Config file must be valid YAML. Any value containing colons, brackets, or other special characters should be quoted, e.g. (`condition: "text contains my:text"`)
119
121
  - You can see what condition matched in Marked by opening <b>Help->Show Custom Processor Log</b> and checking the STDERR output.
120
- - To run [a custom processor for Bear](https://brettterpstra.com/2023/10/08/marked-and-bear/), use the condition `text contains /source: *bear/`
122
+ - To run [a custom processor for Bear](https://brettterpstra.com/2023/10/08/marked-and-bear/), use the condition `"text contains <!-- source: bear.app -->"`
121
123
  - To run a custom processor for Obsidian, use the condition `tree contains .obsidian`
122
124
 
123
125
  ## Testing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marked-conductor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra