marked-conductor 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -3
- data/bin/conductor +20 -0
- data/lib/conductor/condition.rb +18 -12
- data/lib/conductor/env.rb +2 -2
- data/lib/conductor/string.rb +5 -5
- data/lib/conductor/version.rb +1 -1
- data/lib/conductor.rb +3 -1
- data/src/_README.md +9 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 684cf7a82ae4cce7240617f832ce52572b0373e578aaff487fbc50b47e2f5afd
|
4
|
+
data.tar.gz: a6c5a9db2ee07216abd703f9ca833e4f83110b19eeba0ad993327ad2ef963623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e47df55cfed559207ddf931b2c08b98cae32709534d2b612b6b94afd3bee3b79342a7c4dc558ca4eefc77a6e894c0e8d37bb09358275fa260c2ccaffac480235
|
7
|
+
data.tar.gz: 077e24abc630b9588671e2eb8b3af7736f88299063e76b5176b84b681690c81eb89532057121a795ce2c50fcf34ad3c4356f298064186e156c778f2f9fdb7184
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
### 1.0.6
|
2
|
+
|
3
|
+
2024-04-26 11:17
|
4
|
+
|
5
|
+
#### FIXED
|
6
|
+
|
7
|
+
- Always wait for STDIN or Marked will crash. Still possible to use $file in script/command values
|
8
|
+
- More string encoding fixes
|
9
|
+
- "path contains" was returning $PATH instead of the filepath
|
10
|
+
|
11
|
+
### 1.0.5
|
12
|
+
|
13
|
+
2024-04-25 17:00
|
14
|
+
|
15
|
+
#### FIXED
|
16
|
+
|
17
|
+
- First-run config creating directory instead of file
|
18
|
+
- Frozen string/encoding issue on string comparisons
|
19
|
+
|
1
20
|
### 1.0.3
|
2
21
|
|
3
22
|
2024-04-25 14:32
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,7 +38,7 @@ The top level key in the YAML file is `tracks:`. This is an array of hashes, eac
|
|
38
38
|
|
39
39
|
A simple config would look like:
|
40
40
|
|
41
|
-
```
|
41
|
+
```yaml
|
42
42
|
tracks:
|
43
43
|
- condition: yaml includes comments
|
44
44
|
script: blog-processor
|
@@ -52,7 +52,7 @@ Instead of a `script` or `command`, a track can contain another `tracks` key, in
|
|
52
52
|
|
53
53
|
For example, the following functions the same as `condition: phase is pre AND tree contains .obsidian AND (extension is md or extension is markdown)`:
|
54
54
|
|
55
|
-
```
|
55
|
+
```yaml
|
56
56
|
tracks:
|
57
57
|
- condition: phase is pre
|
58
58
|
tracks:
|
@@ -70,7 +70,7 @@ Available conditions are:
|
|
70
70
|
|
71
71
|
- `extension` (or `ext`): This will test the extension of the file, e.g. `ext is md` or `ext contains task`
|
72
72
|
- `tree contains ...`: This will test whether a given file or directory exists in any of the parent folders of the current file, starting with the current directory of the file. Example: `tree contains .obsidian` would test whether there was an `.obsidian` directory in any of the directories above the file (indicating it's within an Obsidian vault)
|
73
|
-
- `path`: This tests just the path itself, allowing conditions like `path contains _drafts` or `path does not contain _posts`.
|
73
|
+
- `path`: This tests just the path to the file itself, allowing conditions like `path contains _drafts` or `path does not contain _posts`.
|
74
74
|
- `phase`: Tests whether Marked is in Preprocessor or Processor phase, allowing conditions like `phase is preprocess` or `phase is process` (which can be shortened to `pre` and `pro`).
|
75
75
|
- `text`: This tests for any string match within the text of the document being processed. This can be used with operators `starts with`, `ends with`, or `contains`, e.g. `text contains @taskpaper` or `text does not contain <!--more-->`.
|
76
76
|
- If the test value is surrounded by forward slashes, it will be treated as a regular expression. Regexes are always flagged as case insensitive. Use it like `text contains /@\w+/`.
|
@@ -114,6 +114,12 @@ All of the [capabilities and requirements](https://marked2app.com/help/Custom_Pr
|
|
114
114
|
|
115
115
|
A script run by Conductor already knows it has the right type of file with the expected data and path, so your script can focus on just processing one file type. It's recommended to separate all of that logic you may already have written out into separate scripts and let Conductor handle the forking based on various criteria.
|
116
116
|
|
117
|
+
## Tips
|
118
|
+
|
119
|
+
- 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/`
|
121
|
+
- To run a custom processor for Obsidian, use the condition `tree contains .obsidian`
|
122
|
+
|
117
123
|
## Testing
|
118
124
|
|
119
125
|
In order to test from the command line, you'll need certain environment variables set. This can be done by exporting the following variables with your own definitions, or by running conductor with all of the variables preceding the command, e.g. `$ MARKED_ORIGIN=/path/to/markdown_file.md [...] conductor`.
|
data/bin/conductor
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require_relative '../lib/conductor'
|
5
|
+
require 'optparse'
|
5
6
|
|
6
7
|
# raise 'No input on STDIN' unless Conductor.stdin
|
7
8
|
|
@@ -9,6 +10,8 @@ include Conductor
|
|
9
10
|
|
10
11
|
config = Config.new
|
11
12
|
|
13
|
+
stdin = Conductor.stdin
|
14
|
+
|
12
15
|
def conduct(tracks, res = nil, condition = nil)
|
13
16
|
tracks.each do |track|
|
14
17
|
cond = Condition.new(track[:condition])
|
@@ -41,6 +44,23 @@ def conduct(tracks, res = nil, condition = nil)
|
|
41
44
|
[res, condition]
|
42
45
|
end
|
43
46
|
|
47
|
+
options = {}
|
48
|
+
optparse = OptionParser.new do|opts|
|
49
|
+
opts.banner = "Called from Marked 2 as a Custom Pre/Processor"
|
50
|
+
|
51
|
+
opts.on('-v', '--version', 'Show version number') do
|
52
|
+
puts "conductor v#{Conductor::VERSION}"
|
53
|
+
Process.exit 0
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('-h', '--help', 'Display this screen') do
|
57
|
+
puts opts
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
optparse.parse!
|
63
|
+
|
44
64
|
tracks = config.tracks
|
45
65
|
res, condition = conduct(tracks)
|
46
66
|
|
data/lib/conductor/condition.rb
CHANGED
@@ -85,6 +85,8 @@ module Conductor
|
|
85
85
|
|
86
86
|
return operator == :not_equal if val1.nil?
|
87
87
|
|
88
|
+
val2 = val2.force_encoding('utf-8')
|
89
|
+
|
88
90
|
if val1.date?
|
89
91
|
if val2.time?
|
90
92
|
date1 = val1.to_date
|
@@ -112,22 +114,22 @@ module Conductor
|
|
112
114
|
else
|
113
115
|
Regexp.escape(val2)
|
114
116
|
end
|
115
|
-
|
117
|
+
val1 = val1.dup.to_s.force_encoding('utf-8')
|
116
118
|
case operator
|
117
119
|
when :contains
|
118
|
-
val1
|
120
|
+
val1 =~ /#{val2}/i
|
119
121
|
when :not_starts_with
|
120
|
-
val1
|
122
|
+
val1 !~ /^#{val2}/i
|
121
123
|
when :not_ends_with
|
122
|
-
val1
|
124
|
+
val1 !~ /#{val2}$/i
|
123
125
|
when :starts_with
|
124
|
-
val1
|
126
|
+
val1 =~ /^#{val2}/i
|
125
127
|
when :ends_with
|
126
|
-
val1
|
128
|
+
val1 =~ /#{val2}$/i
|
127
129
|
when :equal
|
128
|
-
val1
|
130
|
+
val1 =~ /^#{val2}$/i
|
129
131
|
when :not_equal
|
130
|
-
val1
|
132
|
+
val1 !~ /^#{val2}$/i
|
131
133
|
else
|
132
134
|
false
|
133
135
|
end
|
@@ -148,7 +150,7 @@ module Conductor
|
|
148
150
|
end
|
149
151
|
|
150
152
|
def test_truthy(value1, value2, operator)
|
151
|
-
return false unless value2
|
153
|
+
return false unless value2&.bool?
|
152
154
|
|
153
155
|
value2 = value2.to_bool if value2.is_a?(String)
|
154
156
|
|
@@ -175,21 +177,25 @@ module Conductor
|
|
175
177
|
when /^tree/i
|
176
178
|
test_tree(@env[:origin], value, operator)
|
177
179
|
when /^(path|dir)/i
|
178
|
-
test_string(@env[:
|
180
|
+
test_string(@env[:filepath], value, operator) ? true : false
|
179
181
|
when /^phase/i
|
180
182
|
test_string(@env[:phase], value, :starts_with) ? true : false
|
181
183
|
when /^text/i
|
182
|
-
|
184
|
+
puts IO.read(@env[:filepath]).force_encoding('utf-8')
|
185
|
+
test_string(IO.read(@env[:filepath]).force_encoding('utf-8'), value, operator) ? true : false
|
183
186
|
when /^(yaml|headers|frontmatter)(?::(.*?))?$/i
|
184
187
|
m = Regexp.last_match
|
185
188
|
content = IO.read(@env[:filepath]).force_encoding('utf-8')
|
186
|
-
return false unless content =~ /^---/
|
189
|
+
return false unless content =~ /^---/m
|
187
190
|
|
188
191
|
yaml = YAML.safe_load(content.split(/^(?:---|\.\.\.)/)[1])
|
189
192
|
|
190
193
|
return false unless yaml
|
194
|
+
|
191
195
|
if m[2]
|
192
196
|
value1 = yaml[m[2]]
|
197
|
+
return false if value1.nil?
|
198
|
+
|
193
199
|
value1 = value1.join(',') if value1.is_a?(Array)
|
194
200
|
if %i[type_of not_type_of].include?(operator)
|
195
201
|
test_type(value1, value, operator)
|
data/lib/conductor/env.rb
CHANGED
@@ -28,8 +28,8 @@ module Conductor
|
|
28
28
|
css_path: '/Applications/Marked 2.app/Contents/Resources/swiss.css',
|
29
29
|
ext: 'md',
|
30
30
|
includes: [],
|
31
|
-
origin: '/Users/ttscoff/
|
32
|
-
filepath: '/Users/ttscoff/
|
31
|
+
origin: '/Users/ttscoff/Desktop/Code/marked-conductor/',
|
32
|
+
filepath: '/Users/ttscoff/Desktop/Code/marked-conductor/README.md',
|
33
33
|
phase: 'PREPROCESS',
|
34
34
|
outline: 'NONE',
|
35
35
|
path: '/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/ttscoff/Dropbox/Writing/brettterpstra.com/_drafts/'
|
data/lib/conductor/string.rb
CHANGED
@@ -14,19 +14,19 @@ class ::String
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def date?
|
17
|
-
match(/^\d{4}-\d{2}-\d{2}/) ? true : false
|
17
|
+
dup.force_encoding('utf-8').match(/^\d{4}-\d{2}-\d{2}/) ? true : false
|
18
18
|
end
|
19
19
|
|
20
20
|
def time?
|
21
|
-
match(/ \d{1,2}(:\d\d)? *([ap]m)?/i)
|
21
|
+
dup.force_encoding('utf-8').match(/ \d{1,2}(:\d\d)? *([ap]m)?/i)
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_date
|
25
|
-
Chronic.parse(self)
|
25
|
+
Chronic.parse(self.dup.force_encoding('utf-8'))
|
26
26
|
end
|
27
27
|
|
28
28
|
def strip_time
|
29
|
-
sub(/ \d{1,2}(:\d\d)? *([ap]m)?/i, '')
|
29
|
+
dup.force_encoding('utf-8').sub(/ \d{1,2}(:\d\d)? *([ap]m)?/i, '')
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_day(time = :end)
|
@@ -39,7 +39,7 @@ class ::String
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def bool?
|
42
|
-
match(/^(?:y(?:es)?|no?|t(?:rue)?|f(?:alse)?)$/) ? true : false
|
42
|
+
dup.force_encoding('utf-8').match(/^(?:y(?:es)?|no?|t(?:rue)?|f(?:alse)?)$/) ? true : false
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_bool!
|
data/lib/conductor/version.rb
CHANGED
data/lib/conductor.rb
CHANGED
@@ -7,6 +7,7 @@ require 'fcntl'
|
|
7
7
|
require 'time'
|
8
8
|
require 'chronic'
|
9
9
|
require 'fileutils'
|
10
|
+
require_relative 'conductor/version'
|
10
11
|
require_relative 'conductor/env'
|
11
12
|
require_relative 'conductor/config'
|
12
13
|
require_relative 'conductor/hash'
|
@@ -20,7 +21,8 @@ require_relative 'conductor/condition'
|
|
20
21
|
module Conductor
|
21
22
|
class << self
|
22
23
|
def stdin
|
23
|
-
|
24
|
+
warn 'input on STDIN required' unless $stdin.stat.size.positive? || $stdin.fcntl(Fcntl::F_GETFL, 0).zero?
|
25
|
+
@stdin ||= $stdin.read.strip.force_encoding('utf-8')
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/src/_README.md
CHANGED
@@ -38,7 +38,7 @@ The top level key in the YAML file is `tracks:`. This is an array of hashes, eac
|
|
38
38
|
|
39
39
|
A simple config would look like:
|
40
40
|
|
41
|
-
```
|
41
|
+
```yaml
|
42
42
|
tracks:
|
43
43
|
- condition: yaml includes comments
|
44
44
|
script: blog-processor
|
@@ -52,7 +52,7 @@ Instead of a `script` or `command`, a track can contain another `tracks` key, in
|
|
52
52
|
|
53
53
|
For example, the following functions the same as `condition: phase is pre AND tree contains .obsidian AND (extension is md or extension is markdown)`:
|
54
54
|
|
55
|
-
```
|
55
|
+
```yaml
|
56
56
|
tracks:
|
57
57
|
- condition: phase is pre
|
58
58
|
tracks:
|
@@ -70,7 +70,7 @@ Available conditions are:
|
|
70
70
|
|
71
71
|
- `extension` (or `ext`): This will test the extension of the file, e.g. `ext is md` or `ext contains task`
|
72
72
|
- `tree contains ...`: This will test whether a given file or directory exists in any of the parent folders of the current file, starting with the current directory of the file. Example: `tree contains .obsidian` would test whether there was an `.obsidian` directory in any of the directories above the file (indicating it's within an Obsidian vault)
|
73
|
-
- `path`: This tests just the path itself, allowing conditions like `path contains _drafts` or `path does not contain _posts`.
|
73
|
+
- `path`: This tests just the path to the file itself, allowing conditions like `path contains _drafts` or `path does not contain _posts`.
|
74
74
|
- `phase`: Tests whether Marked is in Preprocessor or Processor phase, allowing conditions like `phase is preprocess` or `phase is process` (which can be shortened to `pre` and `pro`).
|
75
75
|
- `text`: This tests for any string match within the text of the document being processed. This can be used with operators `starts with`, `ends with`, or `contains`, e.g. `text contains @taskpaper` or `text does not contain <!--more-->`.
|
76
76
|
- If the test value is surrounded by forward slashes, it will be treated as a regular expression. Regexes are always flagged as case insensitive. Use it like `text contains /@\w+/`.
|
@@ -114,6 +114,12 @@ All of the [capabilities and requirements](https://marked2app.com/help/Custom_Pr
|
|
114
114
|
|
115
115
|
A script run by Conductor already knows it has the right type of file with the expected data and path, so your script can focus on just processing one file type. It's recommended to separate all of that logic you may already have written out into separate scripts and let Conductor handle the forking based on various criteria.
|
116
116
|
|
117
|
+
## Tips
|
118
|
+
|
119
|
+
- 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/`
|
121
|
+
- To run a custom processor for Obsidian, use the condition `tree contains .obsidian`
|
122
|
+
|
117
123
|
## Testing
|
118
124
|
|
119
125
|
In order to test from the command line, you'll need certain environment variables set. This can be done by exporting the following variables with your own definitions, or by running conductor with all of the variables preceding the command, e.g. `$ MARKED_ORIGIN=/path/to/markdown_file.md [...] conductor`.
|
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.
|
4
|
+
version: 1.0.6
|
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-04-
|
11
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|