markdown_exec 1.8.4 → 1.8.6
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/.pryrc +1 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -3
- data/Gemfile.lock +17 -6
- data/bin/bmde +1 -103
- data/bin/tab_completion.sh +15 -3
- data/examples/linked.md +52 -0
- data/examples/linked1.md +11 -1
- data/examples/linked2.md +5 -1
- data/examples/opts.md +23 -3
- data/lib/ansi_formatter.rb +0 -41
- data/lib/cached_nested_file_reader.rb +1 -7
- data/lib/constants.rb +17 -0
- data/lib/directory_searcher.rb +41 -5
- data/lib/filter.rb +2 -21
- data/lib/hash_delegator.rb +300 -177
- data/lib/link_history.rb +5 -2
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +20 -9
- data/lib/menu.src.yml +39 -12
- data/lib/menu.yml +37 -13
- data/lib/regexp_replacer.rb +58 -0
- metadata +4 -2
data/lib/link_history.rb
CHANGED
@@ -5,18 +5,20 @@
|
|
5
5
|
module MarkdownExec
|
6
6
|
class LinkState
|
7
7
|
attr_accessor :block_name, :document_filename,
|
8
|
-
:inherited_block_names, :inherited_lines
|
8
|
+
:inherited_block_names, :inherited_dependencies, :inherited_lines
|
9
9
|
|
10
10
|
# Initialize the LinkState with keyword arguments for each attribute.
|
11
11
|
# @param block_name [String, nil] the name of the block.
|
12
12
|
# @param document_filename [String, nil] the filename of the document.
|
13
13
|
# @param inherited_block_names [Array<String>, nil] the names of the inherited blocks.
|
14
|
+
# @param inherited_dependencies [?, nil] the dependecy hierarcy.
|
14
15
|
# @param inherited_lines [Array<String>, nil] the inherited lines of code.
|
15
16
|
def initialize(block_name: nil, document_filename: nil,
|
16
|
-
inherited_block_names: [], inherited_lines: nil)
|
17
|
+
inherited_block_names: [], inherited_dependencies: nil, inherited_lines: nil)
|
17
18
|
@block_name = block_name
|
18
19
|
@document_filename = document_filename
|
19
20
|
@inherited_block_names = inherited_block_names
|
21
|
+
@inherited_dependencies = inherited_dependencies
|
20
22
|
@inherited_lines = inherited_lines
|
21
23
|
end
|
22
24
|
|
@@ -34,6 +36,7 @@ module MarkdownExec
|
|
34
36
|
other.block_name == block_name &&
|
35
37
|
other.document_filename == document_filename &&
|
36
38
|
other.inherited_block_names == inherited_block_names &&
|
39
|
+
other.inherited_dependencies == inherited_dependencies &&
|
37
40
|
other.inherited_lines == inherited_lines
|
38
41
|
end
|
39
42
|
end
|
data/lib/markdown_exec.rb
CHANGED
@@ -41,6 +41,8 @@ tap_config envvar: MarkdownExec::TAP_DEBUG
|
|
41
41
|
$stderr.sync = true
|
42
42
|
$stdout.sync = true
|
43
43
|
|
44
|
+
ARGV_SEP = '--'
|
45
|
+
|
44
46
|
# custom error: file specified is missing
|
45
47
|
#
|
46
48
|
class FileMissingError < StandardError; end
|
@@ -49,6 +51,11 @@ def dp(str)
|
|
49
51
|
lout " => #{str}", level: DISPLAY_LEVEL_DEBUG
|
50
52
|
end
|
51
53
|
|
54
|
+
def rbi
|
55
|
+
pp(caller.take(4).map.with_index { |line, ind| " - #{ind}: #{line}" })
|
56
|
+
binding.irb
|
57
|
+
end
|
58
|
+
|
52
59
|
def rbp
|
53
60
|
rpry
|
54
61
|
pp(caller.take(4).map.with_index { |line, ind| " - #{ind}: #{line}" })
|
@@ -58,7 +65,7 @@ end
|
|
58
65
|
def bpp(*args)
|
59
66
|
pp '+ bpp()'
|
60
67
|
pp(*args.map.with_index { |line, ind| " - #{ind}: #{line}" })
|
61
|
-
|
68
|
+
rbi
|
62
69
|
end
|
63
70
|
|
64
71
|
def rpry
|
@@ -131,10 +138,11 @@ module MarkdownExec
|
|
131
138
|
)
|
132
139
|
end
|
133
140
|
|
134
|
-
# return arguments before
|
141
|
+
# return arguments before ARGV_SEP
|
142
|
+
# arguments after ARGV_SEP are passed to the generatede script
|
135
143
|
#
|
136
144
|
def arguments_for_mde(argv = ARGV)
|
137
|
-
case ind = argv.find_index(
|
145
|
+
case ind = argv.find_index(ARGV_SEP)
|
138
146
|
when nil
|
139
147
|
argv
|
140
148
|
when 0
|
@@ -200,14 +208,13 @@ module MarkdownExec
|
|
200
208
|
# Reports and executes block logic
|
201
209
|
def execute_block_logic(files)
|
202
210
|
@options[:filename] = select_document_if_multiple(files)
|
203
|
-
@options.
|
211
|
+
@options.document_menu_loop
|
204
212
|
end
|
205
213
|
|
206
214
|
## Executes the block specified in the options
|
207
215
|
#
|
208
216
|
def execute_block_with_error_handling
|
209
217
|
finalize_cli_argument_processing
|
210
|
-
@options[:input_cli_rest] = @rest
|
211
218
|
execute_code_block_based_on_options(@options)
|
212
219
|
rescue FileMissingError
|
213
220
|
warn "File missing: #{$!}"
|
@@ -288,6 +295,7 @@ module MarkdownExec
|
|
288
295
|
#
|
289
296
|
block_name = rest.shift
|
290
297
|
@options[:block_name] = block_name if block_name.present?
|
298
|
+
@options[:input_cli_rest] = @rest
|
291
299
|
rescue FileMissingError
|
292
300
|
warn_format('finalize_cli_argument_processing',
|
293
301
|
"File missing -- #{$!}", { abort: true })
|
@@ -341,10 +349,11 @@ module MarkdownExec
|
|
341
349
|
->(_) { exit }
|
342
350
|
when 'find'
|
343
351
|
->(value) {
|
352
|
+
find_path = @options[:find_path].present? ? @options[:find_path] : @options[:path]
|
344
353
|
@fout.fout 'Searching in: ' \
|
345
|
-
"#{HashDelegator.new(@options).string_send_color(
|
354
|
+
"#{HashDelegator.new(@options).string_send_color(find_path,
|
346
355
|
:menu_chrome_color)}"
|
347
|
-
searcher = DirectorySearcher.new(value, [
|
356
|
+
searcher = DirectorySearcher.new(value, [find_path])
|
348
357
|
|
349
358
|
@fout.fout 'In file contents'
|
350
359
|
hash = searcher.search_in_file_contents
|
@@ -528,6 +537,8 @@ module MarkdownExec
|
|
528
537
|
execute_block_with_error_handling
|
529
538
|
rescue StandardError
|
530
539
|
error_handler('run')
|
540
|
+
ensure
|
541
|
+
yield if block_given?
|
531
542
|
end
|
532
543
|
|
533
544
|
private
|
@@ -539,7 +550,7 @@ module MarkdownExec
|
|
539
550
|
|
540
551
|
saved_name_split filename
|
541
552
|
@options[:save_executed_script] = false
|
542
|
-
@options.
|
553
|
+
@options.document_menu_loop
|
543
554
|
rescue StandardError
|
544
555
|
error_handler('run_last_script')
|
545
556
|
end
|
@@ -606,7 +617,7 @@ module MarkdownExec
|
|
606
617
|
|
607
618
|
saved_name_split(filename)
|
608
619
|
|
609
|
-
@options.
|
620
|
+
@options.document_menu_loop ### ({ save_executed_script: false })
|
610
621
|
end
|
611
622
|
|
612
623
|
public
|
data/lib/menu.src.yml
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
- :arg_name: NAME
|
19
19
|
:compreply: false
|
20
|
-
:description: Name of block
|
20
|
+
:description: Name of block to execute
|
21
21
|
:env_var: MDE_BLOCK_NAME
|
22
22
|
:long_name: block-name
|
23
23
|
:opt_name: block_name
|
@@ -92,6 +92,14 @@
|
|
92
92
|
:opt_name: document_load_opts_block_name
|
93
93
|
:procname: val_as_str
|
94
94
|
|
95
|
+
- :arg_name: BOOL
|
96
|
+
:default: false
|
97
|
+
:description: Dump @delegate_object
|
98
|
+
:env_var: MDE_DUMP_DELEGATE_OBJECT
|
99
|
+
:long_name: dump-dump-delegate-object
|
100
|
+
:opt_name: dump_delegate_object
|
101
|
+
:procname: val_as_bool
|
102
|
+
|
95
103
|
- :arg_name: BOOL
|
96
104
|
:default: false
|
97
105
|
:description: Dump BlocksInFile (stage 1)
|
@@ -100,6 +108,14 @@
|
|
100
108
|
:opt_name: dump_blocks_in_file
|
101
109
|
:procname: val_as_bool
|
102
110
|
|
111
|
+
- :arg_name: BOOL
|
112
|
+
:default: false
|
113
|
+
:description: Dump inherited lines
|
114
|
+
:env_var: MDE_DUMP_INHERITED_LINES
|
115
|
+
:long_name: dump-dump-inherited-lines
|
116
|
+
:opt_name: dump_inherited_lines
|
117
|
+
:procname: val_as_bool
|
118
|
+
|
103
119
|
- :arg_name: BOOL
|
104
120
|
:default: false
|
105
121
|
:description: Dump MenuBlocks (stage 2)
|
@@ -187,18 +203,20 @@
|
|
187
203
|
## match fenced code indented by spaces
|
188
204
|
#
|
189
205
|
- :default: "^(?<indent> *)`{3,}"
|
206
|
+
:description: Matches the start and end of a fenced code block
|
190
207
|
:env_var: MDE_FENCED_START_AND_END_REGEX
|
191
208
|
:opt_name: fenced_start_and_end_regex
|
192
209
|
:procname: val_as_str
|
193
210
|
|
194
211
|
- :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
|
212
|
+
:description: Match the start of a fenced block
|
195
213
|
:env_var: MDE_FENCED_START_EXTENDED_REGEX
|
196
214
|
:opt_name: fenced_start_extended_regex
|
197
215
|
:procname: val_as_str
|
198
216
|
|
199
217
|
- :arg_name: RELATIVE_PATH
|
200
218
|
:compreply: "."
|
201
|
-
:description: Name of document
|
219
|
+
:description: Name of the document to load
|
202
220
|
:env_var: MDE_FILENAME
|
203
221
|
:long_name: filename
|
204
222
|
:opt_name: filename
|
@@ -212,6 +230,14 @@
|
|
212
230
|
:procname: find
|
213
231
|
:short_name: "?"
|
214
232
|
|
233
|
+
- :arg_name: FIND_PATH
|
234
|
+
:default: ""
|
235
|
+
:description: Path for find (uses PATH if empty)
|
236
|
+
:env_var: MDE_FIND_PATH
|
237
|
+
:long_name: find-path
|
238
|
+
:opt_name: find_path
|
239
|
+
:procname: val_as_str
|
240
|
+
|
215
241
|
- :default: "^# *(?<name>[^#]*?) *$"
|
216
242
|
:env_var: MDE_HEADING1_MATCH
|
217
243
|
:opt_name: heading1_match
|
@@ -338,7 +364,7 @@
|
|
338
364
|
|
339
365
|
- :arg_name: BOOL
|
340
366
|
:default: false
|
341
|
-
:description:
|
367
|
+
:description: Controls whether headings(levels 1,2,3) are displayed in the block selection menu
|
342
368
|
:env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
|
343
369
|
:opt_name: menu_blocks_with_headings
|
344
370
|
:procname: val_as_bool
|
@@ -408,7 +434,8 @@
|
|
408
434
|
|
409
435
|
- :arg_name: BOOL
|
410
436
|
:default: false
|
411
|
-
:description: Include imported notes in menu
|
437
|
+
# :description: Include imported notes in menu
|
438
|
+
:description: Whether imported blocks should be included in the menu
|
412
439
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
413
440
|
:opt_name: menu_include_imported_notes
|
414
441
|
:procname: val_as_bool
|
@@ -590,7 +617,7 @@
|
|
590
617
|
|
591
618
|
- :arg_name: BOOL
|
592
619
|
:default: true
|
593
|
-
:description:
|
620
|
+
:description: Whether standard output from execution is displayed
|
594
621
|
:env_var: MDE_OUTPUT_STDOUT
|
595
622
|
:long_name: output-stdout
|
596
623
|
:opt_name: output_stdout
|
@@ -612,14 +639,14 @@
|
|
612
639
|
|
613
640
|
- :arg_name: BOOL
|
614
641
|
:default: true
|
615
|
-
:description:
|
616
|
-
:env_var:
|
642
|
+
:description: Wheter to pause after manually executing a block and the next menu
|
643
|
+
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
617
644
|
:opt_name: pause_after_script_execution
|
618
645
|
:procname: val_as_bool
|
619
646
|
|
620
647
|
- :default: "\nContinue?"
|
621
|
-
:description: Prompt after
|
622
|
-
:env_var:
|
648
|
+
:description: Prompt after manually executing a block and the next menu
|
649
|
+
:env_var: MDE_PROMPT_AFTER_SCRIPT_EXECUTION
|
623
650
|
:opt_name: prompt_after_script_execution
|
624
651
|
:procname: val_as_str
|
625
652
|
|
@@ -701,7 +728,7 @@
|
|
701
728
|
|
702
729
|
- :arg_name: BOOL
|
703
730
|
:default: false
|
704
|
-
:description:
|
731
|
+
:description: Wheter to save an executed script`
|
705
732
|
:env_var: MDE_SAVE_EXECUTED_SCRIPT
|
706
733
|
:long_name: save-executed-script
|
707
734
|
:opt_name: save_executed_script
|
@@ -743,7 +770,7 @@
|
|
743
770
|
|
744
771
|
- :arg_name: RELATIVE_PATH
|
745
772
|
:default: logs
|
746
|
-
:description:
|
773
|
+
:description: Folder where saved scripts are stored
|
747
774
|
:env_var: MDE_SAVED_SCRIPT_FOLDER
|
748
775
|
:long_name: saved-script-folder
|
749
776
|
:opt_name: saved_script_folder
|
@@ -868,7 +895,7 @@
|
|
868
895
|
|
869
896
|
- :arg_name: BOOL
|
870
897
|
:default: true
|
871
|
-
:description:
|
898
|
+
:description: Requires user approval before executing a script
|
872
899
|
:env_var: MDE_USER_MUST_APPROVE
|
873
900
|
:long_name: user-must-approve
|
874
901
|
:opt_name: user_must_approve
|
data/lib/menu.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MDE - Markdown Executor (1.8.
|
1
|
+
# MDE - Markdown Executor (1.8.6)
|
2
2
|
---
|
3
3
|
- :description: Show current configuration values
|
4
4
|
:procname: show_config
|
@@ -15,7 +15,7 @@
|
|
15
15
|
:procname: val_as_str
|
16
16
|
- :arg_name: NAME
|
17
17
|
:compreply: false
|
18
|
-
:description: Name of block
|
18
|
+
:description: Name of block to execute
|
19
19
|
:env_var: MDE_BLOCK_NAME
|
20
20
|
:long_name: block-name
|
21
21
|
:opt_name: block_name
|
@@ -77,6 +77,13 @@
|
|
77
77
|
:env_var: MDE_DOCUMENT_LOAD_OPTS_BLOCK_NAME
|
78
78
|
:opt_name: document_load_opts_block_name
|
79
79
|
:procname: val_as_str
|
80
|
+
- :arg_name: BOOL
|
81
|
+
:default: false
|
82
|
+
:description: Dump @delegate_object
|
83
|
+
:env_var: MDE_DUMP_DELEGATE_OBJECT
|
84
|
+
:long_name: dump-dump-delegate-object
|
85
|
+
:opt_name: dump_delegate_object
|
86
|
+
:procname: val_as_bool
|
80
87
|
- :arg_name: BOOL
|
81
88
|
:default: false
|
82
89
|
:description: Dump BlocksInFile (stage 1)
|
@@ -84,6 +91,13 @@
|
|
84
91
|
:long_name: dump-blocks-in-file
|
85
92
|
:opt_name: dump_blocks_in_file
|
86
93
|
:procname: val_as_bool
|
94
|
+
- :arg_name: BOOL
|
95
|
+
:default: false
|
96
|
+
:description: Dump inherited lines
|
97
|
+
:env_var: MDE_DUMP_INHERITED_LINES
|
98
|
+
:long_name: dump-dump-inherited-lines
|
99
|
+
:opt_name: dump_inherited_lines
|
100
|
+
:procname: val_as_bool
|
87
101
|
- :arg_name: BOOL
|
88
102
|
:default: false
|
89
103
|
:description: Dump MenuBlocks (stage 2)
|
@@ -160,17 +174,19 @@
|
|
160
174
|
:procname: exit
|
161
175
|
:short_name: x
|
162
176
|
- :default: "^(?<indent> *)`{3,}"
|
177
|
+
:description: Matches the start and end of a fenced code block
|
163
178
|
:env_var: MDE_FENCED_START_AND_END_REGEX
|
164
179
|
:opt_name: fenced_start_and_end_regex
|
165
180
|
:procname: val_as_str
|
166
181
|
- :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*)
|
167
182
|
*$"
|
183
|
+
:description: Match the start of a fenced block
|
168
184
|
:env_var: MDE_FENCED_START_EXTENDED_REGEX
|
169
185
|
:opt_name: fenced_start_extended_regex
|
170
186
|
:procname: val_as_str
|
171
187
|
- :arg_name: RELATIVE_PATH
|
172
188
|
:compreply: "."
|
173
|
-
:description: Name of document
|
189
|
+
:description: Name of the document to load
|
174
190
|
:env_var: MDE_FILENAME
|
175
191
|
:long_name: filename
|
176
192
|
:opt_name: filename
|
@@ -182,6 +198,13 @@
|
|
182
198
|
:long_name: find
|
183
199
|
:procname: find
|
184
200
|
:short_name: "?"
|
201
|
+
- :arg_name: FIND_PATH
|
202
|
+
:default: ''
|
203
|
+
:description: Path for find (uses PATH if empty)
|
204
|
+
:env_var: MDE_FIND_PATH
|
205
|
+
:long_name: find-path
|
206
|
+
:opt_name: find_path
|
207
|
+
:procname: val_as_str
|
185
208
|
- :default: "^# *(?<name>[^#]*?) *$"
|
186
209
|
:env_var: MDE_HEADING1_MATCH
|
187
210
|
:opt_name: heading1_match
|
@@ -286,7 +309,8 @@
|
|
286
309
|
:procname: val_as_bool
|
287
310
|
- :arg_name: BOOL
|
288
311
|
:default: false
|
289
|
-
:description:
|
312
|
+
:description: Controls whether headings(levels 1,2,3) are displayed in the block
|
313
|
+
selection menu
|
290
314
|
:env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
|
291
315
|
:opt_name: menu_blocks_with_headings
|
292
316
|
:procname: val_as_bool
|
@@ -345,7 +369,7 @@
|
|
345
369
|
:procname: val_as_bool
|
346
370
|
- :arg_name: BOOL
|
347
371
|
:default: false
|
348
|
-
:description:
|
372
|
+
:description: Whether imported blocks should be included in the menu
|
349
373
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
350
374
|
:opt_name: menu_include_imported_notes
|
351
375
|
:procname: val_as_bool
|
@@ -497,7 +521,7 @@
|
|
497
521
|
:procname: val_as_bool
|
498
522
|
- :arg_name: BOOL
|
499
523
|
:default: true
|
500
|
-
:description:
|
524
|
+
:description: Whether standard output from execution is displayed
|
501
525
|
:env_var: MDE_OUTPUT_STDOUT
|
502
526
|
:long_name: output-stdout
|
503
527
|
:opt_name: output_stdout
|
@@ -516,15 +540,15 @@
|
|
516
540
|
:short_name: p
|
517
541
|
- :arg_name: BOOL
|
518
542
|
:default: true
|
519
|
-
:description:
|
520
|
-
:env_var:
|
543
|
+
:description: Wheter to pause after manually executing a block and the next menu
|
544
|
+
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
521
545
|
:opt_name: pause_after_script_execution
|
522
546
|
:procname: val_as_bool
|
523
547
|
- :default: |2-
|
524
548
|
|
525
549
|
Continue?
|
526
|
-
:description: Prompt after
|
527
|
-
:env_var:
|
550
|
+
:description: Prompt after manually executing a block and the next menu
|
551
|
+
:env_var: MDE_PROMPT_AFTER_SCRIPT_EXECUTION
|
528
552
|
:opt_name: prompt_after_script_execution
|
529
553
|
:procname: val_as_str
|
530
554
|
- :default: |2-
|
@@ -601,7 +625,7 @@
|
|
601
625
|
:procname: val_as_int
|
602
626
|
- :arg_name: BOOL
|
603
627
|
:default: false
|
604
|
-
:description:
|
628
|
+
:description: Wheter to save an executed script`
|
605
629
|
:env_var: MDE_SAVE_EXECUTED_SCRIPT
|
606
630
|
:long_name: save-executed-script
|
607
631
|
:opt_name: save_executed_script
|
@@ -637,7 +661,7 @@
|
|
637
661
|
:procname: val_as_str
|
638
662
|
- :arg_name: RELATIVE_PATH
|
639
663
|
:default: logs
|
640
|
-
:description:
|
664
|
+
:description: Folder where saved scripts are stored
|
641
665
|
:env_var: MDE_SAVED_SCRIPT_FOLDER
|
642
666
|
:long_name: saved-script-folder
|
643
667
|
:opt_name: saved_script_folder
|
@@ -746,7 +770,7 @@
|
|
746
770
|
:procname: val_as_bool
|
747
771
|
- :arg_name: BOOL
|
748
772
|
:default: true
|
749
|
-
:description:
|
773
|
+
:description: Requires user approval before executing a script
|
750
774
|
:env_var: MDE_USER_MUST_APPROVE
|
751
775
|
:long_name: user-must-approve
|
752
776
|
:opt_name: user_must_approve
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# encoding=utf-8
|
5
|
+
|
6
|
+
require 'find'
|
7
|
+
|
8
|
+
class RegexpReplacer
|
9
|
+
# Constructor to initialize with file path
|
10
|
+
def initialize(file_path)
|
11
|
+
@file_path = file_path
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform the replacement based on the specified option
|
15
|
+
def perform_replacement(option)
|
16
|
+
content = File.read(@file_path)
|
17
|
+
modified_content = case option
|
18
|
+
when 1
|
19
|
+
replace_pattern1(content)
|
20
|
+
when 2
|
21
|
+
replace_pattern2(content)
|
22
|
+
else
|
23
|
+
raise "Invalid option. Please choose 1 or 2."
|
24
|
+
end
|
25
|
+
File.write(@file_path, modified_content)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Replacement for pattern 1
|
31
|
+
def replace_pattern1(content)
|
32
|
+
regexp = /^( *)# (@\w+) ('.+)/
|
33
|
+
substitution = '\1;;pp __LINE__,\3 #\2'
|
34
|
+
content.gsub(regexp, substitution)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Replacement for pattern 2
|
38
|
+
def replace_pattern2(content)
|
39
|
+
regexp = /^( *);;pp __LINE__,(.+) #(@\w+)/
|
40
|
+
substitution = '\1# \3 \2'
|
41
|
+
content.gsub(regexp, substitution)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Running the script with command line arguments
|
46
|
+
if ARGV.length != 2
|
47
|
+
puts "Usage: ruby regexp_replacer.rb [file_path] [option (1 or 2)]"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
file_path, option = ARGV
|
52
|
+
replacer = RegexpReplacer.new(file_path)
|
53
|
+
begin
|
54
|
+
replacer.perform_replacement(option.to_i)
|
55
|
+
puts "Replacement performed successfully."
|
56
|
+
rescue StandardError => e
|
57
|
+
puts "Error: #{e.message}"
|
58
|
+
end
|
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.8.
|
4
|
+
version: 1.8.6
|
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-12-
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- examples/import1.md
|
120
120
|
- examples/include.md
|
121
121
|
- examples/infile_config.md
|
122
|
+
- examples/linked.md
|
122
123
|
- examples/linked1.md
|
123
124
|
- examples/linked2.md
|
124
125
|
- examples/linked3.md
|
@@ -156,6 +157,7 @@ files:
|
|
156
157
|
- lib/option_value.rb
|
157
158
|
- lib/pty1.rb
|
158
159
|
- lib/regexp.rb
|
160
|
+
- lib/regexp_replacer.rb
|
159
161
|
- lib/rspec_helpers.rb
|
160
162
|
- lib/saved_assets.rb
|
161
163
|
- lib/saved_files_matcher.rb
|