marked-conductor 1.0.19 → 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: b36eba533a0b58958b2a4a9cb9c1a4ec2e9d93a1f57fb91524fead2ef93f55a5
4
- data.tar.gz: 37897dda228ea0b7f8e84c233fb5703c4ed2e9573fe412ae54b724f7d0c6ef4f
3
+ metadata.gz: c1f949d9bf655cb035b9bc2ed9f023e49c475effab65533f30b86c5392fa9908
4
+ data.tar.gz: de2824955f1c84608c3c32e5c9ef43b9b28a9e9623f454723ca7ddff3cede011
5
5
  SHA512:
6
- metadata.gz: 15a5ec6f5a56f5def420bddbd26c4c644f0ce37e3b32a430d13ba51d35957811f882778ce5f9cd396bde255607ef6697b6c07ce7b64a7a3191548f3302705a76
7
- data.tar.gz: 73472bc3cb6add78f1566d79e7b5c032da312af0021fc7ccebb17523ba719ca1e7f65f5ab478d05a4e5f29782a62141c169c74136997085230be45c23f2f607f
6
+ metadata.gz: 0f9c7c098a2e714ddca8673eda552d912319822c3a3c711fbfdba1a816e3f26dc8e42162532a68ccd1fb478d0452304b72e2a0d19c2a3025766ee9e0b3800db2
7
+ data.tar.gz: ae32f776ecbd94a2eba88b92fbdb3f30c016ace349ded8f8b64ecf1fb688125732d790f6d5ad31152ec74570aab16ef859be9bb43b0df49219086d64c0f52169
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
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
+
1
13
  ### 1.0.19
2
14
 
3
15
  2024-07-02 11:25
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)
@@ -15,6 +15,8 @@ module Conductor
15
15
  @tracks = @config["tracks"].symbolize_keys
16
16
  end
17
17
 
18
+ private
19
+
18
20
  def create_config(config_file)
19
21
  config_dir = File.dirname(config_file)
20
22
  scripts_dir = File.dirname(File.join(config_dir, "scripts"))
@@ -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
@@ -234,10 +242,12 @@ class ::String
234
242
  title
235
243
  end
236
244
 
237
- def insert_title
245
+ def insert_title(shift: 0)
246
+ content = dup
238
247
  title = get_title
239
- lines = split(/\n/)
240
- 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
241
251
  insert_at = insert_point.positive? ? insert_point + 1 : 0
242
252
  lines.insert(insert_at, "# #{title}\n")
243
253
  lines.join("\n")
@@ -328,7 +338,7 @@ class ::String
328
338
  end
329
339
 
330
340
  def autolink
331
- 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@:%_+.~#?&/=]*))},
332
342
  '<\1>')
333
343
  end
334
344
 
@@ -367,7 +377,15 @@ class Filter < String
367
377
  end
368
378
  content
369
379
  when /(insert|add|inject)title/
370
- 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)
371
389
  when /(insert|add|inject)script/
372
390
  content.append!("\n\n<div>")
373
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.19'
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.19
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