marked-conductor 1.0.5 → 1.0.6

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: c6a0da9f71e766f19edb6cb13fc27139af3934f3cdf013b0c51164cc3b20d73f
4
- data.tar.gz: a0d4c8b2d37653632d8757f0704008fbc370a6edcc89c46e9f1eac8927cab9e7
3
+ metadata.gz: 684cf7a82ae4cce7240617f832ce52572b0373e578aaff487fbc50b47e2f5afd
4
+ data.tar.gz: a6c5a9db2ee07216abd703f9ca833e4f83110b19eeba0ad993327ad2ef963623
5
5
  SHA512:
6
- metadata.gz: 5ccaa5df5811bf5433bea16f2ddc5b71c056592250b0757d83119e998a65426eaeb04e291f3b758bc0e74e64b1a6f58bcbcb59ed7a9eccdf5e58dfe26e474886
7
- data.tar.gz: 340f3e73ff68f7026f169cc6c686de8dcd6651836c6b685e886e5a3c115f17b676ea889565929a6ec778ad017b914c0c796ac4e8b724fc8808288535bf5da54d
6
+ metadata.gz: e47df55cfed559207ddf931b2c08b98cae32709534d2b612b6b94afd3bee3b79342a7c4dc558ca4eefc77a6e894c0e8d37bb09358275fa260c2ccaffac480235
7
+ data.tar.gz: 077e24abc630b9588671e2eb8b3af7736f88299063e76b5176b84b681690c81eb89532057121a795ce2c50fcf34ad3c4356f298064186e156c778f2f9fdb7184
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
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
+
1
11
  ### 1.0.5
2
12
 
3
13
  2024-04-25 17:00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- marked-conductor (0.1.0)
4
+ marked-conductor (1.0.5)
5
5
  chronic (~> 0.10.2)
6
6
  tty-which (~> 0.5.0)
7
7
 
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
 
@@ -150,7 +150,7 @@ module Conductor
150
150
  end
151
151
 
152
152
  def test_truthy(value1, value2, operator)
153
- return false unless value2.bool?
153
+ return false unless value2&.bool?
154
154
 
155
155
  value2 = value2.to_bool if value2.is_a?(String)
156
156
 
@@ -177,21 +177,25 @@ module Conductor
177
177
  when /^tree/i
178
178
  test_tree(@env[:origin], value, operator)
179
179
  when /^(path|dir)/i
180
- test_string(@env[:origin], value, operator) ? true : false
180
+ test_string(@env[:filepath], value, operator) ? true : false
181
181
  when /^phase/i
182
182
  test_string(@env[:phase], value, :starts_with) ? true : false
183
183
  when /^text/i
184
- test_string(IO.read(@env[:filepath]), value, operator) ? true : false
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
185
186
  when /^(yaml|headers|frontmatter)(?::(.*?))?$/i
186
187
  m = Regexp.last_match
187
188
  content = IO.read(@env[:filepath]).force_encoding('utf-8')
188
- return false unless content =~ /^---/
189
+ return false unless content =~ /^---/m
189
190
 
190
191
  yaml = YAML.safe_load(content.split(/^(?:---|\.\.\.)/)[1])
191
192
 
192
193
  return false unless yaml
194
+
193
195
  if m[2]
194
196
  value1 = yaml[m[2]]
197
+ return false if value1.nil?
198
+
195
199
  value1 = value1.join(',') if value1.is_a?(Array)
196
200
  if %i[type_of not_type_of].include?(operator)
197
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/Dropbox/Writing/brettterpstra.com/_drafts/',
32
- filepath: '/Users/ttscoff/Dropbox/Writing/brettterpstra.com/_drafts/marked-2-and-obsidian.md',
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/'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conductor
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
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
- @stdin ||= $stdin.read.strip.force_encoding('utf-8') if $stdin.stat.size.positive? || $stdin.fcntl(Fcntl::F_GETFL, 0).zero?
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.5
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-25 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry