marked-conductor 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.irbrc +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +145 -0
- data/Rakefile +57 -0
- data/bin/conductor +54 -0
- data/images/preferences.jpg +0 -0
- data/lib/conductor/array.rb +12 -0
- data/lib/conductor/command.rb +53 -0
- data/lib/conductor/condition.rb +248 -0
- data/lib/conductor/config.rb +47 -0
- data/lib/conductor/env.rb +54 -0
- data/lib/conductor/hash.rb +11 -0
- data/lib/conductor/script.rb +59 -0
- data/lib/conductor/string.rb +62 -0
- data/lib/conductor/version.rb +5 -0
- data/lib/conductor.rb +25 -0
- data/marked-conductor.gemspec +40 -0
- data/src/_README.md +147 -0
- metadata +127 -0
data/src/_README.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
<!--README-->
|
2
|
+
[![RubyGems.org](https://img.shields.io/gem/v/journal-cli)](https://rubygems.org/gems/journal-cli)
|
3
|
+
|
4
|
+
# Marked Conductor
|
5
|
+
|
6
|
+
A "train conductor" for [Marked 2](https://marked2app.com). Conductor can be set up as a Custom Preprocessor or Custom Processor for Marked, and can run different commands and scripts based on conditions in a YAML configuration file, allowing you to have multiple processors that run based on predicates.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
$ gem install marked-conductor
|
11
|
+
|
12
|
+
If you run into errors, try running with the `--user-install` flag:
|
13
|
+
|
14
|
+
$ gem install --user-install marked-conductor
|
15
|
+
|
16
|
+
> I've noticed lately with `asdf` that I have to run `asdf reshim` after installing gems containing binaries.
|
17
|
+
|
18
|
+
If you use Homebrew, you can run
|
19
|
+
|
20
|
+
$ brew gem install marked-conductor
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
To use Conductor, you need to set up a configuration file in `~/.config/conductor/tracks.yaml`. Run `conductor` once to create the directory and an empty configuration. See [Configuration](#configuration) below for details on setting up your "tracks."
|
25
|
+
|
26
|
+
Once configured, you can set up conductor as a Custom Processor in Marked. Run `which conductor | pbcopy` to get the full path to the binary and copy it, then open <b>Marked Preferences > Advanced</b> and select either Custom Processor or Custom Preprocessor (or both) and paste into the <b>Path:</b> field. You can select <i>Automatically enable for new windows</i> to have the processor enabled by default when opening documents.
|
27
|
+
|
28
|
+
<!--JEKYLL {% img aligncenter /uploads/2024/04/marked-preferences-conductor.jpg 593 673 "marked-preferences-conductor.jpg" %}-->
|
29
|
+
<!--GITHUB-->![Marked preferences](images/preferences.jpg)<!--END GITHUB-->
|
30
|
+
|
31
|
+
Conductor requires that it be run from Marked 2, and won't function on the command line. This is because Marked defines special environment variables that can be used in scripts, and these won't exist when running from your shell. If you want to be able to test Conductor from the command line, see [Testing](#testing).
|
32
|
+
|
33
|
+
## Configuration
|
34
|
+
|
35
|
+
Configuration is done in a YAML file located at `~/.config/conductor/tracks.yaml`. Run `conductor` from the command line to generate the necessary directories and sample config file if it doesn't already exist.
|
36
|
+
|
37
|
+
The top level key in the YAML file is `tracks:`. This is an array of hashes, each hash containing a `condition` and either a `script` or `command` key.
|
38
|
+
|
39
|
+
A simple config would look like:
|
40
|
+
|
41
|
+
```
|
42
|
+
tracks:
|
43
|
+
- condition: yaml includes comments
|
44
|
+
script: blog-processor
|
45
|
+
- condition: any
|
46
|
+
command: echo 'NOCUSTOM'
|
47
|
+
```
|
48
|
+
|
49
|
+
This would run a script at `~/.config/conductor/scripts/blog-processor` if there was YAML present in the document and it included a key called `comments`. If not, the `condition: any` would echo `NOCUSTOM` to Marked, indicating it should skip any Custom Processor. If no condition is met, NOCUSTOM is automatically sent, so this particular example is redundant. In practice you would include a catchall processor to act as the default if no prior conditions were met.
|
50
|
+
|
51
|
+
Instead of a `script` or `command`, a track can contain another `tracks` key, in which case the parent condition will branch and it will cycle through the tracks contained in the `tracks` key for the hash. `tracks` keys can be repeatedly nested to create AND conditions.
|
52
|
+
|
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
|
+
|
55
|
+
```
|
56
|
+
tracks:
|
57
|
+
- condition: phase is pre
|
58
|
+
tracks:
|
59
|
+
- condition: tree contains .obsidian
|
60
|
+
tracks:
|
61
|
+
- condition: extension is md
|
62
|
+
command: obsidian-md-filter
|
63
|
+
- condition: extension is markdown
|
64
|
+
command: obsidian-md-filter
|
65
|
+
```
|
66
|
+
|
67
|
+
### Conditions
|
68
|
+
|
69
|
+
Available conditions are:
|
70
|
+
|
71
|
+
- `extension` (or `ext`): This will test the extension of the file, e.g. `ext is md` or `ext contains task`
|
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`.
|
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
|
+
- `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
|
+
- 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 matches @\w+`.
|
77
|
+
- `yaml`, `headers`, or `frontmatter` will test for YAML headers. If a `yaml:KEY` is defined, a specific YAML key will be tested for. If a value is defined with an operator, it will be tested against the value key.
|
78
|
+
- `yaml` tests for the presence of YAML frontmatter.
|
79
|
+
- `yaml:comments` tests for the presence of a `comments` key.
|
80
|
+
- `yaml:comments is true` tests whether `comments: true` exists.
|
81
|
+
- `yaml:tags contains appreview` will test whether the tags array contains `appreview`.
|
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
|
+
- 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
|
+
- If the YAML value is a boolean, you can test with `is true` or `is not true` (or `is false`)
|
85
|
+
- 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
|
+
- `any`
|
87
|
+
- `else`
|
88
|
+
- `all`
|
89
|
+
- `true`
|
90
|
+
- `catchall`
|
91
|
+
|
92
|
+
Available comparison operators are:
|
93
|
+
|
94
|
+
- `is` or `equals` (negate with `is not` or `does not equal`) tests for equality on strings, numbers, or dates
|
95
|
+
- `contains` or `includes` (negate with `does not contain`) tests on strings or array values
|
96
|
+
- `begins with` (or `starts with`) or `ends with` (negate with `does not begin with`) tests on strings
|
97
|
+
- `greater than` or `less than` (tests on numbers or dates)
|
98
|
+
|
99
|
+
Conditions can be combined with AND or OR (must be uppercase) and simple parenthetical operations will work (parenthesis can not be nested). A boolean condition would look like `path contains _posts AND extension is md` or `(tree includes .obsidian AND extension is todo) OR extension is taskpaper`.
|
100
|
+
|
101
|
+
### Actions
|
102
|
+
|
103
|
+
The action can be either `script` or `command`.
|
104
|
+
|
105
|
+
Scripts are located in `~/.config/conductor/scripts/` and should be executable files that take input on STDIN (unless `$file` is specified in the `script` definition). If a script is defined starting with `~` or `/`, that will be interpreted as a full path to an alternate location.
|
106
|
+
|
107
|
+
Commands are interpreted as shell commands. If a command exists in the `$PATH`, a full path will automatically be determined, so a command can be as simple as just `pandoc`. Add any arguments needed after the command.
|
108
|
+
|
109
|
+
Using `$file` as an argument to a script or command will bypass processing of STDIN input, and instead use the value of $MARKED_PATH to read the contents of the specified file.
|
110
|
+
|
111
|
+
## Testing
|
112
|
+
|
113
|
+
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`.
|
114
|
+
|
115
|
+
The following need to be defined. Some can be left as empty or to defaults, such as `MARKED_INCLUDES` and `MARKED_OUTLINE`, but all need to be set to something.
|
116
|
+
|
117
|
+
```
|
118
|
+
HOME=$HOME
|
119
|
+
MARKED_CSS_PATH="" # The path to CSS, can be empty
|
120
|
+
MARKED_EXT="md" # The extension of the current file in Marked, set as needed for testing
|
121
|
+
MARKED_INCLUDES="" # Files included in the document, can be empty
|
122
|
+
MARKED_ORIGIN="/Users/ttscoff/notes/" # Base directory for the file being tested
|
123
|
+
MARKED_PATH="/Users/ttscoff/notes/markdown_file.md" # Full path to Markdown file
|
124
|
+
MARKED_PHASE="PREPROCESS" # either "PROCESS" or "PREPROCESS"
|
125
|
+
OUTLINE="none" # Outline mode, can be "none"
|
126
|
+
PATH=$PATH # The system $PATH variable
|
127
|
+
```
|
128
|
+
|
129
|
+
Further, input on STDIN is required, unless the script/command being matched contains `$file`, in which case $MARKED_PATH will be read and operated on. For the purpose of testing, you can use `echo` or `cat FILE` and pipe to conductor, e.g. `echo "TESTING" | conductor`.
|
130
|
+
|
131
|
+
To test which conditions are being met, you can just set the `command:` for a track to `echo "meaningful message"`, where the message is something that indicates which condition(s) have passed.
|
132
|
+
|
133
|
+
<!--GITHUB-->
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/ttscoff/marked-conductor>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ttscoff/marked-conductor/blob/main/CODE_OF_CONDUCT.md).
|
138
|
+
|
139
|
+
## License
|
140
|
+
|
141
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
142
|
+
|
143
|
+
## Code of Conduct
|
144
|
+
|
145
|
+
Everyone interacting in the Marked::Conductor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ttscoff/marked-conductor/blob/main/CODE_OF_CONDUCT.md).
|
146
|
+
<!--END GITHUB-->
|
147
|
+
<!--END README-->
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marked-conductor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Terpstra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_print
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.9.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.9.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-which
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chronic
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.2
|
69
|
+
description: Conductor allows easy configuration of multiple scripts that are run
|
70
|
+
as custom pre/processors for Marked based on conditional statements.
|
71
|
+
email:
|
72
|
+
- me@brettterpstra.com
|
73
|
+
executables:
|
74
|
+
- conductor
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".irbrc"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/conductor
|
88
|
+
- images/preferences.jpg
|
89
|
+
- lib/conductor.rb
|
90
|
+
- lib/conductor/array.rb
|
91
|
+
- lib/conductor/command.rb
|
92
|
+
- lib/conductor/condition.rb
|
93
|
+
- lib/conductor/config.rb
|
94
|
+
- lib/conductor/env.rb
|
95
|
+
- lib/conductor/hash.rb
|
96
|
+
- lib/conductor/script.rb
|
97
|
+
- lib/conductor/string.rb
|
98
|
+
- lib/conductor/version.rb
|
99
|
+
- marked-conductor.gemspec
|
100
|
+
- src/_README.md
|
101
|
+
homepage: https://github.com/ttscoff/marked-conductor
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata:
|
105
|
+
homepage_uri: https://github.com/ttscoff/marked-conductor
|
106
|
+
source_code_uri: https://github.com/ttscoff/marked-conductor
|
107
|
+
changelog_uri: https://github.com/ttscoff/marked-conductor/CHANGELOG.md
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 2.6.0
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubygems_version: 3.2.16
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A custom processor manager for Marked 2 (Mac)
|
127
|
+
test_files: []
|