marked-conductor 1.0.13 → 1.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +37 -5
- data/html/Filter.html +243 -0
- data/html/String.html +219 -26
- data/html/created.rid +4 -4
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/table_of_contents.html +50 -20
- data/lib/conductor/filter.rb +77 -1
- data/lib/conductor/string.rb +9 -0
- data/lib/conductor/version.rb +1 -1
- data/src/_README.md +37 -5
- metadata +3 -2
data/html/table_of_contents.html
CHANGED
@@ -103,9 +103,9 @@
|
|
103
103
|
<span class="container">Conductor::Env</span>
|
104
104
|
|
105
105
|
<li class="method">
|
106
|
-
<a href="Conductor/
|
106
|
+
<a href="Conductor/Config.html#method-c-new">::new</a>
|
107
107
|
—
|
108
|
-
<span class="container">Conductor::
|
108
|
+
<span class="container">Conductor::Config</span>
|
109
109
|
|
110
110
|
<li class="method">
|
111
111
|
<a href="Conductor/Command.html#method-c-new">::new</a>
|
@@ -118,14 +118,14 @@
|
|
118
118
|
<span class="container">Conductor::Condition</span>
|
119
119
|
|
120
120
|
<li class="method">
|
121
|
-
<a href="
|
121
|
+
<a href="Conductor/Script.html#method-c-new">::new</a>
|
122
122
|
—
|
123
|
-
<span class="container">
|
123
|
+
<span class="container">Conductor::Script</span>
|
124
124
|
|
125
125
|
<li class="method">
|
126
|
-
<a href="
|
126
|
+
<a href="Filter.html#method-c-new">::new</a>
|
127
127
|
—
|
128
|
-
<span class="container">
|
128
|
+
<span class="container">Filter</span>
|
129
129
|
|
130
130
|
<li class="method">
|
131
131
|
<a href="Conductor.html#method-c-stdin">::stdin</a>
|
@@ -153,9 +153,9 @@
|
|
153
153
|
<span class="container">String</span>
|
154
154
|
|
155
155
|
<li class="method">
|
156
|
-
<a href="
|
156
|
+
<a href="String.html#method-i-append">#append</a>
|
157
157
|
—
|
158
|
-
<span class="container">
|
158
|
+
<span class="container">String</span>
|
159
159
|
|
160
160
|
<li class="method">
|
161
161
|
<a href="Conductor/Script.html#method-i-args-3D">#args=</a>
|
@@ -163,20 +163,25 @@
|
|
163
163
|
<span class="container">Conductor::Script</span>
|
164
164
|
|
165
165
|
<li class="method">
|
166
|
-
<a href="
|
166
|
+
<a href="Conductor/Command.html#method-i-args-3D">#args=</a>
|
167
167
|
—
|
168
|
-
<span class="container">
|
168
|
+
<span class="container">Conductor::Command</span>
|
169
169
|
|
170
170
|
<li class="method">
|
171
|
-
<a href="
|
171
|
+
<a href="String.html#method-i-bool-3F">#bool?</a>
|
172
172
|
—
|
173
|
-
<span class="container">
|
173
|
+
<span class="container">String</span>
|
174
174
|
|
175
175
|
<li class="method">
|
176
176
|
<a href="FalseClass.html#method-i-bool-3F">#bool?</a>
|
177
177
|
—
|
178
178
|
<span class="container">FalseClass</span>
|
179
179
|
|
180
|
+
<li class="method">
|
181
|
+
<a href="TrueClass.html#method-i-bool-3F">#bool?</a>
|
182
|
+
—
|
183
|
+
<span class="container">TrueClass</span>
|
184
|
+
|
180
185
|
<li class="method">
|
181
186
|
<a href="String.html#method-i-bool_to_symbol">#bool_to_symbol</a>
|
182
187
|
—
|
@@ -212,11 +217,26 @@
|
|
212
217
|
—
|
213
218
|
<span class="container">String</span>
|
214
219
|
|
220
|
+
<li class="method">
|
221
|
+
<a href="String.html#method-i-get_title">#get_title</a>
|
222
|
+
—
|
223
|
+
<span class="container">String</span>
|
224
|
+
|
215
225
|
<li class="method">
|
216
226
|
<a href="String.html#method-i-has_comment-3F">#has_comment?</a>
|
217
227
|
—
|
218
228
|
<span class="container">String</span>
|
219
229
|
|
230
|
+
<li class="method">
|
231
|
+
<a href="String.html#method-i-insert_script">#insert_script</a>
|
232
|
+
—
|
233
|
+
<span class="container">String</span>
|
234
|
+
|
235
|
+
<li class="method">
|
236
|
+
<a href="String.html#method-i-insert_title">#insert_title</a>
|
237
|
+
—
|
238
|
+
<span class="container">String</span>
|
239
|
+
|
220
240
|
<li class="method">
|
221
241
|
<a href="String.html#method-i-meta-3F">#meta?</a>
|
222
242
|
—
|
@@ -278,14 +298,14 @@
|
|
278
298
|
<span class="container">String</span>
|
279
299
|
|
280
300
|
<li class="method">
|
281
|
-
<a href="Conductor/
|
301
|
+
<a href="Conductor/Command.html#method-i-run">#run</a>
|
282
302
|
—
|
283
|
-
<span class="container">Conductor::
|
303
|
+
<span class="container">Conductor::Command</span>
|
284
304
|
|
285
305
|
<li class="method">
|
286
|
-
<a href="Conductor/
|
306
|
+
<a href="Conductor/Script.html#method-i-run">#run</a>
|
287
307
|
—
|
288
|
-
<span class="container">Conductor::
|
308
|
+
<span class="container">Conductor::Script</span>
|
289
309
|
|
290
310
|
<li class="method">
|
291
311
|
<a href="Conductor.html#method-i-sample_config">#sample_config</a>
|
@@ -318,14 +338,14 @@
|
|
318
338
|
<span class="container">String</span>
|
319
339
|
|
320
340
|
<li class="method">
|
321
|
-
<a href="
|
341
|
+
<a href="Array.html#method-i-symbolize_keys">#symbolize_keys</a>
|
322
342
|
—
|
323
|
-
<span class="container">
|
343
|
+
<span class="container">Array</span>
|
324
344
|
|
325
345
|
<li class="method">
|
326
|
-
<a href="
|
346
|
+
<a href="Hash.html#method-i-symbolize_keys">#symbolize_keys</a>
|
327
347
|
—
|
328
|
-
<span class="container">
|
348
|
+
<span class="container">Hash</span>
|
329
349
|
|
330
350
|
<li class="method">
|
331
351
|
<a href="Array.html#method-i-symbolize_keys-21">#symbolize_keys!</a>
|
@@ -387,6 +407,16 @@
|
|
387
407
|
—
|
388
408
|
<span class="container">String</span>
|
389
409
|
|
410
|
+
<li class="method">
|
411
|
+
<a href="String.html#method-i-title_from_slug">#title_from_slug</a>
|
412
|
+
—
|
413
|
+
<span class="container">String</span>
|
414
|
+
|
415
|
+
<li class="method">
|
416
|
+
<a href="String.html#method-i-titleize">#titleize</a>
|
417
|
+
—
|
418
|
+
<span class="container">String</span>
|
419
|
+
|
390
420
|
<li class="method">
|
391
421
|
<a href="String.html#method-i-to_bool">#to_bool</a>
|
392
422
|
—
|
data/lib/conductor/filter.rb
CHANGED
@@ -47,6 +47,73 @@ class ::String
|
|
47
47
|
insert_point
|
48
48
|
end
|
49
49
|
|
50
|
+
def append(string)
|
51
|
+
"#{self}\n#{string}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def insert_script(path)
|
55
|
+
path.strip!
|
56
|
+
path = "#{path}.js" unless path =~ /\.js$/
|
57
|
+
|
58
|
+
if path =~ %r{^[~/]}
|
59
|
+
path = File.expand_path(path)
|
60
|
+
else
|
61
|
+
new_path = if File.directory?(File.expand_path("~/.config/conductor/javascript"))
|
62
|
+
File.expand_path("~/.config/conductor/javascript/#{path}")
|
63
|
+
elsif File.directory?(File.expand_path("~/.config/conductor/javascripts"))
|
64
|
+
File.expand_path("~/.config/conductor/javascripts/#{path}")
|
65
|
+
else
|
66
|
+
File.expand_path("~/.config/conductor/scripts/#{path}")
|
67
|
+
end
|
68
|
+
|
69
|
+
path = new_path if File.exist?(new_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
%(#{self}\n<script type="javascript" src="#{path}"></script>\n)
|
73
|
+
end
|
74
|
+
|
75
|
+
def title_from_slug
|
76
|
+
filename = File.basename(Conductor::Env.env[:filepath]).sub(/\.[a-z]+$/i, "")
|
77
|
+
filename.sub!(/-?\d{4}-\d{2}-\d{2}-?/, "")
|
78
|
+
filename.sub!(/\bdot\b/, ".")
|
79
|
+
filename.sub!(/ dash /, "-")
|
80
|
+
filename
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_title
|
84
|
+
title = nil
|
85
|
+
|
86
|
+
case meta_type
|
87
|
+
when :yaml
|
88
|
+
m = match(/^---.*?\n(---|\.\.\.)/m)
|
89
|
+
yaml = YAML.load(m[0])
|
90
|
+
title = yaml["title"]
|
91
|
+
when :mmd
|
92
|
+
split(/\n/).each do |line|
|
93
|
+
if line =~ /^ *title: *(\S.*?)$/i
|
94
|
+
title = Regexp.last_match(1)
|
95
|
+
break
|
96
|
+
end
|
97
|
+
end
|
98
|
+
else
|
99
|
+
m = match(/title: (.*?)$/i)
|
100
|
+
title = m ? m[0] : nil
|
101
|
+
end
|
102
|
+
|
103
|
+
title ||= title_from_slug.titleize
|
104
|
+
|
105
|
+
title
|
106
|
+
end
|
107
|
+
|
108
|
+
def insert_title
|
109
|
+
title = get_title
|
110
|
+
lines = split(/\n/)
|
111
|
+
insert_point = meta_insert_point
|
112
|
+
insert_at = insert_point.positive? ? insert_point + 1 : 0
|
113
|
+
lines.insert(insert_at, "# #{title}\n")
|
114
|
+
lines.join("\n")
|
115
|
+
end
|
116
|
+
|
50
117
|
def set_meta(key, value, style: :comment)
|
51
118
|
case style
|
52
119
|
when :yaml
|
@@ -143,7 +210,7 @@ class ::String
|
|
143
210
|
end
|
144
211
|
|
145
212
|
def to_pattern
|
146
|
-
gsub(/\$(\d+)/, '\\\\\1').gsub(/(^["']|["']$)/,
|
213
|
+
gsub(/\$(\d+)/, '\\\\\1').gsub(/(^["']|["']$)/, "")
|
147
214
|
end
|
148
215
|
end
|
149
216
|
|
@@ -153,12 +220,21 @@ class Filter < String
|
|
153
220
|
|
154
221
|
def initialize(filter)
|
155
222
|
@filter, @params = filter.normalize_filter
|
223
|
+
super
|
156
224
|
end
|
157
225
|
|
158
226
|
def process
|
159
227
|
content = Conductor.stdin
|
160
228
|
|
161
229
|
case @filter
|
230
|
+
when /(insert|add|inject)title/
|
231
|
+
content.insert_title
|
232
|
+
when /(insert|add|inject)script/
|
233
|
+
content = content.append("\n\n<div>")
|
234
|
+
@params.each do |script|
|
235
|
+
content = content.insert_script(script)
|
236
|
+
end
|
237
|
+
"#{content}</div>"
|
162
238
|
when /(add|set)meta/
|
163
239
|
unless @params.count == 2
|
164
240
|
warn "Invalid filter parameters: #{@filter}(#{@params.join(",")})"
|
data/lib/conductor/string.rb
CHANGED
data/lib/conductor/version.rb
CHANGED
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
|
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
|
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
|
-
|
129
|
+
> Example:
|
130
|
+
>
|
131
|
+
> script: github_pre
|
130
132
|
|
131
|
-
|
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
|
|
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.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-
|
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
|