marked-conductor 1.0.12 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/src/_README.md CHANGED
@@ -23,7 +23,7 @@ If you use Homebrew, you can run
23
23
 
24
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
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.
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 **Marked Preferences > Advanced** and select either Custom Processor or Custom Preprocessor (or both) and paste into the **Path:** field. You can select *Automatically enable for new windows* to have the processor enabled by default when opening documents.
27
27
 
28
28
  <!--JEKYLL {% img aligncenter /uploads/2024/04/marked-preferences-conductor.jpg 593 673 "marked-preferences-conductor.jpg" %}-->
29
29
  <!--GITHUB-->![Marked preferences](images/preferences.jpg)<!--END GITHUB-->
@@ -122,13 +122,45 @@ Conditions can be combined with AND or OR (must be uppercase) and simple parenth
122
122
 
123
123
  ### Actions
124
124
 
125
- The action can be either `script` or `command`.
125
+ The action can be `script`, `command`, or `filter`.
126
126
 
127
- 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.
127
+ **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.
128
128
 
129
- 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.
129
+ > Example:
130
+ >
131
+ > script: github_pre
130
132
 
131
- 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.
133
+ **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.
134
+
135
+ > Example:
136
+ >
137
+ > command: multimarkdown
138
+
139
+
140
+ > 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.
141
+
142
+ **Filters** are simple actions that can be run on the content without having to write a separate script for it. Available filters are:
143
+ | filter | description |
144
+ | :---- | :---------- |
145
+ | `setMeta(key, value)` | adds or updates a meta key, aware of YAML and MMD |
146
+ | `stripMeta` | strips all metadata (YAML or MMD) from the content |
147
+ | `stripMeta(key)` | removes a specific key (YAML or MMD) |
148
+ | `setStyle(name)` | sets the Marked preview style to a preconfigured Style name
149
+ | `replace(search, replace)` | performs a (single) search and replace on content |
150
+ | `replaceAll(search, replace)` | global version of `replaceAll`) |
151
+ | `insertTitle` | adds a title to the document, either from metadata or filename |
152
+ | `insertScript(path[,path])` | injects javascript(s) |
153
+
154
+ For `insertScript`, if path is just a filename it will look for a match in `~/.config/conductor/javascript` or `~/.config/conductor/scripts` and turn that into an absolute path if the file is found.
155
+
156
+ For `replace` and `replaceAll`: If *search* is surrounded with forward slashes followed by optional flags (*i* for case-insensitive, *m* to make dot match newlines), e.g. `/contribut(ing)?/i`, it will be interpreted as a regular expression. The *replace* value can include numeric capture groups, e.g. `Follow$2`.
157
+
158
+ > Example:
159
+ >
160
+ > filter: setStyle(github)
161
+
162
+
163
+ > Filters can be camel case (replaceAll) or snake case (replace_all), either will work, case insensitive.
132
164
 
133
165
  ## Custom Processors
134
166
 
@@ -142,8 +174,8 @@ A script run by Conductor already knows it has the right type of file with the e
142
174
  ## Tips
143
175
 
144
176
  - 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"`)
145
- - You can see what condition matched in Marked by opening <b>Help->Show Custom Processor Log</b> and checking the STDERR output.
146
- - To run [a custom processor for Bear](https://brettterpstra.com/2023/10/08/marked-and-bear/), use the condition `"text contains <!-- source: bear.app -->"`
177
+ - You can see what condition matched in Marked by opening **Help->Show Custom Processor Log** and checking the STDERR output.
178
+ - To run [a custom processor for Bear](https://brettterpstra.com/2023/10/08/marked-and-bear/), use the condition `"text contains <!-- source: bear.app -->"`. You might consider running a commonmark CLI with Bear to support more of its syntax.
147
179
  - To run a custom processor for Obsidian, use the condition `tree contains .obsidian`
148
180
 
149
181
  ## Testing
@@ -154,6 +186,8 @@ In Marked's Custom Processor Log, you can see both the STDOUT output and the STD
154
186
 
155
187
  ### From the command line
156
188
 
189
+ > There's a script included in the repo called [test.sh](https://github.com/ttscoff/marked-conductor/blob/main/test.sh) that will take a file path as an argument and set all of the environment variables for testing. Run `test.sh -h` for usage instructions.
190
+
157
191
  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`.
158
192
 
159
193
  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.
data/test.sh ADDED
@@ -0,0 +1,83 @@
1
+ #!/bin/bash
2
+
3
+ # ./test.sh PATH [pr[eo]]
4
+
5
+ OPTIND=1 # Reset in case getopts has been used previously in the shell.
6
+
7
+ # Initialize our own variables:
8
+ output_file=""
9
+ verbose=0
10
+
11
+ show_help() {
12
+ echo "$(basename $0): Shortcut for testing conductor with a given file"
13
+ echo "Options:"
14
+ echo " -p [pre|pro] (run as preprocessor(*) or processor)"
15
+ echo " -o [err|out] (output stderr, stdout, both(*))"
16
+ echo " -d (debug, only show stderr)"
17
+ echo "Usage:"
18
+ echo " $0 [-p PHASE] [-o OUTPUT] FILE_PATH"
19
+ }
20
+
21
+ if [[ -d bin ]]; then
22
+ CMD="./bin/conductor"
23
+ else
24
+ CMD="$(which conductor)"
25
+ fi
26
+
27
+ PHASE="PREPROCESS"
28
+ STD="BOTH"
29
+
30
+ while getopts "h?p:o:d" opt; do
31
+ case "$opt" in
32
+ h|\?)
33
+ show_help
34
+ exit 0
35
+ ;;
36
+ p) PHASE=$OPTARG
37
+ ;;
38
+ o) STD=$OPTARG
39
+ ;;
40
+ d)
41
+ STD="ERR"
42
+ ;;
43
+ esac
44
+ done
45
+
46
+ shift $((OPTIND-1))
47
+
48
+ [ "${1:-}" = "--" ] && shift
49
+
50
+ if [[ -z $1 ]]; then
51
+ show_help
52
+ exit 1
53
+ fi
54
+
55
+ FILE=$(realpath $1)
56
+ FILENAME=$(basename -- "$FILE")
57
+ EXTENSION="${FILENAME##*.}"
58
+ PHASE=$(echo $PHASE | tr [a-z] [A-Z])
59
+ STD=$(echo $STD | tr [a-z] [A-Z])
60
+
61
+ if [[ $PHASE =~ ^PRE ]]; then
62
+ PHASE="PREPROCESS"
63
+ else
64
+ PHASE="PROCESS"
65
+ fi
66
+
67
+ export OUTLINE="NONE"
68
+ export MARKED_ORIGIN="$FILE"
69
+ export MARKED_EXT="$EXTENSION"
70
+ export MARKED_CSS_PATH="/Applications/Marked 2.app/Contents/Resources/swiss.css"
71
+ export PATH="$PATH:$(dirname "$FILE")"
72
+ export MARKED_PATH="$FILE"
73
+ export MARKED_INCLUDES=""
74
+ export MARKED_PHASE="$PHASE"
75
+
76
+ if [[ $STD =~ ^(STD)?E ]]; then
77
+ command cat "$FILE" | $CMD 1>/dev/null
78
+ elif [[ $STD =~ ^(STD)?O ]]; then
79
+ command cat "$FILE" | $CMD 2>/dev/null
80
+ else
81
+ command cat "$FILE" | $CMD
82
+ fi
83
+
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.12
4
+ version: 1.0.14
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-05-01 00:00:00.000000000 Z
11
+ date: 2024-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -212,6 +212,7 @@ files:
212
212
  - html/Conductor/Env.html
213
213
  - html/Conductor/Script.html
214
214
  - html/FalseClass.html
215
+ - html/Filter.html
215
216
  - html/Hash.html
216
217
  - html/Object.html
217
218
  - html/README_rdoc.html
@@ -269,12 +270,14 @@ files:
269
270
  - lib/conductor/condition.rb
270
271
  - lib/conductor/config.rb
271
272
  - lib/conductor/env.rb
273
+ - lib/conductor/filter.rb
272
274
  - lib/conductor/hash.rb
273
275
  - lib/conductor/script.rb
274
276
  - lib/conductor/string.rb
275
277
  - lib/conductor/version.rb
276
278
  - marked-conductor.gemspec
277
279
  - src/_README.md
280
+ - test.sh
278
281
  homepage: https://github.com/ttscoff/marked-conductor
279
282
  licenses:
280
283
  - MIT