markdown_exec 2.6.0 → 2.7.0

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -2
  3. data/Gemfile.lock +2 -2
  4. data/Rakefile +36 -0
  5. data/bats/command-substitution.bats +8 -0
  6. data/bats/options.bats +4 -4
  7. data/bats/plain.bats +8 -0
  8. data/bats/table.bats +6 -1
  9. data/bats/variable-expansion.bats +4 -4
  10. data/bin/bmde +46 -2
  11. data/bin/tab_completion.sh +1 -1
  12. data/docs/dev/command-substitution.md +24 -0
  13. data/docs/dev/load_code.md +14 -0
  14. data/docs/dev/no-active-elements.md +6 -0
  15. data/docs/dev/screen-width.md +21 -0
  16. data/docs/dev/table-invalid.md +20 -0
  17. data/examples/bash-blocks.md +2 -1
  18. data/examples/block-names.md +2 -1
  19. data/examples/block-types.md +2 -1
  20. data/examples/data-files.md +1 -0
  21. data/examples/document_options.md +1 -0
  22. data/examples/example-document-opts.md +6 -0
  23. data/examples/index.md +1 -1
  24. data/examples/interrupt.md +1 -0
  25. data/examples/link-blocks-load-save.md +8 -10
  26. data/examples/link-blocks-vars.md +12 -9
  27. data/examples/linked.md +9 -12
  28. data/examples/linked1.md +7 -6
  29. data/examples/linked2.md +6 -7
  30. data/examples/linked3.md +6 -5
  31. data/examples/linked_show.md +5 -4
  32. data/examples/nickname.md +1 -0
  33. data/examples/opts-blocks-require.md +1 -0
  34. data/examples/opts-blocks.md +1 -0
  35. data/examples/opts_output_execution.md +1 -0
  36. data/examples/pass-through-arguments.md +1 -0
  37. data/examples/pause-after-execution.md +1 -0
  38. data/examples/port-blocks.md +14 -10
  39. data/examples/save.md +1 -0
  40. data/examples/text-markup.md +2 -1
  41. data/examples/variable-expansion-save-block.md +48 -0
  42. data/examples/variable-expansion.md +3 -1
  43. data/examples/vars-blocks.md +14 -24
  44. data/examples/wrap.md +2 -1
  45. data/lib/collapser.rb +83 -47
  46. data/lib/evaluate_shell_expressions.rb +3 -2
  47. data/lib/fcb.rb +8 -2
  48. data/lib/hash_delegator.rb +214 -118
  49. data/lib/input_sequencer.rb +0 -7
  50. data/lib/markdown_exec/version.rb +1 -1
  51. data/lib/markdown_exec.rb +6 -1
  52. data/lib/menu.src.yml +22 -9
  53. data/lib/menu.yml +22 -7
  54. data/lib/ww.rb +1 -1
  55. metadata +16 -9
  56. data/docs/dev/table-crash.md +0 -39
  57. data/examples/load_code.md +0 -10
  58. /data/{examples → docs/dev}/load1.sh +0 -0
@@ -94,18 +94,13 @@ class InputSequencer
94
94
  break if exit_when_bq_empty && bq_is_empty? && !now_menu.prior_block_was_link
95
95
 
96
96
  if now_menu.display_menu
97
- # !!b
98
97
  break if run_yield(:end_of_cli, &block) == :exit
99
- # !!b
100
98
 
101
99
  exit_when_bq_empty = false
102
100
  run_yield :display_menu, &block
103
- # !!b
104
101
 
105
102
  choice = run_yield :user_choice, &block
106
- # !!b
107
103
  break if choice == :break
108
- # !!b
109
104
 
110
105
  raise BlockMissing, 'Block not recognized.' if choice.nil?
111
106
  # Exit loop and method to terminate the app
@@ -120,9 +115,7 @@ class InputSequencer
120
115
  if now_menu.block_name && !now_menu.block_name.empty?
121
116
  block_name = now_menu.block_name
122
117
  else
123
- # break if bq_is_empty? # Exit loop if no more blocks to process
124
118
  if bq_is_empty? # Exit loop if no more blocks to process
125
- # !!b
126
119
  run_yield :end_of_cli, &block
127
120
  break
128
121
  end
@@ -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 = '2.6.0'
10
+ VERSION = '2.7.0'
11
11
  end
data/lib/markdown_exec.rb CHANGED
@@ -6,6 +6,7 @@
6
6
  require 'English'
7
7
  require 'clipboard'
8
8
  require 'fileutils'
9
+ require 'io/console'
9
10
  require 'open3'
10
11
  require 'optparse'
11
12
  require 'shellwords'
@@ -405,6 +406,7 @@ module MarkdownExec
405
406
  #
406
407
  def execute_block_with_error_handling
407
408
  finalize_cli_argument_processing
409
+ @options.register_console_attributes(@options)
408
410
  execute_initial_commands_and_main_loop(@options, @options.run_state)
409
411
  rescue FileMissingError
410
412
  warn "File missing: #{$!}"
@@ -991,6 +993,7 @@ module MarkdownExec
991
993
  end
992
994
 
993
995
  def select_document_if_multiple(files = list_markdown_files_in_path,
996
+ cycle: true,
994
997
  prompt: options[:prompt_select_md].to_s)
995
998
  return files[0] if (count = files.count) == 1
996
999
 
@@ -1004,7 +1007,9 @@ module MarkdownExec
1004
1007
  :prompt_color_after_script_execution
1005
1008
  ),
1006
1009
  files,
1007
- opts.merge(per_page: opts[:select_page_height])
1010
+ HashDelegator.options_for_tty_menu(opts).merge(
1011
+ cycle: cycle
1012
+ )
1008
1013
  )
1009
1014
  end
1010
1015
 
data/lib/menu.src.yml CHANGED
@@ -102,11 +102,11 @@
102
102
  :default: true
103
103
  :procname: val_as_bool
104
104
 
105
- # - :opt_name: command_substitution_regexp
106
- # :env_var: MDE_COMMAND_SUBSTITUTION_REGEXP
107
- # :description: command_substitution_regexp
108
- # :default: "(?<expression>\\$\\((?<variable>[A-Z0-9a-z_]+)\\))"
109
- # :procname: val_as_str
105
+ - :opt_name: command_substitution_regexp
106
+ :env_var: MDE_COMMAND_SUBSTITUTION_REGEXP
107
+ :description: command_substitution_regexp
108
+ :default: "(?<expression>\\$\\((?<command>([^()]*(\\([^()]*\\))*[^()]*)*)\\))"
109
+ :procname: val_as_str
110
110
 
111
111
  - :long_name: config
112
112
  :description: Read configuration file
@@ -462,7 +462,7 @@
462
462
 
463
463
  - :opt_name: heading1_match
464
464
  :env_var: MDE_HEADING1_MATCH
465
- :default: "^#(?<line>(?!#)(?<collapse>[+-~]?)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
465
+ :default: "^(?<indent>[ \t]*)#(?<collapse>[+-~]?)(?<leading>[ \t]*)(?<line>(?!#)(?<text>.*?))?(?<trailing>[ \t]*)$"
466
466
  :procname: val_as_str
467
467
 
468
468
  - :opt_name: heading2_center
@@ -482,7 +482,8 @@
482
482
 
483
483
  - :opt_name: heading2_match
484
484
  :env_var: MDE_HEADING2_MATCH
485
- :default: "^##(?<line>(?!#)(?<collapse>[+-~]?)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
485
+ :default: "^(?<indent>[ \t]*)#{2}(?<collapse>[+-~]?)(?<leading>[ \t]*)(?<line>(?!#)(?<text>.*?))?(?<trailing>[ \t]*)$"
486
+
486
487
  :procname: val_as_str
487
488
 
488
489
  - :opt_name: heading3_center
@@ -502,7 +503,7 @@
502
503
 
503
504
  - :opt_name: heading3_match
504
505
  :env_var: MDE_HEADING3_MATCH
505
- :default: "^###(?<collapse>[+-~]?)(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
506
+ :default: "^(?<indent>[ \t]*)#{3}(?<collapse>[+-~]?)(?<gap>[ \t]*)(?<line>(?!#)(?<text>.*?))?(?<trailing>[ \t]*)$"
506
507
  :procname: val_as_str
507
508
 
508
509
  - :long_name: help
@@ -994,7 +995,7 @@
994
995
  - :opt_name: menu_table_rows_match
995
996
  :env_var: MDE_MENU_TABLE_ROWS_MATCH
996
997
  :description: Pattern for table rows
997
- :default: '^(?<line>(?<indent>[ \t]*)(?<text>\|.*?)(?<trailing>[ \t]*))$'
998
+ :default: '^(?<indent>[ \t]*)(?<line>(?<text>\|.*?)(?<trailing>[ \t]*))$'
998
999
  :procname: val_as_str
999
1000
 
1000
1001
  - :opt_name: menu_task_color
@@ -1256,6 +1257,12 @@
1256
1257
  :default: Other
1257
1258
  :procname: val_as_str
1258
1259
 
1260
+ - :opt_name: prompt_margin_left_text
1261
+ :env_var: MDE_PROMPT_MARGIN_LEFT_TEXT
1262
+ :description: prompt_margin_left_text
1263
+ :default: "» "
1264
+ :procname: val_as_str
1265
+
1259
1266
  - :opt_name: prompt_no
1260
1267
  :env_var: MDE_PROMPT_NO
1261
1268
  :description: Prompt for no
@@ -1455,6 +1462,12 @@
1455
1462
  :default: mde_*.out.txt
1456
1463
  :procname: val_as_str
1457
1464
 
1465
+ - :opt_name: screen_width
1466
+ :env_var: MDE_SCREEN_WIDTH
1467
+ :description: Screen width for document and interface. 0 to use the actual dimension.
1468
+ :default: 0
1469
+ :procname: val_as_int
1470
+
1458
1471
  - :opt_name: script_execution_frame_color
1459
1472
  :env_var: MDE_SCRIPT_EXECUTION_FRAME_COLOR
1460
1473
  :description: script_execution_frame_color
data/lib/menu.yml CHANGED
@@ -83,6 +83,11 @@
83
83
  :arg_name: BOOL
84
84
  :default: true
85
85
  :procname: val_as_bool
86
+ - :opt_name: command_substitution_regexp
87
+ :env_var: MDE_COMMAND_SUBSTITUTION_REGEXP
88
+ :description: command_substitution_regexp
89
+ :default: "(?<expression>\\$\\((?<command>([^()]*(\\([^()]*\\))*[^()]*)*)\\))"
90
+ :procname: val_as_str
86
91
  - :long_name: config
87
92
  :description: Read configuration file
88
93
  :arg_name: PATH
@@ -386,8 +391,8 @@
386
391
  :procname: val_as_bool
387
392
  - :opt_name: heading1_match
388
393
  :env_var: MDE_HEADING1_MATCH
389
- :default: "^#(?<line>(?!#)(?<collapse>[+-~]?)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[
390
- \t]*))?$"
394
+ :default: "^(?<indent>[ \t]*)#(?<collapse>[+-~]?)(?<leading>[ \t]*)(?<line>(?!#)(?<text>.*?))?(?<trailing>[
395
+ \t]*)$"
391
396
  :procname: val_as_str
392
397
  - :opt_name: heading2_center
393
398
  :env_var: MDE_HEADING2_CENTER
@@ -403,8 +408,8 @@
403
408
  :procname: val_as_bool
404
409
  - :opt_name: heading2_match
405
410
  :env_var: MDE_HEADING2_MATCH
406
- :default: "^##(?<line>(?!#)(?<collapse>[+-~]?)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[
407
- \t]*))?$"
411
+ :default: "^(?<indent>[ \t]*)#{2}(?<collapse>[+-~]?)(?<leading>[ \t]*)(?<line>(?!#)(?<text>.*?))?(?<trailing>[
412
+ \t]*)$"
408
413
  :procname: val_as_str
409
414
  - :opt_name: heading3_center
410
415
  :env_var: MDE_HEADING3_CENTER
@@ -420,8 +425,8 @@
420
425
  :procname: val_as_bool
421
426
  - :opt_name: heading3_match
422
427
  :env_var: MDE_HEADING3_MATCH
423
- :default: "^###(?<collapse>[+-~]?)(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[
424
- \t]*))?$"
428
+ :default: "^(?<indent>[ \t]*)#{3}(?<collapse>[+-~]?)(?<gap>[ \t]*)(?<line>(?!#)(?<text>.*?))?(?<trailing>[
429
+ \t]*)$"
425
430
  :procname: val_as_str
426
431
  - :long_name: help
427
432
  :short_name: h
@@ -833,7 +838,7 @@
833
838
  - :opt_name: menu_table_rows_match
834
839
  :env_var: MDE_MENU_TABLE_ROWS_MATCH
835
840
  :description: Pattern for table rows
836
- :default: "^(?<line>(?<indent>[ \\t]*)(?<text>\\|.*?)(?<trailing>[ \\t]*))$"
841
+ :default: "^(?<indent>[ \\t]*)(?<line>(?<text>\\|.*?)(?<trailing>[ \\t]*))$"
837
842
  :procname: val_as_str
838
843
  - :opt_name: menu_task_color
839
844
  :env_var: MDE_MENU_TASK_COLOR
@@ -1059,6 +1064,11 @@
1059
1064
  :description: User wants a custom file name
1060
1065
  :default: Other
1061
1066
  :procname: val_as_str
1067
+ - :opt_name: prompt_margin_left_text
1068
+ :env_var: MDE_PROMPT_MARGIN_LEFT_TEXT
1069
+ :description: prompt_margin_left_text
1070
+ :default: "» "
1071
+ :procname: val_as_str
1062
1072
  - :opt_name: prompt_no
1063
1073
  :env_var: MDE_PROMPT_NO
1064
1074
  :description: Prompt for no
@@ -1237,6 +1247,11 @@
1237
1247
  :arg_name: GLOB
1238
1248
  :default: mde_*.out.txt
1239
1249
  :procname: val_as_str
1250
+ - :opt_name: screen_width
1251
+ :env_var: MDE_SCREEN_WIDTH
1252
+ :description: Screen width for document and interface. 0 to use the actual dimension.
1253
+ :default: 0
1254
+ :procname: val_as_int
1240
1255
  - :opt_name: script_execution_frame_color
1241
1256
  :env_var: MDE_SCRIPT_EXECUTION_FRAME_COLOR
1242
1257
  :description: script_execution_frame_color
data/lib/ww.rb CHANGED
@@ -17,7 +17,7 @@ end
17
17
  def ww(*objs, **kwargs)
18
18
  return unless $debug
19
19
 
20
- ww0(*objs, **kwargs)
20
+ ww0(*objs, **kwargs.merge(locations: caller_locations))
21
21
  end
22
22
 
23
23
  def ww0(*objs,
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.6.0
4
+ version: 2.7.0
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-11-28 00:00:00.000000000 Z
11
+ date: 2024-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: yaml
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.0
75
+ version: '0.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.0
82
+ version: '0.2'
83
83
  description: Interactively select and execute fenced code blocks in markdown files.
84
84
  Build complex scripts by naming and requiring blocks. Log resulting scripts and
85
85
  output. Re-run scripts.
@@ -109,6 +109,7 @@ files:
109
109
  - bats/bats.bats
110
110
  - bats/block-types.bats
111
111
  - bats/cli.bats
112
+ - bats/command-substitution.bats
112
113
  - bats/fail.bats
113
114
  - bats/history.bats
114
115
  - bats/import.bats
@@ -116,6 +117,7 @@ files:
116
117
  - bats/mde.bats
117
118
  - bats/options-collapse.bats
118
119
  - bats/options.bats
120
+ - bats/plain.bats
119
121
  - bats/publish.bats
120
122
  - bats/table.bats
121
123
  - bats/test_helper.bash
@@ -132,20 +134,25 @@ files:
132
134
  - docs/dev/block-type-opts.md
133
135
  - docs/dev/block-type-port.md
134
136
  - docs/dev/block-type-vars.md
137
+ - docs/dev/command-substitution.md
135
138
  - docs/dev/data-blocks.md
136
139
  - docs/dev/disable.md
137
140
  - docs/dev/import-missing.md
138
141
  - docs/dev/import.md
139
142
  - docs/dev/linked-file.md
143
+ - docs/dev/load1.sh
144
+ - docs/dev/load_code.md
140
145
  - docs/dev/manage-saved-documents.md
141
146
  - docs/dev/menu-cli.md
147
+ - docs/dev/no-active-elements.md
142
148
  - docs/dev/options-collapse.md
143
149
  - docs/dev/pass-through-arguments.md
144
150
  - docs/dev/requiring-blocks.md
151
+ - docs/dev/screen-width.md
145
152
  - docs/dev/specs-import.md
146
153
  - docs/dev/specs.md
147
- - docs/dev/table-crash.md
148
154
  - docs/dev/table-indent.md
155
+ - docs/dev/table-invalid.md
149
156
  - docs/dev/text-decoration.md
150
157
  - docs/dev/variable-expansion.md
151
158
  - examples/bash-blocks.md
@@ -156,6 +163,7 @@ files:
156
163
  - examples/data-files.md
157
164
  - examples/document_options.md
158
165
  - examples/duplicate_block.md
166
+ - examples/example-document-opts.md
159
167
  - examples/import0.md
160
168
  - examples/import1.md
161
169
  - examples/include.md
@@ -172,9 +180,7 @@ files:
172
180
  - examples/linked3.md
173
181
  - examples/linked_show.md
174
182
  - examples/llm.md
175
- - examples/load1.sh
176
183
  - examples/load2.sh
177
- - examples/load_code.md
178
184
  - examples/nickname.md
179
185
  - examples/opts-blocks-require.md
180
186
  - examples/opts-blocks.md
@@ -188,6 +194,7 @@ files:
188
194
  - examples/table-markup.md
189
195
  - examples/text-markup.md
190
196
  - examples/title.md
197
+ - examples/variable-expansion-save-block.md
191
198
  - examples/variable-expansion.md
192
199
  - examples/vars-blocks.md
193
200
  - examples/wrap.md
@@ -1,39 +0,0 @@
1
- / The lines below are an invalid table
2
- | Region| VPC ID| VPC Name
3
- -
4
- # Demonstrate Tables
5
-
6
- Table flush at left.
7
- Centered columns.
8
- | Common Name| Species| Genus| Family| Year Discovered
9
- |:-:|:-:|:-:|:-:|:-:
10
- | Tapanuli Orangutan| Pongo tapanuliensis| Pongo| Hominidae| 2017
11
- | Psychedelic Frogfish| Histiophryne psychedelica| Histiophryne| Antennariidae| 2009
12
- | Ruby Seadragon| Phyllopteryx dewysea| Phyllopteryx| Syngnathidae| 2015
13
-
14
- Table indented with two spaces.
15
- Left-justified columns.
16
- | Common Name| Species| Genus| Family| Year Discovered
17
- |:-|:-|:-|:-|:-
18
- | Illacme tobini (Millipede)| Illacme tobini| Illacme| Siphonorhinidae| 2016
19
- | Cappuccino Snake| Hydrodynastes bicinctus| Hydrodynastes| Colubridae| 2021
20
- | Homo luzonensis| Homo luzonensis| Homo| Hominidae| 2019
21
-
22
- Table indented with one tab.
23
- Right-justified columns.
24
- | Common Name| Species| Genus| Family| Year Discovered
25
- |-:|-:|-:|-:|-:
26
- | Spiny Dandelion| Taraxacum japonicum| Taraxacum| Asteraceae| 2022
27
- | Mythical Monkey| Cercopithecus lomamiensis| Cercopithecus| Cercopithecidae| 2012
28
- | Yeti Crab| Kiwa hirsuta| Kiwa| Kiwaidae| 2005
29
-
30
- ## Non-table text is not modified
31
- 1. |
32
- 2. ||
33
- |
34
- ||
35
-
36
- ## markup with table
37
- | Common Name| Species| Genus| Family| Year Discovered
38
- |:-:|:-:|:-:|:-:|:-:
39
- | `Tapanuli Orangutan`| **Pongo tapanuliensis**| __Pongo__| Hominidae| 2017
@@ -1,10 +0,0 @@
1
- Demonstrate loading inherited code via the command line.
2
-
3
- Run this command to display the inherited code.
4
- `mde --load-code examples/load1.sh examples/load_code.md display_variables`
5
-
6
- ```bash :display_variables
7
- source bin/colorize_env_vars.sh
8
- echo The current value of environment variables:
9
- colorize_env_vars '' var1 var2
10
- ```
File without changes