marked-conductor 1.0.18 → 1.0.20

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: 07cc317b99e30de42235572b6444e09b6a958b79bc2eda7fdb8fa9b88d608b3f
4
- data.tar.gz: 31b568475ab2a17c310d5279e8c356d10d4c8217ecb112a667edde4e6a6425a5
3
+ metadata.gz: c1f949d9bf655cb035b9bc2ed9f023e49c475effab65533f30b86c5392fa9908
4
+ data.tar.gz: de2824955f1c84608c3c32e5c9ef43b9b28a9e9623f454723ca7ddff3cede011
5
5
  SHA512:
6
- metadata.gz: cb5b28f08d4de3b9e2574564302f390d519dbeab569b84e08a6eac7f432053235a53bf6cf31f9742384eb978618b5cf73d24661f22fc1f9b91e1e18a4686d7eb
7
- data.tar.gz: 9067a2196bf46d104bc62a0152908a14cee90e1b7c27434a24452d85a2da20abcfd19499947e65503fdde7051e9e023a3c5829930e0451b28041c5fdf4d1713a
6
+ metadata.gz: 0f9c7c098a2e714ddca8673eda552d912319822c3a3c711fbfdba1a816e3f26dc8e42162532a68ccd1fb478d0452304b72e2a0d19c2a3025766ee9e0b3800db2
7
+ data.tar.gz: ae32f776ecbd94a2eba88b92fbdb3f30c016ace349ded8f8b64ecf1fb688125732d790f6d5ad31152ec74570aab16ef859be9bb43b0df49219086d64c0f52169
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ### 1.0.20
2
+
3
+ 2024-07-04 12:18
4
+
5
+ #### NEW
6
+
7
+ - The `insertTitle` filter can now take an argument of `true` or a number and will shift the remaining headlines in the document by 1 (or the number given in the argument), allowing for title insertion while only having 1 H1 in the document.
8
+
9
+ #### IMPROVED
10
+
11
+ - Ignore self-linking urls in single quotes, just in case they're used in a script line
12
+
13
+ ### 1.0.19
14
+
15
+ 2024-07-02 11:25
16
+
17
+ #### FIXED
18
+
19
+ - Bug in creating default config
20
+
1
21
  ### 1.0.18
2
22
 
3
23
  2024-07-02 11:08
data/README.md CHANGED
@@ -170,12 +170,16 @@ For `insertScript`, if path is just a filename it will look for a match in `~/.c
170
170
 
171
171
  For `insertCSS`, if path is just a filename (with or without .css extension), the file will be searched for in `~/.config/conductor/css` or `~/.config/conductor/files` and injected. CSS will be compressed using the YUI algorithm and inserted at the top of the document, but after any existing metadata.
172
172
 
173
+ For `insertTitle`, if an argument of `true` or a number is given (e.g. `insertTitle(true)`, the headers in the document will be shifted by 1 (or by the number given) so that there's only one H1 in the document.
174
+
173
175
  If the path for `insertScript` or `insertCSS` is a URL instead of a filename, the URL will be properly inserted instead of a file path. Inserted scripts will be surrounded with `<div>` tags, which fixes a quirk with javascript in Marked.
174
176
 
175
177
  For all of the prepend/append file filters, you can store files in `~/.config/conductor/files` and reference them with just a filename. Otherwise a full path will be assumed.
176
178
 
177
179
  For `autoLink`, any URL that's not contained in parenthesis or following a `[]: url` pattern will be autolinked (surrounded by angle brackets). URLs must contain `//` to be recognized, but any protocol will work, e.g. `x-marked://refresh`.
178
180
 
181
+ **Note:** successive filters in a sequence that insert or prepend will always insert content before/above the result of the previous insert filter. So if you have an `insertTitle` filter followed by an `insertCSS` filter, the CSS will appear above the inserted title. If you want elements inserted in reverse order, reverse the order of the inserts in the sequence.
182
+
179
183
  > Example:
180
184
  >
181
185
  > filter: setStyle(github)
@@ -14,34 +14,36 @@ module Conductor
14
14
 
15
15
  @tracks = @config["tracks"].symbolize_keys
16
16
  end
17
- end
18
17
 
19
- def create_config(config_file)
20
- config_dir = File.dirname(config_file)
21
- scripts_dir = File.dirname(File.join(config_dir, "scripts"))
22
- FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
23
- FileUtils.mkdir_p(scripts_dir) unless File.directory?(scripts_dir)
24
- File.open(config_file, "w") { |f| f.puts sample_config }
25
- puts "Sample config created at #{config_file}"
18
+ private
26
19
 
27
- Process.exit 0
28
- end
20
+ def create_config(config_file)
21
+ config_dir = File.dirname(config_file)
22
+ scripts_dir = File.dirname(File.join(config_dir, "scripts"))
23
+ FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
24
+ FileUtils.mkdir_p(scripts_dir) unless File.directory?(scripts_dir)
25
+ File.open(config_file, "w") { |f| f.puts sample_config }
26
+ puts "Sample config created at #{config_file}"
29
27
 
30
- def sample_config
31
- <<~EOCONFIG
32
- tracks:
33
- - condition: phase is pre
34
- tracks:
35
- - condition: tree contains .obsidian
28
+ Process.exit 0
29
+ end
30
+
31
+ def sample_config
32
+ <<~EOCONFIG
33
+ tracks:
34
+ - condition: phase is pre
36
35
  tracks:
36
+ - condition: tree contains .obsidian
37
+ tracks:
38
+ - condition: extension is md
39
+ script: obsidian-md-filter
37
40
  - condition: extension is md
38
- script: obsidian-md-filter
39
- - condition: extension is md
40
- command: rdiscount $file
41
- - condition: yaml includes comments
42
- script: blog-processor
43
- - condition: any
44
- command: echo 'NOCUSTOM'
45
- EOCONFIG
41
+ command: rdiscount $file
42
+ - condition: yaml includes comments
43
+ script: blog-processor
44
+ - condition: any
45
+ command: echo 'NOCUSTOM'
46
+ EOCONFIG
47
+ end
46
48
  end
47
49
  end
@@ -69,9 +69,17 @@ class ::String
69
69
  first
70
70
  end
71
71
 
72
+ def shift_headers(amt = 1)
73
+ gsub(/^#/, "#{"#" * amt}#")
74
+ end
75
+
76
+ def shift_headers!(amt = 1)
77
+ replace shift_headers(amt)
78
+ end
79
+
72
80
  def insert_toc(max = nil, after = :h1)
73
81
  lines = split(/\n/)
74
- max = max && max.to_i.positive? ? " max#{max}" : ""
82
+ max = max.to_i&.positive? ? " max#{max}" : ""
75
83
  line = case after.to_sym
76
84
  when :h2
77
85
  first_h2.positive? ? first_h2 + 1 : 0
@@ -172,10 +180,16 @@ class ::String
172
180
  %(#{self}\n<script type="javascript" src="#{path.strip}"></script>\n)
173
181
  end
174
182
 
183
+ def insert_raw_javascript(content)
184
+ %(#{self}\n<script>#{content}</script>)
185
+ end
186
+
175
187
  def insert_script(path)
176
188
  path.strip!
177
189
  return insert_javascript(path) if path =~ /^http/
178
190
 
191
+ return insert_raw_javascript(path) if path =~ /\(.*?\)/
192
+
179
193
  path.sub!(/(\.js)?$/, '.js')
180
194
 
181
195
  if path =~ %r{^[~/]}
@@ -228,10 +242,12 @@ class ::String
228
242
  title
229
243
  end
230
244
 
231
- def insert_title
245
+ def insert_title(shift: 0)
246
+ content = dup
232
247
  title = get_title
233
- lines = split(/\n/)
234
- insert_point = meta_insert_point
248
+ content.shift_headers!(shift) if shift.positive?
249
+ lines = content.split(/\n/)
250
+ insert_point = content.meta_insert_point
235
251
  insert_at = insert_point.positive? ? insert_point + 1 : 0
236
252
  lines.insert(insert_at, "# #{title}\n")
237
253
  lines.join("\n")
@@ -322,7 +338,7 @@ class ::String
322
338
  end
323
339
 
324
340
  def autolink
325
- gsub(%r{(?mi)(?<!\(|\]: |")\b((?:[\w-]+?://)[-a-zA-Z0-9@:%._+~#=]{2,256}\b(?:[-a-zA-Z0-9@:%_+.~#?&/=]*))},
341
+ gsub(%r{(?mi)(?<!\(|\]: |"|')\b((?:[\w-]+?://)[-a-zA-Z0-9@:%._+~#=]{2,256}\b(?:[-a-zA-Z0-9@:%_+.~#?&/=]*))},
326
342
  '<\1>')
327
343
  end
328
344
 
@@ -361,7 +377,15 @@ class Filter < String
361
377
  end
362
378
  content
363
379
  when /(insert|add|inject)title/
364
- content.insert_title
380
+ amt = 0
381
+ if @params
382
+ amt = if @params[0] =~ /^[yts]/
383
+ 1
384
+ else
385
+ @params[0].to_i
386
+ end
387
+ end
388
+ content.insert_title(shift: amt)
365
389
  when /(insert|add|inject)script/
366
390
  content.append!("\n\n<div>")
367
391
  @params.each do |script|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conductor
4
- VERSION = '1.0.18'
4
+ VERSION = '1.0.20'
5
5
  end
data/src/_README.md CHANGED
@@ -170,12 +170,16 @@ For `insertScript`, if path is just a filename it will look for a match in `~/.c
170
170
 
171
171
  For `insertCSS`, if path is just a filename (with or without .css extension), the file will be searched for in `~/.config/conductor/css` or `~/.config/conductor/files` and injected. CSS will be compressed using the YUI algorithm and inserted at the top of the document, but after any existing metadata.
172
172
 
173
+ For `insertTitle`, if an argument of `true` or a number is given (e.g. `insertTitle(true)`, the headers in the document will be shifted by 1 (or by the number given) so that there's only one H1 in the document.
174
+
173
175
  If the path for `insertScript` or `insertCSS` is a URL instead of a filename, the URL will be properly inserted instead of a file path. Inserted scripts will be surrounded with `<div>` tags, which fixes a quirk with javascript in Marked.
174
176
 
175
177
  For all of the prepend/append file filters, you can store files in `~/.config/conductor/files` and reference them with just a filename. Otherwise a full path will be assumed.
176
178
 
177
179
  For `autoLink`, any URL that's not contained in parenthesis or following a `[]: url` pattern will be autolinked (surrounded by angle brackets). URLs must contain `//` to be recognized, but any protocol will work, e.g. `x-marked://refresh`.
178
180
 
181
+ **Note:** successive filters in a sequence that insert or prepend will always insert content before/above the result of the previous insert filter. So if you have an `insertTitle` filter followed by an `insertCSS` filter, the CSS will appear above the inserted title. If you want elements inserted in reverse order, reverse the order of the inserts in the sequence.
182
+
179
183
  > Example:
180
184
  >
181
185
  > filter: setStyle(github)
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.18
4
+ version: 1.0.20
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-07-02 00:00:00.000000000 Z
11
+ date: 2024-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print