markdown_exec 3.5.1 → 3.5.2

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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.ai-agent-instructions +54 -0
  3. data/.cursorrules +198 -0
  4. data/.rubocop.wide.yml +5 -0
  5. data/.rubocop.yml +7 -2
  6. data/CHANGELOG.md +12 -1
  7. data/Gemfile.lock +1 -1
  8. data/Rakefile +2 -0
  9. data/ai-principles.md +516 -0
  10. data/architecture-decisions.md +190 -0
  11. data/bats/block-hide.bats +1 -1
  12. data/bats/block-type-bash.bats +5 -5
  13. data/bats/block-type-link.bats +1 -1
  14. data/bats/block-type-opts.bats +3 -3
  15. data/bats/block-type-port.bats +2 -2
  16. data/bats/block-type-shell-require-ux.bats +2 -2
  17. data/bats/block-type-ux-allowed.bats +4 -4
  18. data/bats/block-type-ux-auto.bats +1 -1
  19. data/bats/block-type-ux-chained.bats +1 -1
  20. data/bats/block-type-ux-default.bats +1 -1
  21. data/bats/block-type-ux-echo-hash-transform.bats +1 -1
  22. data/bats/block-type-ux-echo-hash.bats +2 -2
  23. data/bats/block-type-ux-echo.bats +3 -3
  24. data/bats/block-type-ux-exec-hash-transform.bats +1 -1
  25. data/bats/block-type-ux-exec-hash.bats +2 -2
  26. data/bats/block-type-ux-exec.bats +1 -1
  27. data/bats/block-type-ux-force.bats +1 -1
  28. data/bats/block-type-ux-formats.bats +1 -1
  29. data/bats/block-type-ux-hidden.bats +1 -1
  30. data/bats/block-type-ux-invalid.bats +1 -1
  31. data/bats/block-type-ux-readonly.bats +1 -1
  32. data/bats/block-type-ux-require-chained.bats +2 -2
  33. data/bats/block-type-ux-require-context.bats +2 -2
  34. data/bats/block-type-ux-require.bats +2 -2
  35. data/bats/block-type-ux-required-variables.bats +1 -1
  36. data/bats/block-type-ux-row-format.bats +1 -1
  37. data/bats/block-type-ux-sources.bats +4 -4
  38. data/bats/block-type-ux-transform.bats +1 -1
  39. data/bats/block-type-vars.bats +3 -3
  40. data/bats/border.bats +1 -1
  41. data/bats/cli.bats +11 -11
  42. data/bats/command-substitution-options.bats +2 -2
  43. data/bats/command-substitution.bats +1 -1
  44. data/bats/document-shell.bats +1 -1
  45. data/bats/history.bats +5 -5
  46. data/bats/import-conflict.bats +1 -1
  47. data/bats/import-directive-line-continuation.bats +1 -1
  48. data/bats/import-directive-parameter-symbols.bats +1 -1
  49. data/bats/import-duplicates.bats +6 -6
  50. data/bats/import-parameter-symbols.bats +1 -1
  51. data/bats/import-with-text-substitution.bats +1 -1
  52. data/bats/import.bats +3 -3
  53. data/bats/indented-block-type-vars.bats +1 -1
  54. data/bats/indented-multi-line-output.bats +1 -1
  55. data/bats/line-decor-dynamic.bats +1 -1
  56. data/bats/line-wrapping.bats +1 -1
  57. data/bats/load-vars-state-demo.bats +4 -4
  58. data/bats/markup.bats +4 -4
  59. data/bats/mde.bats +4 -4
  60. data/bats/option-expansion.bats +1 -1
  61. data/bats/options-collapse.bats +4 -4
  62. data/bats/options.bats +47 -17
  63. data/bats/plain.bats +1 -1
  64. data/bats/publish.bats +2 -2
  65. data/bats/table-column-truncate.bats +1 -1
  66. data/bats/table.bats +2 -2
  67. data/bats/variable-expansion-multiline.bats +1 -1
  68. data/bats/variable-expansion.bats +6 -6
  69. data/conversation-template.md +611 -0
  70. data/docs/block-execution-modes.md +177 -0
  71. data/docs/block-filtering.md +252 -0
  72. data/docs/block-naming-patterns.md +210 -0
  73. data/docs/block-scanning-patterns.md +248 -0
  74. data/docs/cli-reference.md +370 -0
  75. data/docs/dev/block-hide.md +1 -1
  76. data/docs/dev/block-type-ux-transform.md +5 -4
  77. data/docs/dev/print_bytes.md +3 -0
  78. data/docs/dev/shebang.md +6 -0
  79. data/docs/docker-testing.md +5 -0
  80. data/docs/execution-control.md +384 -0
  81. data/docs/getting-started.md +209 -0
  82. data/docs/import-options.md +391 -0
  83. data/docs/tab-completion.md +7 -0
  84. data/docs/ux-blocks.md +376 -0
  85. data/examples/linked1.md +8 -1
  86. data/implementation-decisions.md +212 -0
  87. data/lib/cached_nested_file_reader.rb +138 -1
  88. data/lib/command_result.rb +27 -6
  89. data/lib/executed_shell_command.rb +512 -0
  90. data/lib/filter.rb +7 -7
  91. data/lib/hash_delegator.rb +403 -350
  92. data/lib/link_history.rb +22 -11
  93. data/lib/markdown_exec/version.rb +1 -1
  94. data/lib/mdoc.rb +103 -44
  95. data/lib/menu.src.yml +110 -83
  96. data/lib/menu.yml +149 -83
  97. data/lib/transformed_shell_command.rb +449 -0
  98. data/lib/wl.rb +15 -0
  99. data/lib/ww.rb +16 -5
  100. data/requirements.md +111 -0
  101. data/semantic-tokens.md +132 -0
  102. data/tasks.md +69 -0
  103. metadata +26 -4
  104. data/docs/ux-blocks-examples.md +0 -120
  105. data/docs/ux-blocks-init-act.md +0 -100
@@ -0,0 +1,177 @@
1
+ # Block Execution Modes
2
+
3
+ This document explains how blocks can be configured to execute in different modes: batch mode, interactive mode, or the default document mode.
4
+
5
+ ## Overview
6
+
7
+ Markdown Exec supports three execution modes for code blocks, plus a disable option:
8
+
9
+ 1. **Default Mode**: Uses `document_play_bin` (default: `play`) - standard execution
10
+ 2. **Batch Mode**: Uses `play_bin_batch` (default: `play`) - for non-interactive batch execution
11
+ 3. **Interactive Mode**: Uses `play_bin_interactive` (default: `play_interactive`) - for interactive execution
12
+ 4. **Disabled**: Blocks matching `block_disable_match` are marked as disabled and cannot be executed
13
+
14
+ ## Configuration Options
15
+
16
+ ### Block Batch Match
17
+
18
+ - **Option**: `block_batch_match`
19
+ - **Environment Variable**: `MDE_BLOCK_BATCH_MATCH`
20
+ - **Default**: `'@batch'`
21
+ - **Description**: Pattern to match blocks that should be executed in batch mode
22
+
23
+ Blocks whose start line matches this pattern will be executed using the `play_bin_batch` binary instead of the default `document_play_bin`.
24
+
25
+ ### Block Interactive Match
26
+
27
+ - **Option**: `block_interactive_match`
28
+ - **Environment Variable**: `MDE_BLOCK_INTERACTIVE_MATCH`
29
+ - **Default**: `'@interactive'`
30
+ - **Description**: Pattern to match blocks that should be executed in interactive mode
31
+
32
+ Blocks whose start line matches this pattern will be executed using the `play_bin_interactive` binary.
33
+
34
+ ### Block Disable Match
35
+
36
+ - **Option**: `block_disable_match`
37
+ - **Environment Variable**: `MDE_BLOCK_DISABLE_MATCH`
38
+ - **Default**: `'@disable'`
39
+ - **Description**: Pattern to match blocks that should be disabled (not executable)
40
+
41
+ Blocks whose start line matches this pattern will be marked as disabled in the menu and cannot be executed. This is useful for documentation blocks, examples, or blocks that should be visible but not runnable.
42
+
43
+ ### Execution Binaries
44
+
45
+ The following options control which binary is used for each execution mode:
46
+
47
+ #### Document Play Bin
48
+
49
+ - **Option**: `document_play_bin`
50
+ - **Environment Variable**: `MDE_DOCUMENT_PLAY_BIN`
51
+ - **Default**: `'play'`
52
+ - **Description**: Binary used for default block execution mode
53
+
54
+ This is the default binary used when a block doesn't match any special execution mode pattern.
55
+
56
+ #### Play Bin Batch
57
+
58
+ - **Option**: `play_bin_batch`
59
+ - **Environment Variable**: `MDE_PLAY_BIN_BATCH`
60
+ - **Default**: `'play'`
61
+ - **Description**: Binary used for batch mode block execution
62
+
63
+ This binary is used when a block matches the `block_batch_match` pattern.
64
+
65
+ #### Play Bin Interactive
66
+
67
+ - **Option**: `play_bin_interactive`
68
+ - **Environment Variable**: `MDE_PLAY_BIN_INTERACTIVE`
69
+ - **Default**: `'play_interactive'`
70
+ - **Description**: Binary used for interactive mode block execution
71
+
72
+ This binary is used when a block matches the `block_interactive_match` pattern.
73
+
74
+ ## How It Works
75
+
76
+ ### Execution Mode Selection
77
+
78
+ The execution mode is determined by checking the block's start line against these patterns in the following order:
79
+
80
+ 1. First, check if the start line matches `block_interactive_match`
81
+ - If matched → use `play_bin_interactive`
82
+ 2. Then, check if the start line matches `block_batch_match`
83
+ - If matched → use `play_bin_batch`
84
+ 3. Otherwise → use `document_play_bin` (default)
85
+
86
+ This logic is implemented in `lib/hash_delegator.rb` in the `compile_execute_and_trigger_reuse` method (lines 1586-1596).
87
+
88
+ ### Block Disabling
89
+
90
+ Block disabling is handled separately during menu filtering. If a block's start line matches `block_disable_match`, the block is marked as disabled (`TtyMenu::DISABLE`) and will appear in the menu but cannot be executed. This check happens in `lib/filter.rb` in the `apply_other_filters` method (lines 130-132).
91
+
92
+ **Note**: Disabled blocks are still visible in the menu but are shown as non-selectable/disabled. This is different from hidden blocks (which use `block_name_hide_custom_match` and are completely hidden from the menu).
93
+
94
+ ## Usage Examples
95
+
96
+ ### Batch Mode
97
+
98
+ To mark a block for batch execution, include `@batch` in the block's start line:
99
+
100
+ ```bash :example-batch @batch
101
+ echo "This block will execute in batch mode"
102
+ echo "It uses play_bin_batch instead of document_play_bin"
103
+ ```
104
+
105
+ ### Interactive Mode
106
+
107
+ To mark a block for interactive execution, include `@interactive` in the block's start line:
108
+
109
+ ```bash :example-interactive @interactive
110
+ echo "This block will execute in interactive mode"
111
+ echo "It uses play_bin_interactive"
112
+ ```
113
+
114
+ ### Disabled Blocks
115
+
116
+ To mark a block as disabled (visible but not executable), include `@disable` in the block's start line:
117
+
118
+ ```bash :example-disabled @disable
119
+ echo "This block is visible but cannot be executed"
120
+ echo "It will appear in the menu but be marked as disabled"
121
+ ```
122
+
123
+ ### Custom Patterns
124
+
125
+ You can customize the patterns via configuration:
126
+
127
+ ```opts
128
+ block_batch_match: '@batch-mode'
129
+ block_interactive_match: '@interactive-mode'
130
+ block_disable_match: '@skip'
131
+ ```
132
+
133
+ Then use the custom markers:
134
+
135
+ ```bash :custom-batch @batch-mode
136
+ echo "Custom batch marker"
137
+ ```
138
+
139
+ ```bash :custom-interactive @interactive-mode
140
+ echo "Custom interactive marker"
141
+ ```
142
+
143
+ ```bash :custom-disabled @skip
144
+ echo "Custom disabled marker"
145
+ ```
146
+
147
+ ### Custom Execution Binaries
148
+
149
+ You can also customize which binaries are used for each mode:
150
+
151
+ ```opts
152
+ document_play_bin: 'play'
153
+ play_bin_batch: 'play_batch'
154
+ play_bin_interactive: 'play_interactive'
155
+ ```
156
+
157
+ ## Related Configuration
158
+
159
+ All options in this group work together:
160
+
161
+ - **Pattern Matching Options**:
162
+ - `block_interactive_match`: Pattern for interactive mode (checked first)
163
+ - `block_batch_match`: Pattern for batch mode (checked second)
164
+ - `block_disable_match`: Pattern for disabled blocks (checked during filtering)
165
+
166
+ - **Binary Selection Options**:
167
+ - `document_play_bin`: Binary for default mode (default: `play`)
168
+ - `play_bin_batch`: Binary for batch mode (default: `play`)
169
+ - `play_bin_interactive`: Binary for interactive mode (default: `play_interactive`)
170
+
171
+ ## Related Documentation
172
+
173
+ - [Block Filtering](block-filtering.md) - Filtering options including `block_name_hide_custom_match`, `hide_blocks_by_name`
174
+ - [Execution Control](execution-control.md) - Execution control options including `user_must_approve`, `execute_in_own_window`
175
+ - [Block Naming Patterns](block-naming-patterns.md) - How block names are parsed
176
+ - [CLI Reference](cli-reference.md) - Command-line usage
177
+
@@ -0,0 +1,252 @@
1
+ # Block Filtering Options
2
+
3
+ This document explains how blocks are filtered for inclusion or exclusion from menus and execution in markdown_exec.
4
+
5
+ ## Overview
6
+
7
+ Markdown Exec provides multiple mechanisms to filter blocks:
8
+
9
+ 1. **Type-based filtering**: Filter by block type (bash, expect, etc.)
10
+ 2. **Name-based filtering**: Filter by block name using regex patterns
11
+ 3. **Shell-based filtering**: Filter by shell type using regex patterns
12
+ 4. **Pattern-based filtering**: Use naming patterns (hidden, include, wrapper)
13
+
14
+ These filters work together in a specific order to determine which blocks appear in menus and can be executed.
15
+
16
+ ## Configuration Options
17
+
18
+ ### Bash Only
19
+
20
+ - **Option**: `bash_only`
21
+ - **Environment Variable**: `MDE_BASH_ONLY`
22
+ - **Default**: `false`
23
+ - **Description**: Execute only blocks of type "bash"
24
+
25
+ When enabled, only blocks explicitly marked as type "bash" will be included. Blocks without a shell type specified will be excluded.
26
+
27
+ **Usage:**
28
+ ```opts
29
+ bash_only: true
30
+ ```
31
+
32
+ ### Exclude by Name Regex
33
+
34
+ - **Option**: `exclude_by_name_regex`
35
+ - **Environment Variable**: `MDE_EXCLUDE_BY_NAME_REGEX`
36
+ - **Default**: (empty)
37
+ - **Description**: Regex pattern to exclude blocks whose names match
38
+
39
+ Blocks whose names match this regex pattern will be excluded from menus and execution. This is checked after name selection filters.
40
+
41
+ **Example:**
42
+ ```opts
43
+ exclude_by_name_regex: '^test-|^internal-'
44
+ ```
45
+
46
+ This excludes blocks whose names start with `test-` or `internal-`.
47
+
48
+ ### Exclude by Shell Regex
49
+
50
+ - **Option**: `exclude_by_shell_regex`
51
+ - **Environment Variable**: `MDE_EXCLUDE_BY_SHELL_REGEX`
52
+ - **Default**: (empty)
53
+ - **Description**: Regex pattern to exclude blocks whose shell type matches
54
+
55
+ Blocks whose shell type matches this regex pattern will be excluded from menus and execution.
56
+
57
+ **Example:**
58
+ ```opts
59
+ exclude_by_shell_regex: '^(python|ruby)$'
60
+ ```
61
+
62
+ This excludes blocks with shell types "python" or "ruby".
63
+
64
+ ### Exclude Expect Blocks
65
+
66
+ - **Option**: `exclude_expect_blocks`
67
+ - **Environment Variable**: `MDE_EXCLUDE_EXPECT_BLOCKS`
68
+ - **Default**: `true`
69
+ - **Description**: Whether to exclude all blocks of type "expect" from menus
70
+
71
+ When enabled (default), all blocks of type "expect" are automatically excluded from menus. Expect blocks are typically used for automated testing and are not meant for interactive execution.
72
+
73
+ **Usage:**
74
+ ```opts
75
+ exclude_expect_blocks: false # Show expect blocks in menu
76
+ ```
77
+
78
+ ### Hide Blocks by Name
79
+
80
+ - **Option**: `hide_blocks_by_name`
81
+ - **Environment Variable**: `MDE_HIDE_BLOCKS_BY_NAME`
82
+ - **Default**: `true`
83
+ - **Description**: Whether to hide blocks whose names match block_name_hide_custom_match pattern
84
+
85
+ When enabled, blocks whose names match the `block_name_hide_custom_match` pattern (default: `^-.+-$`) will be hidden from menus. This works in conjunction with the naming pattern options.
86
+
87
+ **Usage:**
88
+ ```opts
89
+ hide_blocks_by_name: true
90
+ block_name_hide_custom_match: '^internal-.*'
91
+ ```
92
+
93
+ ### Select by Name Regex
94
+
95
+ - **Option**: `select_by_name_regex`
96
+ - **Environment Variable**: `MDE_SELECT_BY_NAME_REGEX`
97
+ - **Default**: (empty)
98
+ - **Description**: Regex pattern to include only blocks whose names match
99
+
100
+ When specified, only blocks whose names match this regex pattern will be included. All other blocks will be excluded. This is checked before exclude filters.
101
+
102
+ **Example:**
103
+ ```opts
104
+ select_by_name_regex: '^production-'
105
+ ```
106
+
107
+ This includes only blocks whose names start with `production-`.
108
+
109
+ ### Select by Shell Regex
110
+
111
+ - **Option**: `select_by_shell_regex`
112
+ - **Environment Variable**: `MDE_SELECT_BY_SHELL_REGEX`
113
+ - **Default**: (empty)
114
+ - **Description**: Regex pattern to include only blocks whose shell type matches
115
+
116
+ When specified, only blocks whose shell type matches this regex pattern will be included. All other blocks will be excluded.
117
+
118
+ **Example:**
119
+ ```opts
120
+ select_by_shell_regex: '^(bash|sh)$'
121
+ ```
122
+
123
+ This includes only blocks with shell types "bash" or "sh".
124
+
125
+ ## How It Works
126
+
127
+ The filtering system in `lib/filter.rb` evaluates blocks in a specific order:
128
+
129
+ ### Filter Evaluation Order
130
+
131
+ 1. **Depth Check**: Blocks with `depth == true` are excluded
132
+ 2. **Chrome Check**: Decorative blocks (chrome) are included unless `no_chrome` is enabled
133
+ 3. **Expect Blocks**: If `exclude_expect_blocks` is true, expect blocks are excluded
134
+ 4. **Hidden Name Check**: If `hide_blocks_by_name` is enabled and name matches `block_name_hide_custom_match`, block is excluded
135
+ 5. **Include Name Check**: If name matches `block_name_hidden_match`, block is included
136
+ 6. **Wrapper Name Check**: If name matches `block_name_wrapper_match`, block is included
137
+ 7. **Exclude Filters**:
138
+ - If `name_exclude` is true (name matches `exclude_by_name_regex`) → exclude
139
+ - If `shell_exclude` is true (shell matches `exclude_by_shell_regex`) → exclude
140
+ 8. **Select Filters**:
141
+ - If `name_select` is false (name doesn't match `select_by_name_regex`) → exclude
142
+ - If `shell_select` is false (shell doesn't match `select_by_shell_regex`) → exclude
143
+ 9. **Select Filters (positive)**:
144
+ - If `name_select` is true → include
145
+ - If `shell_select` is true → include
146
+ 10. **Default Filters**:
147
+ - If `name_default` is false or `shell_default` is false → exclude
148
+ 11. **Default**: Include the block
149
+
150
+ ### Filter Logic Details
151
+
152
+ **Name Filters** (`apply_name_filters`):
153
+ - `select_by_name_regex` is checked first - if specified, only matching blocks pass
154
+ - `exclude_by_name_regex` is checked second - matching blocks are excluded
155
+ - If neither is specified, all blocks pass name filtering
156
+
157
+ **Shell Filters** (`apply_shell_filters`):
158
+ - If `bash_only` is true and shell is empty, block is excluded
159
+ - `select_by_shell_regex` is checked first - if specified, only matching blocks pass
160
+ - `exclude_by_shell_regex` is checked second - matching blocks are excluded
161
+ - Expect blocks are marked for exclusion if `exclude_expect_blocks` is true
162
+
163
+ **Other Filters** (`apply_other_filters`):
164
+ - Disabled blocks (via `block_disable_match`) are marked
165
+ - Hidden name patterns are checked if `hide_blocks_by_name` is enabled
166
+ - Include and wrapper name patterns are checked
167
+
168
+ ## Usage Examples
169
+
170
+ ### Filter to Only Bash Blocks
171
+
172
+ ```opts
173
+ bash_only: true
174
+ ```
175
+
176
+ Only blocks explicitly marked as `bash` will be included.
177
+
178
+ ### Exclude Test Blocks
179
+
180
+ ```opts
181
+ exclude_by_name_regex: '^test'
182
+ ```
183
+
184
+ All blocks whose names start with "test" will be excluded.
185
+
186
+ ### Include Only Production Blocks
187
+
188
+ ```opts
189
+ select_by_name_regex: '^production-'
190
+ ```
191
+
192
+ Only blocks whose names start with "production-" will be included.
193
+
194
+ ### Filter by Shell Type
195
+
196
+ ```opts
197
+ select_by_shell_regex: '^(bash|sh)$'
198
+ exclude_by_shell_regex: 'python'
199
+ ```
200
+
201
+ Include only bash/sh blocks, but exclude any Python blocks.
202
+
203
+ ### Hide Internal Blocks
204
+
205
+ ```opts
206
+ hide_blocks_by_name: true
207
+ block_name_hide_custom_match: '^-internal-'
208
+ ```
209
+
210
+ Blocks with names like `-internal-setup-` will be hidden.
211
+
212
+ ### Combined Filtering
213
+
214
+ ```opts
215
+ # Only show bash blocks
216
+ bash_only: true
217
+
218
+ # But exclude test blocks
219
+ exclude_by_name_regex: '^test'
220
+
221
+ # And only include production blocks
222
+ select_by_name_regex: '^production-'
223
+ ```
224
+
225
+ This configuration will:
226
+ 1. Only include bash blocks
227
+ 2. Exclude blocks starting with "test"
228
+ 3. Only include blocks starting with "production-"
229
+
230
+ ## Filter Priority
231
+
232
+ When multiple filters conflict, the evaluation order determines priority:
233
+
234
+ 1. **Explicit excludes** (exclude_by_name_regex, exclude_by_shell_regex) take precedence
235
+ 2. **Select filters** (select_by_name_regex, select_by_shell_regex) act as allowlists
236
+ 3. **Pattern-based filters** (hidden, include, wrapper) are evaluated early
237
+ 4. **Type-based filters** (bash_only, exclude_expect_blocks) are evaluated early
238
+
239
+ ## Related Configuration
240
+
241
+ - **Block Naming Patterns**: `block_name_hide_custom_match`, `block_name_hidden_match`, `block_name_wrapper_match` - work with `hide_blocks_by_name`
242
+ - **Block Execution Modes**: `block_disable_match` - marks blocks as disabled
243
+ - **Menu Options**: `menu_include_imported_blocks` - controls imported block visibility
244
+
245
+ ## Related Documentation
246
+
247
+ - [Block Naming Patterns](block-naming-patterns.md) - Pattern-based filtering
248
+ - [Block Execution Modes](block-execution-modes.md) - Execution mode filtering
249
+ - [Block Scanning Patterns](block-scanning-patterns.md) - How block content is scanned
250
+ - [Import Options](import-options.md) - Imported block filtering
251
+ - [CLI Reference](cli-reference.md) - Command-line usage
252
+
@@ -0,0 +1,210 @@
1
+ # Block Naming Patterns
2
+
3
+ This document explains how block names are parsed, matched, and used for filtering and display in markdown_exec.
4
+
5
+ ## Overview
6
+
7
+ Markdown Exec uses several regex patterns to identify and categorize block names:
8
+
9
+ 1. **Block Name Extraction**: `block_name_match` - extracts the name from the fenced code block start line
10
+ 2. **Block Visibility**: `block_name_hide_custom_match` - control which blocks appear in menus
11
+ 3. **Block Types**: `block_name_hidden_match`, `block_name_nick_match`, `block_name_wrapper_match` - identify special block naming patterns
12
+
13
+ ## Configuration Options
14
+
15
+ ### Block Name Match
16
+
17
+ - **Option**: `block_name_match`
18
+ - **Environment Variable**: `MDE_BLOCK_NAME_MATCH`
19
+ - **Default**: `":(?<title>\\S+)( |$)"`
20
+ - **Description**: Regex pattern to extract the block name from the fenced code block start line
21
+
22
+ This pattern is used to parse the block name from lines like:
23
+ ```bash
24
+ ```bash :my-block-name
25
+ ```
26
+
27
+ The default pattern matches a colon followed by a name (captured in the `title` group). The pattern must include a named capture group (typically `title`) to extract the block name.
28
+
29
+ **Example matches:**
30
+ - `:example` → extracts `example`
31
+ - `:my-block-name` → extracts `my-block-name`
32
+ - `:test_block` → extracts `test_block`
33
+
34
+ ### Block Name Hidden Match
35
+
36
+ - **Option**: `block_name_hide_custom_match`
37
+ - **Environment Variable**: `MDE_BLOCK_NAME_HIDE_CUSTOM_MATCH`
38
+ - **Default**: `"^-.+-$"`
39
+ - **Description**: Regex pattern for block names that should be hidden from the menu
40
+
41
+ Blocks whose names match this pattern will be hidden from the block selection menu when `hide_blocks_by_name` is enabled. The default pattern matches names that start and end with hyphens (e.g., `-hidden-`, `-internal-`).
42
+
43
+ **Example matches:**
44
+ - `-hidden-` → hidden from menu
45
+ - `-internal-block-` → hidden from menu
46
+ - `visible-block` → shown in menu
47
+
48
+ ### Block Name Hidden Match
49
+
50
+ - **Option**: `block_name_hidden_match`
51
+ - **Environment Variable**: `MDE_BLOCK_NAME_HIDE_CUSTOM_MATCH`
52
+ - **Default**: `"^\\(.*\\)$"`
53
+ - **Description**: Regex pattern for block names that should be included in the menu
54
+
55
+ Blocks whose names match this pattern will be explicitly included in the menu, even if they might otherwise be filtered. The default pattern matches names in parentheses (e.g., `(document_opts)`, `(document_vars)`).
56
+
57
+ **Example matches:**
58
+ - `(document_opts)` → included in menu
59
+ - `(document_vars)` → included in menu
60
+ - `(config)` → included in menu
61
+
62
+ **Note**: This works in conjunction with other filtering options. When `include_name` is true in the filter evaluation, the block is shown in the menu.
63
+
64
+ ### Block Name Nick Match
65
+
66
+ - **Option**: `block_name_nick_match`
67
+ - **Environment Variable**: `MDE_BLOCK_NAME_NICK_MATCH`
68
+ - **Default**: `"^\\[.*\\]$"`
69
+ - **Description**: Regex pattern for block nicknames (alternative names not displayed in menu)
70
+
71
+ Blocks whose names match this pattern are treated as having nicknames. The nickname is an alternative identifier that is not displayed in the menu but can be used for references and dependencies. The default pattern matches names in square brackets (e.g., `[alias]`, `[short-name]`).
72
+
73
+ **Example matches:**
74
+ - `[alias]` → treated as nickname
75
+ - `[short]` → treated as nickname
76
+ - `regular-name` → not a nickname
77
+
78
+ **Usage**: Nicknames are useful when you want to reference a block by a shorter name internally, but display a different name in the menu.
79
+
80
+ ### Block Name Wrapper Match
81
+
82
+ - **Option**: `block_name_wrapper_match`
83
+ - **Environment Variable**: `MDE_BLOCK_NAME_WRAPPER_MATCH`
84
+ - **Default**: `"^{.+}$"`
85
+ - **Description**: Regex pattern for block names that act as wrappers (include other blocks)
86
+
87
+ Blocks whose names match this pattern are treated as wrapper blocks that can include or wrap other blocks. The default pattern matches names in curly braces (e.g., `{wrapper}`, `{container}`).
88
+
89
+ **Example matches:**
90
+ - `{wrapper}` → treated as wrapper
91
+ - `{container}` → treated as wrapper
92
+ - `regular-block` → not a wrapper
93
+
94
+ **Usage**: Wrapper blocks are used in dependency resolution and block composition. When a block name matches this pattern in a dependency specification (e.g., `+{wrapper}`), it's treated as a wrapper rather than a regular dependency.
95
+
96
+ ### Block Name (CLI Option)
97
+
98
+ - **Option**: `block_name`
99
+ - **Long Name**: `--block-name`
100
+ - **Short Name**: `-b`
101
+ - **Environment Variable**: `MDE_BLOCK_NAME`
102
+ - **Description**: Name of block to execute
103
+
104
+ This is a CLI option that allows you to directly specify which block to execute, bypassing the interactive menu selection.
105
+
106
+ **Usage:**
107
+ ```bash
108
+ mde document.md -b my-block-name
109
+ mde document.md --block-name example-block
110
+ ```
111
+
112
+ ## How It Works
113
+
114
+ ### Name Extraction Process
115
+
116
+ 1. When a fenced code block is encountered, the start line is matched against `block_name_match`
117
+ 2. If a match is found, the `title` capture group is extracted as the block name
118
+ 3. The extracted name is stored as the block's primary identifier
119
+
120
+ ### Filtering Process
121
+
122
+ The filtering logic in `lib/filter.rb` evaluates blocks in this order:
123
+
124
+ 1. **Custome Hidden Name Check**: If `hide_blocks_by_name` is enabled and the name matches `block_name_hide_custom_match`, the block is hidden
125
+ 2. **Hidden Name Check**: If the name matches `block_name_hidden_match`, the block is hidden
126
+ 3. **Wrapper Name Check**: If the name matches `block_name_wrapper_match`, it's marked as a wrapper
127
+ 4. **Final Decision**: The `evaluate_filters` method combines these flags to determine menu visibility
128
+
129
+ ### Special Name Types
130
+
131
+ - **Nicknames**: Matched by `block_name_nick_match`, used for internal references but not displayed
132
+ - **Wrappers**: Matched by `block_name_wrapper_match`, used in dependency resolution
133
+ - **Custom Hidden**: Matched by `block_name_hide_custom_match`, excluded from menus
134
+ - **Hidden**: Matched by `block_name_hidden_match`, excluded from menus
135
+
136
+ ## Usage Examples
137
+
138
+ ### Basic Block Naming
139
+
140
+ ```bash :example-block
141
+ echo "This block is named 'example-block'"
142
+ ```
143
+
144
+ The name `example-block` is extracted using `block_name_match` pattern.
145
+
146
+ ### Hidden Blocks
147
+
148
+ ```bash :-internal-
149
+ echo "This block is hidden from the menu"
150
+ ```
151
+
152
+ The name `-internal-` matches `block_name_hide_custom_match` and will be hidden when `hide_blocks_by_name` is enabled.
153
+
154
+ ### Included Blocks (Document Configuration)
155
+
156
+ ```opts :(document_opts)
157
+ # Configuration options
158
+ clear_screen_for_select_block: false
159
+ ```
160
+
161
+ The name `(document_opts)` matches `block_name_hidden_match` and will be hidden from the menu.
162
+
163
+ ### Nickname Blocks
164
+
165
+ ```bash :[alias]
166
+ echo "This block has a nickname"
167
+ ```
168
+
169
+ The name `[alias]` matches `block_name_nick_match` and is treated as a nickname.
170
+
171
+ ### Wrapper Blocks
172
+
173
+ ```bash :{wrapper}
174
+ echo "This is a wrapper block"
175
+ ```
176
+
177
+ The name `{wrapper}` matches `block_name_wrapper_match` and is treated as a wrapper.
178
+
179
+ ### Custom Patterns
180
+
181
+ You can customize the patterns to match your naming conventions:
182
+
183
+ ```opts
184
+ # Match block names starting with "internal_"
185
+ block_name_hide_custom_match: '^internal_.*'
186
+
187
+ # Match block names in double parentheses
188
+ block_name_hidden_match: '^\\(\\(.*\\)\\)$'
189
+
190
+ # Match block names starting with "@"
191
+ block_name_nick_match: '^@.*'
192
+
193
+ # Match block names in angle brackets
194
+ block_name_wrapper_match: '^<.+>$'
195
+ ```
196
+
197
+ ## Related Configuration
198
+
199
+ - `hide_blocks_by_name`: Enable/disable hiding blocks based on name patterns
200
+ - `block_name`: CLI option to directly specify a block to execute
201
+ - Block filtering options: `exclude_by_name_regex`, `select_by_name_regex`
202
+
203
+ ## Related Documentation
204
+
205
+ - [Block Filtering](block-filtering.md) - Other block filtering mechanisms
206
+ - [Block Execution Modes](block-execution-modes.md) - Execution mode patterns
207
+ - [Block Scanning Patterns](block-scanning-patterns.md) - How block content is scanned
208
+ - [Import Options](import-options.md) - How imported blocks are named
209
+ - [CLI Reference](cli-reference.md) - Command-line usage
210
+