markdown_exec 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -2
- data/CHANGELOG.md +27 -0
- data/Gemfile.lock +1 -1
- data/bin/tab_completion.sh +2 -2
- data/examples/interrupt.md +9 -0
- data/examples/line-wrapping.md +17 -0
- data/examples/nickname.md +46 -9
- data/examples/pause-after-execution.md +9 -0
- data/lib/colorize.rb +25 -0
- data/lib/constants.rb +1 -0
- data/lib/fcb.rb +15 -0
- data/lib/hash_delegator.rb +365 -100
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +1 -0
- data/lib/mdoc.rb +9 -14
- data/lib/menu.src.yml +38 -13
- data/lib/menu.yml +26 -14
- data/lib/saved_assets.rb +4 -3
- metadata +5 -2
data/lib/markdown_exec.rb
CHANGED
@@ -749,6 +749,7 @@ module MarkdownExec
|
|
749
749
|
def select_option_or_exit(prompt_text, strings, opts = {})
|
750
750
|
result = @options.select_option_with_metadata(prompt_text, strings,
|
751
751
|
opts)
|
752
|
+
### 2024-04-20 what for?
|
752
753
|
# return unless result.fetch(:option, nil)
|
753
754
|
|
754
755
|
result[:selected]
|
data/lib/mdoc.rb
CHANGED
@@ -72,11 +72,10 @@ module MarkdownExec
|
|
72
72
|
#
|
73
73
|
def collect_block_dependencies(anyname:)
|
74
74
|
name_block = get_block_by_anyname(anyname)
|
75
|
-
if name_block.nil? || name_block.keys.empty?
|
76
|
-
|
77
|
-
|
75
|
+
raise "Named code block `#{anyname}` not found. (@#{__LINE__})" if name_block.nil? || name_block.keys.empty?
|
76
|
+
|
77
|
+
nickname = name_block.pub_name
|
78
78
|
|
79
|
-
nickname = name_block[:nickname] || name_block[:oname]
|
80
79
|
dependencies = collect_dependencies(nickname)
|
81
80
|
# &bc 'dependencies.count:',dependencies.count
|
82
81
|
all_dependency_names = collect_unique_names(dependencies).push(nickname).uniq
|
@@ -85,9 +84,7 @@ module MarkdownExec
|
|
85
84
|
# select non-chrome blocks in order of appearance in source documents
|
86
85
|
#
|
87
86
|
blocks = @table.select do |fcb|
|
88
|
-
!fcb.fetch(:chrome,
|
89
|
-
false) && all_dependency_names.include?(fcb.fetch(:nickname,
|
90
|
-
nil) || fcb.fetch(:oname))
|
87
|
+
!fcb.fetch(:chrome, false) && all_dependency_names.include?(fcb.pub_name)
|
91
88
|
end
|
92
89
|
# &bc 'blocks.count:',blocks.count
|
93
90
|
|
@@ -95,7 +92,7 @@ module MarkdownExec
|
|
95
92
|
#
|
96
93
|
unmet_dependencies = all_dependency_names.dup
|
97
94
|
blocks = blocks.map do |fcb|
|
98
|
-
unmet_dependencies.delete(fcb
|
95
|
+
unmet_dependencies.delete(fcb.pub_name) # may not exist if block name is duplicated
|
99
96
|
if (call = fcb[:call])
|
100
97
|
[get_block_by_anyname("[#{call.match(/^%\((\S+) |\)/)[1]}]")
|
101
98
|
.merge({ cann: call })]
|
@@ -124,7 +121,7 @@ module MarkdownExec
|
|
124
121
|
# &bc 'blocks.count:',blocks.count
|
125
122
|
|
126
123
|
block_search.merge(
|
127
|
-
{ block_names: blocks.map
|
124
|
+
{ block_names: blocks.map(&:pub_name),
|
128
125
|
code: blocks.map do |fcb|
|
129
126
|
if fcb[:cann]
|
130
127
|
collect_block_code_cann(fcb)
|
@@ -136,7 +133,7 @@ module MarkdownExec
|
|
136
133
|
elsif fcb[:shell] == BlockType::PORT
|
137
134
|
collect_block_code_shell(fcb)
|
138
135
|
elsif label_body
|
139
|
-
block_name_for_bash_comment =
|
136
|
+
block_name_for_bash_comment = fcb.pub_name.gsub(/\s+/, '_')
|
140
137
|
[label_format_above && format(label_format_above,
|
141
138
|
block_source.merge({ block_name: block_name_for_bash_comment }))] +
|
142
139
|
fcb[:body] +
|
@@ -198,7 +195,7 @@ module MarkdownExec
|
|
198
195
|
|
199
196
|
### hide rows correctly
|
200
197
|
|
201
|
-
|
198
|
+
unless options[:menu_include_imported_blocks]
|
202
199
|
selrows = selrows.reject do |block|
|
203
200
|
block.fetch(:depth, 0).positive?
|
204
201
|
end
|
@@ -287,9 +284,7 @@ module MarkdownExec
|
|
287
284
|
return memo if memo.keys.include? source
|
288
285
|
|
289
286
|
block = get_block_by_anyname(source)
|
290
|
-
if block.nil? || block.keys.empty?
|
291
|
-
raise "Named code block `#{source}` not found. (@#{__LINE__})"
|
292
|
-
end
|
287
|
+
raise "Named code block `#{source}` not found. (@#{__LINE__})" if block.nil? || block.keys.empty?
|
293
288
|
|
294
289
|
memo[source] = block[:reqs]
|
295
290
|
return memo unless memo[source]&.count&.positive?
|
data/lib/menu.src.yml
CHANGED
@@ -106,6 +106,12 @@
|
|
106
106
|
:opt_name: display_level_xbase_prefix
|
107
107
|
:procname: val_as_str
|
108
108
|
|
109
|
+
# - :default: "(document_link)"
|
110
|
+
# :description: Name of Link block to load with the document
|
111
|
+
# :env_var: MDE_DOCUMENT_LOAD_LINK_BLOCK_NAME
|
112
|
+
# :opt_name: document_load_link_block_name
|
113
|
+
# :procname: val_as_str
|
114
|
+
|
109
115
|
- :default: "(document_options)"
|
110
116
|
:description: Name of Opts block to load with the document
|
111
117
|
:env_var: MDE_DOCUMENT_LOAD_OPTS_BLOCK_NAME
|
@@ -227,6 +233,8 @@
|
|
227
233
|
:opt_name: exclude_expect_blocks
|
228
234
|
:procname: val_as_bool
|
229
235
|
|
236
|
+
# - :default: >
|
237
|
+
# osascript scripts/applescript/mde.applescript "%{batch_index}" "%{home}" " %{started_at} - %{document_filename} - %{block_name} " "%{script_filespec}" "%{output_filespec}"
|
230
238
|
- :default: >
|
231
239
|
osascript -e '
|
232
240
|
on run argv
|
@@ -328,17 +336,17 @@
|
|
328
336
|
:opt_name: find_path
|
329
337
|
:procname: val_as_str
|
330
338
|
|
331
|
-
- :default: "^# *(?<
|
339
|
+
- :default: "^#(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
332
340
|
:env_var: MDE_HEADING1_MATCH
|
333
341
|
:opt_name: heading1_match
|
334
342
|
:procname: val_as_str
|
335
343
|
|
336
|
-
- :default: "^## *(?<
|
344
|
+
- :default: "^##(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
337
345
|
:env_var: MDE_HEADING2_MATCH
|
338
346
|
:opt_name: heading2_match
|
339
347
|
:procname: val_as_str
|
340
348
|
|
341
|
-
- :default: "^### *(?<
|
349
|
+
- :default: "^###(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
342
350
|
:env_var: MDE_HEADING3_MATCH
|
343
351
|
:opt_name: heading3_match
|
344
352
|
:procname: val_as_str
|
@@ -496,7 +504,7 @@
|
|
496
504
|
:opt_name: menu_divider_format
|
497
505
|
:procname: val_as_str
|
498
506
|
|
499
|
-
- :default: "^:::
|
507
|
+
- :default: "^:::(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
500
508
|
:description: Pattern for topics/dividers in block selection menu
|
501
509
|
:env_var: MDE_MENU_DIVIDER_MATCH
|
502
510
|
:opt_name: menu_divider_match
|
@@ -529,37 +537,40 @@
|
|
529
537
|
:opt_name: menu_final_divider
|
530
538
|
:procname: val_as_str
|
531
539
|
|
532
|
-
- :default:
|
540
|
+
- :default: fg_bg_rgbh_80_80_c0_10_10_20
|
533
541
|
:description: Color for heading 1 in menu
|
534
542
|
:env_var: MDE_MENU_HEADING1_COLOR
|
535
543
|
:opt_name: menu_heading1_color
|
536
544
|
:procname: val_as_str
|
537
545
|
|
538
|
-
|
546
|
+
# strip heading tag
|
547
|
+
- :default: "%{line}"
|
539
548
|
:description: format for menu heading1 in menu
|
540
549
|
:env_var: MDE_MENU_HEADING1_FORMAT
|
541
550
|
:opt_name: menu_heading1_format
|
542
551
|
:procname: val_as_str
|
543
552
|
|
544
|
-
- :default:
|
553
|
+
- :default: fg_bg_rgbh_60_60_c0_10_10_20
|
545
554
|
:description: Color for heading 2 in menu
|
546
555
|
:env_var: MDE_MENU_HEADING2_COLOR
|
547
556
|
:opt_name: menu_heading2_color
|
548
557
|
:procname: val_as_str
|
549
558
|
|
550
|
-
|
559
|
+
# strip heading tag
|
560
|
+
- :default: "%{line}"
|
551
561
|
:description: format for menu heading2 in menu
|
552
562
|
:env_var: MDE_MENU_HEADING2_FORMAT
|
553
563
|
:opt_name: menu_heading2_format
|
554
564
|
:procname: val_as_str
|
555
565
|
|
556
|
-
- :default:
|
566
|
+
- :default: fg_bg_rgbh_40_40_c0_10_10_20
|
557
567
|
:description: Color for heading 3 in menu
|
558
568
|
:env_var: MDE_MENU_HEADING3_COLOR
|
559
569
|
:opt_name: menu_heading3_color
|
560
570
|
:procname: val_as_str
|
561
571
|
|
562
|
-
|
572
|
+
# strip heading tag
|
573
|
+
- :default: "%{line}"
|
563
574
|
:description: format for menu heading3 in menu
|
564
575
|
:env_var: MDE_MENU_HEADING3_FORMAT
|
565
576
|
:opt_name: menu_heading3_format
|
@@ -624,7 +635,7 @@
|
|
624
635
|
:opt_name: menu_link_format
|
625
636
|
:procname: val_as_str
|
626
637
|
|
627
|
-
- :default:
|
638
|
+
- :default: fg_rgbh_c0_c0_c0
|
628
639
|
:description: Color of menu note
|
629
640
|
:env_var: MDE_MENU_NOTE_COLOR
|
630
641
|
:opt_name: menu_note_color
|
@@ -637,7 +648,7 @@
|
|
637
648
|
:procname: val_as_str
|
638
649
|
|
639
650
|
## all lines that do not start with "/ " are notes
|
640
|
-
- :default: "^(?<line>(?!/ )
|
651
|
+
- :default: "^(?<line>(?!/ )(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
641
652
|
:description: Pattern for notes in block selection menu
|
642
653
|
:env_var: MDE_MENU_NOTE_MATCH
|
643
654
|
:opt_name: menu_note_match
|
@@ -678,6 +689,13 @@
|
|
678
689
|
:opt_name: menu_option_save_name
|
679
690
|
:procname: val_as_str
|
680
691
|
|
692
|
+
- :default:
|
693
|
+
:line: "! Shell"
|
694
|
+
:description: Text for Shell option
|
695
|
+
:env_var: MDE_MENU_OPTION_SHELL_NAME
|
696
|
+
:opt_name: menu_option_shell_name
|
697
|
+
:procname: val_as_str
|
698
|
+
|
681
699
|
- :default:
|
682
700
|
:line: "* View"
|
683
701
|
:description: Text for View option
|
@@ -772,6 +790,13 @@
|
|
772
790
|
:opt_name: menu_with_inherited_lines
|
773
791
|
:procname: val_as_bool
|
774
792
|
|
793
|
+
- :arg_name: BOOL
|
794
|
+
:default: true
|
795
|
+
:description: Display Shell option in menu
|
796
|
+
:env_var: MDE_MENU_WITH_SHELL
|
797
|
+
:opt_name: menu_with_shell
|
798
|
+
:procname: val_as_bool
|
799
|
+
|
775
800
|
- :arg_name: BOOL
|
776
801
|
:default: false
|
777
802
|
:description: Hide decorative menu entries
|
@@ -874,7 +899,7 @@
|
|
874
899
|
|
875
900
|
- :arg_name: BOOL
|
876
901
|
:default: false
|
877
|
-
:description:
|
902
|
+
:description: Whether to pause after manually executing a block and the next menu
|
878
903
|
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
879
904
|
:opt_name: pause_after_script_execution
|
880
905
|
:procname: val_as_bool
|
data/lib/menu.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MDE - Markdown Executor (2.0.
|
1
|
+
# MDE - Markdown Executor (2.0.7)
|
2
2
|
---
|
3
3
|
- :description: Show current configuration values
|
4
4
|
:procname: show_config
|
@@ -285,15 +285,15 @@
|
|
285
285
|
:long_name: find-path
|
286
286
|
:opt_name: find_path
|
287
287
|
:procname: val_as_str
|
288
|
-
- :default: "^# *(?<
|
288
|
+
- :default: "^#(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
289
289
|
:env_var: MDE_HEADING1_MATCH
|
290
290
|
:opt_name: heading1_match
|
291
291
|
:procname: val_as_str
|
292
|
-
- :default: "^## *(?<
|
292
|
+
- :default: "^##(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
293
293
|
:env_var: MDE_HEADING2_MATCH
|
294
294
|
:opt_name: heading2_match
|
295
295
|
:procname: val_as_str
|
296
|
-
- :default: "^### *(?<
|
296
|
+
- :default: "^###(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
297
297
|
:env_var: MDE_HEADING3_MATCH
|
298
298
|
:opt_name: heading3_match
|
299
299
|
:procname: val_as_str
|
@@ -425,7 +425,7 @@
|
|
425
425
|
:env_var: MDE_MENU_DIVIDER_FORMAT
|
426
426
|
:opt_name: menu_divider_format
|
427
427
|
:procname: val_as_str
|
428
|
-
- :default: "^:::
|
428
|
+
- :default: "^:::(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
429
429
|
:description: Pattern for topics/dividers in block selection menu
|
430
430
|
:env_var: MDE_MENU_DIVIDER_MATCH
|
431
431
|
:opt_name: menu_divider_match
|
@@ -453,32 +453,32 @@
|
|
453
453
|
:env_var: MDE_MENU_FINAL_DIVIDER
|
454
454
|
:opt_name: menu_final_divider
|
455
455
|
:procname: val_as_str
|
456
|
-
- :default:
|
456
|
+
- :default: fg_bg_rgbh_80_80_c0_10_10_20
|
457
457
|
:description: Color for heading 1 in menu
|
458
458
|
:env_var: MDE_MENU_HEADING1_COLOR
|
459
459
|
:opt_name: menu_heading1_color
|
460
460
|
:procname: val_as_str
|
461
|
-
- :default: "
|
461
|
+
- :default: "%{line}"
|
462
462
|
:description: format for menu heading1 in menu
|
463
463
|
:env_var: MDE_MENU_HEADING1_FORMAT
|
464
464
|
:opt_name: menu_heading1_format
|
465
465
|
:procname: val_as_str
|
466
|
-
- :default:
|
466
|
+
- :default: fg_bg_rgbh_60_60_c0_10_10_20
|
467
467
|
:description: Color for heading 2 in menu
|
468
468
|
:env_var: MDE_MENU_HEADING2_COLOR
|
469
469
|
:opt_name: menu_heading2_color
|
470
470
|
:procname: val_as_str
|
471
|
-
- :default: "
|
471
|
+
- :default: "%{line}"
|
472
472
|
:description: format for menu heading2 in menu
|
473
473
|
:env_var: MDE_MENU_HEADING2_FORMAT
|
474
474
|
:opt_name: menu_heading2_format
|
475
475
|
:procname: val_as_str
|
476
|
-
- :default:
|
476
|
+
- :default: fg_bg_rgbh_40_40_c0_10_10_20
|
477
477
|
:description: Color for heading 3 in menu
|
478
478
|
:env_var: MDE_MENU_HEADING3_COLOR
|
479
479
|
:opt_name: menu_heading3_color
|
480
480
|
:procname: val_as_str
|
481
|
-
- :default: "
|
481
|
+
- :default: "%{line}"
|
482
482
|
:description: format for menu heading3 in menu
|
483
483
|
:env_var: MDE_MENU_HEADING3_FORMAT
|
484
484
|
:opt_name: menu_heading3_format
|
@@ -532,7 +532,7 @@
|
|
532
532
|
:env_var: MDE_MENU_LINK_FORMAT
|
533
533
|
:opt_name: menu_link_format
|
534
534
|
:procname: val_as_str
|
535
|
-
- :default:
|
535
|
+
- :default: fg_rgbh_c0_c0_c0
|
536
536
|
:description: Color of menu note
|
537
537
|
:env_var: MDE_MENU_NOTE_COLOR
|
538
538
|
:opt_name: menu_note_color
|
@@ -542,7 +542,7 @@
|
|
542
542
|
:env_var: MDE_MENU_NOTE_FORMAT
|
543
543
|
:opt_name: menu_note_format
|
544
544
|
:procname: val_as_str
|
545
|
-
- :default: "^(?<line>(?!/ )
|
545
|
+
- :default: "^(?<line>(?!/ )(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
546
546
|
:description: Pattern for notes in block selection menu
|
547
547
|
:env_var: MDE_MENU_NOTE_MATCH
|
548
548
|
:opt_name: menu_note_match
|
@@ -577,6 +577,12 @@
|
|
577
577
|
:env_var: MDE_MENU_OPTION_SAVE_NAME
|
578
578
|
:opt_name: menu_option_save_name
|
579
579
|
:procname: val_as_str
|
580
|
+
- :default:
|
581
|
+
:line: "! Shell"
|
582
|
+
:description: Text for Shell option
|
583
|
+
:env_var: MDE_MENU_OPTION_SHELL_NAME
|
584
|
+
:opt_name: menu_option_shell_name
|
585
|
+
:procname: val_as_str
|
580
586
|
- :default:
|
581
587
|
:line: "* View"
|
582
588
|
:description: Text for View option
|
@@ -656,6 +662,12 @@
|
|
656
662
|
:env_var: MDE_MENU_WITH_INHERITED_LINES
|
657
663
|
:opt_name: menu_with_inherited_lines
|
658
664
|
:procname: val_as_bool
|
665
|
+
- :arg_name: BOOL
|
666
|
+
:default: true
|
667
|
+
:description: Display Shell option in menu
|
668
|
+
:env_var: MDE_MENU_WITH_SHELL
|
669
|
+
:opt_name: menu_with_shell
|
670
|
+
:procname: val_as_bool
|
659
671
|
- :arg_name: BOOL
|
660
672
|
:default: false
|
661
673
|
:description: Hide decorative menu entries
|
@@ -743,7 +755,7 @@
|
|
743
755
|
:short_name: p
|
744
756
|
- :arg_name: BOOL
|
745
757
|
:default: false
|
746
|
-
:description:
|
758
|
+
:description: Whether to pause after manually executing a block and the next menu
|
747
759
|
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
748
760
|
:opt_name: pause_after_script_execution
|
749
761
|
:procname: val_as_bool
|
data/lib/saved_assets.rb
CHANGED
@@ -12,7 +12,8 @@ module MarkdownExec
|
|
12
12
|
# method derives a name for stdout redirection.
|
13
13
|
#
|
14
14
|
class SavedAsset
|
15
|
-
FNR11 = %r{
|
15
|
+
FNR11 = %r{[^!#$%&()\+,\-0-9=A-Z_a-z~]}.freeze
|
16
|
+
# / !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
16
17
|
FNR12 = '_'
|
17
18
|
DEFAULT_FTIME = '%F-%H-%M-%S'
|
18
19
|
|
@@ -43,7 +44,7 @@ class SavedAssetTest < Minitest::Test
|
|
43
44
|
time = Time.new(2023, 1, 1, 12, 0, 0)
|
44
45
|
blockname = 'block/1:2'
|
45
46
|
|
46
|
-
expected_name = 'test_2023-01-01-12-00-
|
47
|
+
expected_name = 'test_2023-01-01-12-00-00_sample_txt_,_block_1_2.sh'
|
47
48
|
assert_equal expected_name, MarkdownExec::SavedAsset.script_name(
|
48
49
|
filename: filename, prefix: prefix, time: time, blockname: blockname
|
49
50
|
)
|
@@ -55,7 +56,7 @@ class SavedAssetTest < Minitest::Test
|
|
55
56
|
time = Time.new(2023, 1, 1, 12, 0, 0)
|
56
57
|
blockname = 'block/1:2'
|
57
58
|
|
58
|
-
expected_name = 'test_2023-01-01-12-00-
|
59
|
+
expected_name = 'test_2023-01-01-12-00-00_sample_txt_,_block_1_2.out.txt'
|
59
60
|
assert_equal expected_name, MarkdownExec::SavedAsset.stdout_name(
|
60
61
|
filename: filename, prefix: prefix, time: time, blockname: blockname
|
61
62
|
)
|
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: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05
|
11
|
+
date: 2024-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -122,6 +122,8 @@ files:
|
|
122
122
|
- examples/include.md
|
123
123
|
- examples/indent.md
|
124
124
|
- examples/index.md
|
125
|
+
- examples/interrupt.md
|
126
|
+
- examples/line-wrapping.md
|
125
127
|
- examples/linked.md
|
126
128
|
- examples/linked1.md
|
127
129
|
- examples/linked2.md
|
@@ -134,6 +136,7 @@ files:
|
|
134
136
|
- examples/nickname.md
|
135
137
|
- examples/opts.md
|
136
138
|
- examples/pass-through.md
|
139
|
+
- examples/pause-after-execution.md
|
137
140
|
- examples/plant.md
|
138
141
|
- examples/port.md
|
139
142
|
- examples/search.md
|