markdown_exec 1.8.6 → 1.8.7

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.
@@ -7,5 +7,5 @@ module MarkdownExec
7
7
  BIN_NAME = 'mde'
8
8
  GEM_NAME = 'markdown_exec'
9
9
  TAP_DEBUG = 'MDE_DEBUG'
10
- VERSION = '1.8.6'
10
+ VERSION = '1.8.7'
11
11
  end
data/lib/mdoc.rb CHANGED
@@ -23,6 +23,7 @@ module MarkdownExec
23
23
  #
24
24
  def initialize(table = [])
25
25
  @table = table
26
+ # &bc '@table.count:',@table.count
26
27
  end
27
28
 
28
29
  def collect_block_code_cann(fcb)
@@ -69,20 +70,28 @@ module MarkdownExec
69
70
  # @param name [String] The name of the code block to start the retrieval from.
70
71
  # @return [Array<Hash>] An array of code blocks required by the specified code block.
71
72
  #
72
- def collect_recursively_required_blocks(name)
73
+ def collect_block_dependencies(name)
73
74
  name_block = get_block_by_anyname(name)
74
75
  if name_block.nil? || name_block.keys.empty?
75
76
  raise "Named code block `#{name}` not found. (@#{__LINE__})"
76
77
  end
77
78
 
78
79
  dependencies = collect_dependencies(name_block[:oname])
80
+ # &bc 'dependencies.count:',dependencies.count
79
81
  all_dependency_names = collect_unique_names(dependencies).push(name_block[:oname]).uniq
80
- unmet_dependencies = all_dependency_names.dup
82
+ # &bc 'all_dependency_names.count:',all_dependency_names.count
81
83
 
82
- # in order of appearance in document (@table)
83
- # insert function blocks
84
- blocks = @table.select { |fcb| all_dependency_names.include? fcb[:oname] }
85
- .map do |fcb|
84
+ # select non-chrome blocks in order of appearance in source documents
85
+ #
86
+ blocks = @table.select do |fcb|
87
+ !fcb.fetch(:chrome, false) && all_dependency_names.include?(fcb.fetch(:oname))
88
+ end
89
+ # &bc 'blocks.count:',blocks.count
90
+
91
+ ## add cann key to blocks, calc unmet_dependencies
92
+ #
93
+ unmet_dependencies = all_dependency_names.dup
94
+ blocks = blocks.map do |fcb|
86
95
  unmet_dependencies.delete(fcb[:oname]) # may not exist if block name is duplicated
87
96
  if (call = fcb[:call])
88
97
  [get_block_by_oname("[#{call.match(/^%\((\S+) |\)/)[1]}]")
@@ -91,6 +100,7 @@ module MarkdownExec
91
100
  []
92
101
  end + [fcb]
93
102
  end.flatten(1)
103
+ # &bc 'unmet_dependencies.count:',unmet_dependencies.count
94
104
 
95
105
  { all_dependency_names: all_dependency_names,
96
106
  blocks: blocks,
@@ -103,11 +113,13 @@ module MarkdownExec
103
113
  # @param name [String] The name of the code block to start the collection from.
104
114
  # @return [Array<String>] An array of strings containing the collected code blocks.
105
115
  #
106
- def collect_recursively_required_code(name, label_body: true, label_format_above: nil,
107
- label_format_below: nil, block_source:)
108
- block_search = collect_recursively_required_blocks(name)
116
+ def collect_recursively_required_code(name, block_source:, label_body: true, label_format_above: nil,
117
+ label_format_below: nil)
118
+ block_search = collect_block_dependencies(name)
109
119
  if block_search[:blocks]
110
120
  blocks = collect_wrapped_blocks(block_search[:blocks])
121
+ # &bc 'blocks.count:',blocks.count
122
+
111
123
  block_search.merge(
112
124
  { block_names: blocks.map { |block| block[:oname] },
113
125
  code: blocks.map do |fcb|
@@ -134,6 +146,8 @@ module MarkdownExec
134
146
  else
135
147
  block_search.merge({ block_names: [], code: [] })
136
148
  end
149
+ rescue StandardError
150
+ error_handler('collect_recursively_required_code')
137
151
  end
138
152
 
139
153
  def collect_unique_names(hash)
@@ -160,6 +174,13 @@ module MarkdownExec
160
174
  end.flatten(1).compact
161
175
  end
162
176
 
177
+ def error_handler(name = '', opts = {})
178
+ Exceptions.error_handler(
179
+ "MDoc.#{name} -- #{$!}",
180
+ opts
181
+ )
182
+ end
183
+
163
184
  # Retrieves code blocks based on the provided options.
164
185
  #
165
186
  # @param opts [Hash] The options used for filtering code blocks.
@@ -432,13 +453,13 @@ if $PROGRAM_NAME == __FILE__
432
453
  end
433
454
 
434
455
  ### broken test
435
- def test_collect_recursively_required_blocks
436
- result = @doc.collect_recursively_required_blocks('block3')[:blocks]
456
+ def test_collect_block_dependencies
457
+ result = @doc.collect_block_dependencies('block3')[:blocks]
437
458
  expected_result = [@table[0], @table[1], @table[2]]
438
459
  assert_equal expected_result, result
439
460
 
440
461
  assert_raises(RuntimeError) do
441
- @doc.collect_recursively_required_blocks('missing_block')
462
+ @doc.collect_block_dependencies('missing_block')
442
463
  end
443
464
  end
444
465
 
data/lib/menu.src.yml CHANGED
@@ -238,17 +238,17 @@
238
238
  :opt_name: find_path
239
239
  :procname: val_as_str
240
240
 
241
- - :default: "^# *(?<name>[^#]*?) *$"
241
+ - :default: "^# *(?<line>[^#]*?) *$"
242
242
  :env_var: MDE_HEADING1_MATCH
243
243
  :opt_name: heading1_match
244
244
  :procname: val_as_str
245
245
 
246
- - :default: "^## *(?<name>[^#]*?) *$"
246
+ - :default: "^## *(?<line>[^#]*?) *$"
247
247
  :env_var: MDE_HEADING2_MATCH
248
248
  :opt_name: heading2_match
249
249
  :procname: val_as_str
250
250
 
251
- - :default: "^### *(?<name>.+?) *$"
251
+ - :default: "^### *(?<line>.+?) *$"
252
252
  :env_var: MDE_HEADING3_MATCH
253
253
  :opt_name: heading3_match
254
254
  :procname: val_as_str
@@ -363,7 +363,7 @@
363
363
  :procname: val_as_bool
364
364
 
365
365
  - :arg_name: BOOL
366
- :default: false
366
+ :default: true
367
367
  :description: Controls whether headings(levels 1,2,3) are displayed in the block selection menu
368
368
  :env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
369
369
  :opt_name: menu_blocks_with_headings
@@ -419,6 +419,42 @@
419
419
  :opt_name: menu_final_divider
420
420
  :procname: val_as_str
421
421
 
422
+ - :default: fg_rgbh_80_80_c0
423
+ :description: Color for heading 1 in menu
424
+ :env_var: MDE_MENU_HEADING1_COLOR
425
+ :opt_name: menu_heading1_color
426
+ :procname: val_as_str
427
+
428
+ - :default: "# %{line}"
429
+ :description: format for menu heading1 in menu
430
+ :env_var: MDE_MENU_HEADING1_FORMAT
431
+ :opt_name: menu_heading1_format
432
+ :procname: val_as_str
433
+
434
+ - :default: fg_rgbh_60_60_c0
435
+ :description: Color for heading 2 in menu
436
+ :env_var: MDE_MENU_HEADING2_COLOR
437
+ :opt_name: menu_heading2_color
438
+ :procname: val_as_str
439
+
440
+ - :default: "## %{line}"
441
+ :description: format for menu heading2 in menu
442
+ :env_var: MDE_MENU_HEADING2_FORMAT
443
+ :opt_name: menu_heading2_format
444
+ :procname: val_as_str
445
+
446
+ - :default: fg_rgbh_40_40_c0
447
+ :description: Color for heading 3 in menu
448
+ :env_var: MDE_MENU_HEADING3_COLOR
449
+ :opt_name: menu_heading3_color
450
+ :procname: val_as_str
451
+
452
+ - :default: "### %{line}"
453
+ :description: format for menu heading3 in menu
454
+ :env_var: MDE_MENU_HEADING3_FORMAT
455
+ :opt_name: menu_heading3_format
456
+ :procname: val_as_str
457
+
422
458
  - :default: "0"
423
459
  :description: Import levels for blocks to appear in menu. Empty is all.
424
460
  :env_var: MDE_MENU_IMPORT_LEVEL_MATCH
@@ -440,6 +476,25 @@
440
476
  :opt_name: menu_include_imported_notes
441
477
  :procname: val_as_bool
442
478
 
479
+ - :arg_name: BOOL
480
+ :default: true
481
+ :description: Display inherited lines at top of menu (vs bottom)
482
+ :env_var: MDE_MENU_INHERITED_LINES_AT_TOP
483
+ :opt_name: menu_inherited_lines_at_top
484
+ :procname: val_as_bool
485
+
486
+ - :default: fg_rgbh_94_00_D3
487
+ :description: Color of inherited lines in menu
488
+ :env_var: MDE_MENU_INHERITED_LINES_COLOR
489
+ :opt_name: menu_inherited_lines_color
490
+ :procname: val_as_str
491
+
492
+ - :default: "%{line}"
493
+ :description: format for inherited lines in menu
494
+ :env_var: MDE_MENU_INHERITED_LINES_FORMAT
495
+ :opt_name: menu_inherited_lines_format
496
+ :procname: val_as_str
497
+
443
498
  - :default:
444
499
  :line: ""
445
500
  :description: opening demarcation for menu
@@ -511,6 +566,12 @@
511
566
  :opt_name: menu_opts_set_format
512
567
  :procname: val_as_str
513
568
 
569
+ - :default: "."
570
+ :description: Block name to display menu
571
+ :env_var: MDE_MENU_PERSIST_BLOCK_NAME
572
+ :opt_name: menu_persist_block_name
573
+ :procname: val_as_str
574
+
514
575
  - :default: fg_rgbh_ff_ff_ff
515
576
  :description: Color of menu task
516
577
  :env_var: MDE_MENU_TASK_COLOR
@@ -567,6 +628,13 @@
567
628
  :opt_name: menu_with_exit
568
629
  :procname: val_as_bool
569
630
 
631
+ - :arg_name: BOOL
632
+ :default: true
633
+ :description: Display inherited lines in menu
634
+ :env_var: MDE_MENU_WITH_INHERITED_LINES
635
+ :opt_name: menu_with_inherited_lines
636
+ :procname: val_as_bool
637
+
570
638
  - :arg_name: BOOL
571
639
  :default: false
572
640
  :description: Hide decorative menu entries
data/lib/menu.yml CHANGED
@@ -1,4 +1,4 @@
1
- # MDE - Markdown Executor (1.8.6)
1
+ # MDE - Markdown Executor (1.8.7)
2
2
  ---
3
3
  - :description: Show current configuration values
4
4
  :procname: show_config
@@ -205,15 +205,15 @@
205
205
  :long_name: find-path
206
206
  :opt_name: find_path
207
207
  :procname: val_as_str
208
- - :default: "^# *(?<name>[^#]*?) *$"
208
+ - :default: "^# *(?<line>[^#]*?) *$"
209
209
  :env_var: MDE_HEADING1_MATCH
210
210
  :opt_name: heading1_match
211
211
  :procname: val_as_str
212
- - :default: "^## *(?<name>[^#]*?) *$"
212
+ - :default: "^## *(?<line>[^#]*?) *$"
213
213
  :env_var: MDE_HEADING2_MATCH
214
214
  :opt_name: heading2_match
215
215
  :procname: val_as_str
216
- - :default: "^### *(?<name>.+?) *$"
216
+ - :default: "^### *(?<line>.+?) *$"
217
217
  :env_var: MDE_HEADING3_MATCH
218
218
  :opt_name: heading3_match
219
219
  :procname: val_as_str
@@ -308,7 +308,7 @@
308
308
  :opt_name: menu_blocks_with_docname
309
309
  :procname: val_as_bool
310
310
  - :arg_name: BOOL
311
- :default: false
311
+ :default: true
312
312
  :description: Controls whether headings(levels 1,2,3) are displayed in the block
313
313
  selection menu
314
314
  :env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
@@ -356,6 +356,36 @@
356
356
  :env_var: MDE_MENU_FINAL_DIVIDER
357
357
  :opt_name: menu_final_divider
358
358
  :procname: val_as_str
359
+ - :default: fg_rgbh_80_80_c0
360
+ :description: Color for heading 1 in menu
361
+ :env_var: MDE_MENU_HEADING1_COLOR
362
+ :opt_name: menu_heading1_color
363
+ :procname: val_as_str
364
+ - :default: "# %{line}"
365
+ :description: format for menu heading1 in menu
366
+ :env_var: MDE_MENU_HEADING1_FORMAT
367
+ :opt_name: menu_heading1_format
368
+ :procname: val_as_str
369
+ - :default: fg_rgbh_60_60_c0
370
+ :description: Color for heading 2 in menu
371
+ :env_var: MDE_MENU_HEADING2_COLOR
372
+ :opt_name: menu_heading2_color
373
+ :procname: val_as_str
374
+ - :default: "## %{line}"
375
+ :description: format for menu heading2 in menu
376
+ :env_var: MDE_MENU_HEADING2_FORMAT
377
+ :opt_name: menu_heading2_format
378
+ :procname: val_as_str
379
+ - :default: fg_rgbh_40_40_c0
380
+ :description: Color for heading 3 in menu
381
+ :env_var: MDE_MENU_HEADING3_COLOR
382
+ :opt_name: menu_heading3_color
383
+ :procname: val_as_str
384
+ - :default: "### %{line}"
385
+ :description: format for menu heading3 in menu
386
+ :env_var: MDE_MENU_HEADING3_FORMAT
387
+ :opt_name: menu_heading3_format
388
+ :procname: val_as_str
359
389
  - :default: '0'
360
390
  :description: Import levels for blocks to appear in menu. Empty is all.
361
391
  :env_var: MDE_MENU_IMPORT_LEVEL_MATCH
@@ -373,6 +403,22 @@
373
403
  :env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
374
404
  :opt_name: menu_include_imported_notes
375
405
  :procname: val_as_bool
406
+ - :arg_name: BOOL
407
+ :default: true
408
+ :description: Display inherited lines at top of menu (vs bottom)
409
+ :env_var: MDE_MENU_INHERITED_LINES_AT_TOP
410
+ :opt_name: menu_inherited_lines_at_top
411
+ :procname: val_as_bool
412
+ - :default: fg_rgbh_94_00_D3
413
+ :description: Color of inherited lines in menu
414
+ :env_var: MDE_MENU_INHERITED_LINES_COLOR
415
+ :opt_name: menu_inherited_lines_color
416
+ :procname: val_as_str
417
+ - :default: "%{line}"
418
+ :description: format for inherited lines in menu
419
+ :env_var: MDE_MENU_INHERITED_LINES_FORMAT
420
+ :opt_name: menu_inherited_lines_format
421
+ :procname: val_as_str
376
422
  - :default:
377
423
  :line: ''
378
424
  :description: opening demarcation for menu
@@ -431,6 +477,11 @@
431
477
  :env_var: MDE_MENU_OPTS_SET_FORMAT
432
478
  :opt_name: menu_opts_set_format
433
479
  :procname: val_as_str
480
+ - :default: "."
481
+ :description: Block name to display menu
482
+ :env_var: MDE_MENU_PERSIST_BLOCK_NAME
483
+ :opt_name: menu_persist_block_name
484
+ :procname: val_as_str
434
485
  - :default: fg_rgbh_ff_ff_ff
435
486
  :description: Color of menu task
436
487
  :env_var: MDE_MENU_TASK_COLOR
@@ -478,6 +529,12 @@
478
529
  :env_var: MDE_MENU_WITH_EXIT
479
530
  :opt_name: menu_with_exit
480
531
  :procname: val_as_bool
532
+ - :arg_name: BOOL
533
+ :default: true
534
+ :description: Display inherited lines in menu
535
+ :env_var: MDE_MENU_WITH_INHERITED_LINES
536
+ :opt_name: menu_with_inherited_lines
537
+ :procname: val_as_bool
481
538
  - :arg_name: BOOL
482
539
  :default: false
483
540
  :description: Hide decorative menu entries
@@ -15,28 +15,28 @@ class RegexpReplacer
15
15
  def perform_replacement(option)
16
16
  content = File.read(@file_path)
17
17
  modified_content = case option
18
- when 1
19
- replace_pattern1(content)
20
- when 2
21
- replace_pattern2(content)
18
+ when 'v'
19
+ verbose(content)
20
+ when 'q'
21
+ quiet(content)
22
22
  else
23
- raise "Invalid option. Please choose 1 or 2."
23
+ raise "Invalid option. Please choose 'v' or 'q'."
24
24
  end
25
25
  File.write(@file_path, modified_content)
26
26
  end
27
27
 
28
28
  private
29
29
 
30
- # Replacement for pattern 1
31
- def replace_pattern1(content)
32
- regexp = /^( *)# (@\w+) ('.+)/
33
- substitution = '\1;;pp __LINE__,\3 #\2'
30
+ # Replacement for pattern 'v'
31
+ def verbose(content)
32
+ regexp = /^( *)# (&\w+) ('.+)/
33
+ substitution = '\1;;pp [__LINE__,\3] #\2'
34
34
  content.gsub(regexp, substitution)
35
35
  end
36
36
 
37
- # Replacement for pattern 2
38
- def replace_pattern2(content)
39
- regexp = /^( *);;pp __LINE__,(.+) #(@\w+)/
37
+ # Replacement for pattern 'q'
38
+ def quiet(content)
39
+ regexp = /^( *);; ?pp \[__LINE__,(.+)\] #(&\w+)/
40
40
  substitution = '\1# \3 \2'
41
41
  content.gsub(regexp, substitution)
42
42
  end
@@ -44,14 +44,14 @@ end
44
44
 
45
45
  # Running the script with command line arguments
46
46
  if ARGV.length != 2
47
- puts "Usage: ruby regexp_replacer.rb [file_path] [option (1 or 2)]"
47
+ puts "Usage: ruby regexp_replacer.rb [file_path] [option ('v' or 'q')]"
48
48
  exit
49
49
  end
50
50
 
51
51
  file_path, option = ARGV
52
52
  replacer = RegexpReplacer.new(file_path)
53
53
  begin
54
- replacer.perform_replacement(option.to_i)
54
+ replacer.perform_replacement(option)
55
55
  puts "Replacement performed successfully."
56
56
  rescue StandardError => e
57
57
  puts "Error: #{e.message}"
data/lib/saved_assets.rb CHANGED
@@ -12,18 +12,20 @@ module MarkdownExec
12
12
  # method derives a name for stdout redirection.
13
13
  #
14
14
  class SavedAsset
15
- FNR11 = /pattern1/.freeze # TODO: Replace with actual pattern
16
- FNR12 = 'replacement_string' # TODO: Replace with actual replacement string
15
+ FNR11 = %r{/|:}.freeze
16
+ FNR12 = '_'
17
+ DEFAULT_FTIME = '%F-%H-%M-%S'
17
18
 
18
19
  # Generates a formatted script name based on the provided parameters.
19
- def self.script_name(filename:, prefix:, time:, blockname:)
20
- fne = filename.gsub(FNR11, FNR12)
21
- "#{[prefix, time.strftime('%F-%H-%M-%S'), fne, ',', blockname].join('_')}.sh"
20
+ def self.script_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.sh')
21
+ fne = filename.gsub(pattern, replace)
22
+ "#{[prefix, time.strftime(ftime), fne, ',', blockname].join(join_str)}#{exts}"
22
23
  end
23
24
 
24
25
  # Generates a formatted stdout name based on the provided parameters.
25
- def self.stdout_name(filename:, prefix:, time:, blockname:)
26
- "#{[prefix, time.strftime('%F-%H-%M-%S'), filename, blockname].join('_')}.out.txt"
26
+ def self.stdout_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.out.txt')
27
+ fne = filename.gsub(pattern, replace)
28
+ "#{[prefix, time.strftime(ftime), fne, ',', blockname].join(join_str)}#{exts}"
27
29
  end
28
30
  end
29
31
  end
@@ -50,7 +52,7 @@ if $PROGRAM_NAME == __FILE__
50
52
  time = Time.new(2023, 1, 1, 12, 0, 0)
51
53
  blockname = 'block1'
52
54
 
53
- expected_name = 'test_2023-01-01-12-00-00_sample.txt_block1.out.txt'
55
+ expected_name = 'test_2023-01-01-12-00-00_sample.txt_,_block1.out.txt'
54
56
  assert_equal expected_name,
55
57
  MarkdownExec::SavedAsset.stdout_name(filename: filename, prefix: prefix, time: time,
56
58
  blockname: blockname)
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.6
4
+ version: 1.8.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: 2023-12-26 00:00:00.000000000 Z
11
+ date: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -81,8 +81,8 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.2.0
83
83
  description: Interactively select and execute fenced code blocks in markdown files.
84
- Build complex scripts by linking documents and naming and requiring blocks. Log
85
- resulting scripts and output. Re-run scripts.
84
+ Build complex scripts by naming and requiring blocks. Log resulting scripts and
85
+ output. Re-run scripts.
86
86
  email:
87
87
  - fareed@phomento.com
88
88
  executables: