markdown_exec 1.3.3.3 → 1.3.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +159 -0
- data/Gemfile.lock +1 -1
- data/bin/tab_completion.sh +2 -2
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +20 -22
- data/lib/menu.yml +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c3c3615fdab637a5df4f5616d9c07f277e499f1f8de3a5fa70dda72ae2cb0b3
|
|
4
|
+
data.tar.gz: b7cb1a2abfeaf114f25aac530d316aa181ca1464af5426e5b1f0b5aaa3538320
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2bf8576d03115f6d769e961091d5a33bfc65fafdca8f2f282895230836670fb741a34a94beac49dc1008faa6ea293b3f882721b56f69fcbb697e4c011143ab7a
|
|
7
|
+
data.tar.gz: a53fecba24f39b4e5234164e4eada14a95b8c078111d50572c9094f5171671f3d79efc20065caaf67a1b7bce2f774c9cb52bb5c1bbbf8855678d317a3561bbef
|
data/CHANGELOG.md
CHANGED
|
@@ -106,6 +106,165 @@
|
|
|
106
106
|
|
|
107
107
|
- [! ] option to use most recent named block if dupiclate, currently appends same-name blocks but lists twice in menu
|
|
108
108
|
|
|
109
|
+
- [! ] improve error when imported file is not found
|
|
110
|
+
|
|
111
|
+
- [ ] decorations for import block
|
|
112
|
+
prefix line(s)
|
|
113
|
+
inline replacements
|
|
114
|
+
suffix line(s)
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
##
|
|
118
|
+
# Replace substrings in an input string based on a regular expression pattern
|
|
119
|
+
# with named capture groups. The replacements are formatted using a provided
|
|
120
|
+
# format string. Additional context can be provided to supplement or override
|
|
121
|
+
# the named captures in the format string.
|
|
122
|
+
#
|
|
123
|
+
# @param input_str [String] The input string to process.
|
|
124
|
+
# @param regex [Regexp] The regular expression pattern with named capture groups.
|
|
125
|
+
# @param format_str [String] The format string for sprintf.
|
|
126
|
+
# @param context [Hash] Additional context to supplement or override named captures.
|
|
127
|
+
#
|
|
128
|
+
# @return [String] The processed string after replacements.
|
|
129
|
+
#
|
|
130
|
+
# def gsub_format(input_str, regex, format_str, context: {})
|
|
131
|
+
# input_str.gsub(regex) do
|
|
132
|
+
# captures_hash = $~.names.each_with_object({}) do |name, hash|
|
|
133
|
+
# hash[name.to_sym] = $~[name]
|
|
134
|
+
# end
|
|
135
|
+
|
|
136
|
+
# ### add import file name, line number, line, to captures_hash, chain
|
|
137
|
+
# # $~ (MatchData) - MatchData object created from the match; thread-local and frame-local. - English - $LAST_MATCH_INFO.
|
|
138
|
+
# # $& (Matched Substring) - The matched string. - English - $MATCH.
|
|
139
|
+
# # $` (Pre-Match Substring) - The string to the left of the match. - English - $PREMATCH.
|
|
140
|
+
# # $' (Post-Match Substring) - The string to the right of the match. - English - $POSTMATCH.
|
|
141
|
+
# # $+ (Last Matched Group) - The last group matched. - English - $LAST_PAREN_MATCH.
|
|
142
|
+
|
|
143
|
+
# sprintf(format_str, context.merge(captures_hash))
|
|
144
|
+
# end
|
|
145
|
+
# end
|
|
146
|
+
|
|
147
|
+
class Regexp
|
|
148
|
+
def gsub_format(input_str, format_str, context: {})
|
|
149
|
+
input_str.gsub(self) do
|
|
150
|
+
captures_hash = $~.names.each_with_object({}) do |name, hash|
|
|
151
|
+
hash[name.to_sym] = $~[name]
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# ### add import file name, line number, line, to captures_hash, chain
|
|
155
|
+
# # $~ (MatchData) - MatchData object created from the match; thread-local and frame-local. - English - $LAST_MATCH_INFO.
|
|
156
|
+
# # $& (Matched Substring) - The matched string. - English - $MATCH.
|
|
157
|
+
# # $` (Pre-Match Substring) - The string to the left of the match. - English - $PREMATCH.
|
|
158
|
+
# # $' (Post-Match Substring) - The string to the right of the match. - English - $POSTMATCH.
|
|
159
|
+
# # $+ (Last Matched Group) - The last group matched. - English - $LAST_PAREN_MATCH.
|
|
160
|
+
|
|
161
|
+
# # Add file name, line number, line to captures_hash
|
|
162
|
+
# captures_hash[:file_name] = $~.pre_match.split("\n").last
|
|
163
|
+
# captures_hash[:line_number] = $~.pre_match.count("\n") + 1
|
|
164
|
+
# captures_hash[:line] = $&
|
|
165
|
+
|
|
166
|
+
sprintf(format_str, context.merge(captures_hash))
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# # Example usage:
|
|
172
|
+
# str = "123 example"
|
|
173
|
+
# re = /(?<foo>\d+) (?<bar>\w+)/
|
|
174
|
+
# fmt = "%<foo>d : %<bar>s"
|
|
175
|
+
# new_str = gsub_format(str, re, fmt)
|
|
176
|
+
# puts new_str # Outputs: 123 : example
|
|
177
|
+
|
|
178
|
+
require 'minitest/autorun'
|
|
179
|
+
require_relative 'path_to_your_file' # Make sure to replace this with the path to the file containing the function
|
|
180
|
+
|
|
181
|
+
class ReplaceWithFormatTest < Minitest::Test
|
|
182
|
+
def test_basic_replacement
|
|
183
|
+
input_str = "123 example"
|
|
184
|
+
re = /(?<foo>\d+) (?<bar>\w+)/
|
|
185
|
+
fmt = "%<foo>d : %<bar>s"
|
|
186
|
+
|
|
187
|
+
result = gsub_format(input_str, re, fmt)
|
|
188
|
+
|
|
189
|
+
assert_equal "123 : example", result
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_no_match
|
|
193
|
+
input_str = "This is a test."
|
|
194
|
+
re = /(?<foo>\d+) (?<bar>\w+)/
|
|
195
|
+
fmt = "%<foo>d : %<bar>s"
|
|
196
|
+
|
|
197
|
+
result = gsub_format(input_str, re, fmt)
|
|
198
|
+
|
|
199
|
+
assert_equal "This is a test.", result
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_multiple_matches
|
|
203
|
+
input_str = "123 example, 456 test"
|
|
204
|
+
re = /(?<foo>\d+) (?<bar>\w+)/
|
|
205
|
+
fmt = "[%<foo>d %<bar>s]"
|
|
206
|
+
|
|
207
|
+
result = gsub_format(input_str, re, fmt)
|
|
208
|
+
|
|
209
|
+
assert_equal "[123 example], [456 test]", result
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def test_different_named_captures
|
|
213
|
+
input_str = "Jane is 25 years old."
|
|
214
|
+
re = /(?<name>\w+) is (?<age>\d+)/
|
|
215
|
+
fmt = "%<name>s's age is %<age>d"
|
|
216
|
+
|
|
217
|
+
result = gsub_format(input_str, re, fmt)
|
|
218
|
+
|
|
219
|
+
assert_equal "Jane's age is 25", result
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def test_with_context
|
|
223
|
+
input_str = "Jane is 25 years old."
|
|
224
|
+
re = /(?<name>\w+) is (?<age>\d+)/
|
|
225
|
+
fmt = "%<name>s's age is %<age>d and she lives in %<city>s"
|
|
226
|
+
|
|
227
|
+
result = gsub_format(input_str, re, fmt, context: { city: "New York" })
|
|
228
|
+
|
|
229
|
+
assert_equal "Jane's age is 25 and she lives in New York", result
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
require 'minitest/autorun'
|
|
234
|
+
require_relative 'path_to_your_file' # Ensure this path is correct
|
|
235
|
+
|
|
236
|
+
class RegexpGsubFormatTest < Minitest::Test
|
|
237
|
+
def test_basic_replacement
|
|
238
|
+
input_str = "123 example"
|
|
239
|
+
re = /(?<foo>\d+) (?<bar>\w+)/
|
|
240
|
+
fmt = "%<foo>d : %<bar>s"
|
|
241
|
+
|
|
242
|
+
result = re.gsub_format(input_str, fmt)
|
|
243
|
+
|
|
244
|
+
assert_equal "123 : example", result
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# ... [other tests remain mostly unchanged, just updating the method call]
|
|
248
|
+
|
|
249
|
+
def test_with_context
|
|
250
|
+
input_str = "Jane is 25 years old."
|
|
251
|
+
re = /(?<name>\w+) is (?<age>\d+)/
|
|
252
|
+
fmt = "%<name>s's age is %<age>d and she lives in %<city>s"
|
|
253
|
+
|
|
254
|
+
result = re.gsub_format(input_str, fmt, context: { city: "New York" })
|
|
255
|
+
|
|
256
|
+
assert_equal "Jane's age is 25 and she lives in New York", result
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## [1.3.5] - 2023-10-05
|
|
263
|
+
|
|
264
|
+
### Changed
|
|
265
|
+
|
|
266
|
+
- Fix display of menu dividers.
|
|
267
|
+
|
|
109
268
|
## [1.3.3] - 2023-10-03
|
|
110
269
|
|
|
111
270
|
### Added
|
data/Gemfile.lock
CHANGED
data/bin/tab_completion.sh
CHANGED
|
@@ -13,7 +13,7 @@ __filedirs_all()
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
_mde_echo_version() {
|
|
16
|
-
echo "1.3.3.
|
|
16
|
+
echo "1.3.3.5"
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
_mde() {
|
|
@@ -138,4 +138,4 @@ _mde() {
|
|
|
138
138
|
|
|
139
139
|
complete -o filenames -o nospace -F _mde mde
|
|
140
140
|
# _mde_echo_version
|
|
141
|
-
# echo "Updated: 2023-10-
|
|
141
|
+
# echo "Updated: 2023-10-05 14:21:31 UTC"
|
data/lib/markdown_exec.rb
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
require 'English'
|
|
7
7
|
require 'clipboard'
|
|
8
|
+
require 'fileutils'
|
|
8
9
|
require 'open3'
|
|
9
10
|
require 'optparse'
|
|
10
11
|
require 'shellwords'
|
|
@@ -259,7 +260,6 @@ module MarkdownExec
|
|
|
259
260
|
else
|
|
260
261
|
true
|
|
261
262
|
end.tap_inspect
|
|
262
|
-
# binding.pry
|
|
263
263
|
rescue StandardError => err
|
|
264
264
|
warn("ERROR ** Filter::fcb_select?(); #{err.inspect}")
|
|
265
265
|
raise err
|
|
@@ -357,7 +357,7 @@ module MarkdownExec
|
|
|
357
357
|
selrows = @table.select do |fcb_title_groups|
|
|
358
358
|
Filter.fcb_select? options, fcb_title_groups
|
|
359
359
|
end
|
|
360
|
-
|
|
360
|
+
|
|
361
361
|
### hide rows correctly
|
|
362
362
|
|
|
363
363
|
if opts[:hide_blocks_by_name]
|
|
@@ -662,10 +662,7 @@ module MarkdownExec
|
|
|
662
662
|
end
|
|
663
663
|
|
|
664
664
|
def cfile
|
|
665
|
-
# puts @options.inspect
|
|
666
|
-
# binding.pry
|
|
667
665
|
@cfile ||= CachedNestedFileReader.new(import_pattern: @options.fetch(:import_pattern))
|
|
668
|
-
# @cfile ||= CachedNestedFileReader.new(import_pattern: /^ *#insert (.+)$/)
|
|
669
666
|
end
|
|
670
667
|
|
|
671
668
|
# :reek:DuplicateMethodCall
|
|
@@ -944,7 +941,7 @@ module MarkdownExec
|
|
|
944
941
|
blocks.push FCB.new({
|
|
945
942
|
# name: '',
|
|
946
943
|
chrome: true,
|
|
947
|
-
|
|
944
|
+
name: format(
|
|
948
945
|
opts[:menu_divider_format],
|
|
949
946
|
opts[:menu_initial_divider]
|
|
950
947
|
).send(opts[:menu_divider_color].to_sym),
|
|
@@ -953,7 +950,6 @@ module MarkdownExec
|
|
|
953
950
|
end
|
|
954
951
|
|
|
955
952
|
iter_blocks_in_file(opts) do |btype, fcb|
|
|
956
|
-
# binding.pry
|
|
957
953
|
case btype
|
|
958
954
|
when :filter
|
|
959
955
|
## return type of blocks to select
|
|
@@ -963,14 +959,12 @@ module MarkdownExec
|
|
|
963
959
|
when :line
|
|
964
960
|
## convert line to block
|
|
965
961
|
#
|
|
966
|
-
# binding.pry
|
|
967
962
|
if opts[:menu_divider_match].present? &&
|
|
968
963
|
(mbody = fcb.body[0].match opts[:menu_divider_match])
|
|
969
|
-
# binding.pry
|
|
970
964
|
blocks.push FCB.new(
|
|
971
965
|
{ chrome: true,
|
|
972
966
|
disabled: '',
|
|
973
|
-
|
|
967
|
+
name: format(opts[:menu_divider_format],
|
|
974
968
|
mbody[:name]).send(opts[:menu_divider_color].to_sym) }
|
|
975
969
|
)
|
|
976
970
|
elsif opts[:menu_task_match].present? &&
|
|
@@ -978,7 +972,7 @@ module MarkdownExec
|
|
|
978
972
|
blocks.push FCB.new(
|
|
979
973
|
{ chrome: true,
|
|
980
974
|
disabled: '',
|
|
981
|
-
|
|
975
|
+
name: format(opts[:menu_task_format],
|
|
982
976
|
mbody[:name]).send(opts[:menu_task_color].to_sym) }
|
|
983
977
|
)
|
|
984
978
|
else
|
|
@@ -995,7 +989,7 @@ module MarkdownExec
|
|
|
995
989
|
blocks.push FCB.new(
|
|
996
990
|
{ chrome: true,
|
|
997
991
|
disabled: '',
|
|
998
|
-
|
|
992
|
+
name: format(opts[:menu_divider_format],
|
|
999
993
|
opts[:menu_final_divider])
|
|
1000
994
|
.send(opts[:menu_divider_color].to_sym) }
|
|
1001
995
|
)
|
|
@@ -1277,18 +1271,24 @@ module MarkdownExec
|
|
|
1277
1271
|
}
|
|
1278
1272
|
end
|
|
1279
1273
|
|
|
1274
|
+
## insert exit option at head or tail
|
|
1275
|
+
#
|
|
1276
|
+
def prompt_menu_add_exit(_prompt_text, items, exit_option, _opts = {})
|
|
1277
|
+
if @options[:menu_exit_at_top]
|
|
1278
|
+
(@options[:menu_with_exit] ? [exit_option] : []) + items
|
|
1279
|
+
else
|
|
1280
|
+
items + (@options[:menu_with_exit] ? [exit_option] : [])
|
|
1281
|
+
end
|
|
1282
|
+
end
|
|
1283
|
+
|
|
1280
1284
|
## tty prompt to select
|
|
1281
1285
|
# insert exit option at head or tail
|
|
1282
1286
|
# return selected option or nil
|
|
1283
1287
|
#
|
|
1284
1288
|
def prompt_with_quit(prompt_text, items, opts = {})
|
|
1285
1289
|
exit_option = '* Exit'
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
else
|
|
1289
|
-
items + (@options[:menu_with_exit] ? [exit_option] : [])
|
|
1290
|
-
end
|
|
1291
|
-
sel = @prompt.select(prompt_text, all_items, opts.merge(filter: true))
|
|
1290
|
+
sel = @prompt.select(prompt_text, prompt_menu_add_exit(prompt_text, items, exit_option, opts),
|
|
1291
|
+
opts.merge(filter: true))
|
|
1292
1292
|
sel == exit_option ? nil : sel
|
|
1293
1293
|
end
|
|
1294
1294
|
|
|
@@ -1375,7 +1375,7 @@ module MarkdownExec
|
|
|
1375
1375
|
@options[:logged_stdout_filename]
|
|
1376
1376
|
@logged_stdout_filespec = @options[:logged_stdout_filespec]
|
|
1377
1377
|
(dirname = File.dirname(@options[:logged_stdout_filespec]))
|
|
1378
|
-
|
|
1378
|
+
FileUtils.mkdir_p dirname
|
|
1379
1379
|
|
|
1380
1380
|
ol = ["-STDOUT-\n"]
|
|
1381
1381
|
ol += @execute_files&.fetch(EF_STDOUT, [])
|
|
@@ -1420,8 +1420,6 @@ module MarkdownExec
|
|
|
1420
1420
|
end.compact
|
|
1421
1421
|
return nil if bm.count.zero?
|
|
1422
1422
|
|
|
1423
|
-
# binding.pry
|
|
1424
|
-
|
|
1425
1423
|
sel = prompt_with_quit pt, bm,
|
|
1426
1424
|
per_page: opts[:select_page_height]
|
|
1427
1425
|
return nil if sel.nil?
|
|
@@ -1530,7 +1528,7 @@ module MarkdownExec
|
|
|
1530
1528
|
File.join opts[:saved_script_folder], opts[:saved_script_filename]
|
|
1531
1529
|
|
|
1532
1530
|
dirname = File.dirname(@options[:saved_filespec])
|
|
1533
|
-
|
|
1531
|
+
FileUtils.mkdir_p dirname
|
|
1534
1532
|
(shebang = if @options[:shebang]&.present?
|
|
1535
1533
|
"#{@options[:shebang]} #{@options[:shell]}\n"
|
|
1536
1534
|
else
|
data/lib/menu.yml
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: markdown_exec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.3.
|
|
4
|
+
version: 1.3.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fareed Stevenson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-10-
|
|
11
|
+
date: 2023-10-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: clipboard
|