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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +3 -1
- data/lib/conductor/command.rb +0 -1
- data/lib/conductor/condition.rb +62 -21
- data/lib/conductor/string.rb +8 -0
- data/lib/conductor/version.rb +1 -1
- data/src/_README.md +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b5faacd380f833b615f2f848ed6f0bcb54dd955082b71228ab4f49c9e2bf0ac
|
4
|
+
data.tar.gz: 7c513f2fc4f75094e99ea27c48cf545ca738abe366271ec3da216f92ff0a4a5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c84b488b4cc93effd14039e59be3ea76ce4d8e0c5ab882ceb542e93d158fb82d11b5f46bfcd60d5942a265d6554107fa964bb8acafe2d9ced9e8302ea7eb10a6
|
7
|
+
data.tar.gz: 7e80a80708878d3ab4dbc515d5554c77af6bdd42b8ceb496c2b16bb48b054ea8696aa57351eeae0a35adb3de00ef2dce6c509e77c850aa8ebb4a71c2d672a4f2
|
data/CHANGELOG.md
CHANGED
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
|
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
|
data/lib/conductor/command.rb
CHANGED
data/lib/conductor/condition.rb
CHANGED
@@ -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
|
245
|
+
content.yaml? ? test_yaml(content, value, key, operator) : false
|
246
|
+
when /^(mmd|meta(?:data)?)(?::(.*?))?$/i
|
247
|
+
m = Regexp.last_match
|
192
248
|
|
193
|
-
|
249
|
+
key = m[2] || nil
|
194
250
|
|
195
|
-
|
196
|
-
value1 = yaml[m[2]]
|
197
|
-
return false if value1.nil?
|
251
|
+
content = IO.read(@env[:filepath]).force_encoding('utf-8')
|
198
252
|
|
199
|
-
|
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
|
data/lib/conductor/string.rb
CHANGED
@@ -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
|
data/lib/conductor/version.rb
CHANGED
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
|
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
|