markdown-run 0.1.7 → 0.1.8
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/CHANGELOG.md +4 -0
- data/README.md +15 -4
- data/exe/markdown-run +24 -0
- data/lib/markdown/run/version.rb +1 -1
- data/test_markdown_exec.rb +93 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 921255b90c33af932d6ac33284a24d4f0fc61b5fe3ec0afb45f912c8fcc6e678
|
4
|
+
data.tar.gz: 076f40ed6dc79bafbc7bdba3198f39fabf56754d74e1ef6bd38f451cc34ccafd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01c7168af16a7788b80acb43553f2ae81ee0a8d1dfe7bf7cf048a6c7a77a898257fb1308b277282d9494464189322eab67b164a8c694f0aa8437db8bc8654d36
|
7
|
+
data.tar.gz: 4f719733a2fbea191224f8c0fbcbb44f559d2d9bec1352f9d6c6caf851550593eb3622b2453cfdd584513d3b186f085157cf17cde5dfe61706f60a6d8b2e8050
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -54,12 +54,23 @@ example vscode keybinding
|
|
54
54
|
|
55
55
|
### Code block options
|
56
56
|
|
57
|
-
- `
|
57
|
+
- `run=true` or `run=false` to control whether a code block should be executed at all. `run=true` is the default if not specified
|
58
|
+
- `rerun=true` or `rerun=false` to control whether a code block should be re-executed if a result block already exists. `rerun=false` is the default if not specified
|
58
59
|
|
59
|
-
|
60
|
+
Options can be combined. If `run=false` is specified, the code block will not execute regardless of the `rerun` setting.
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
Examples:
|
63
|
+
|
64
|
+
```js run=false
|
65
|
+
console.log("This will not execute at all");
|
66
|
+
```
|
67
|
+
|
68
|
+
```js rerun=true
|
69
|
+
console.log("This will re-execute even if result exists");
|
70
|
+
```
|
71
|
+
|
72
|
+
```js run=true rerun=false
|
73
|
+
console.log("This will execute only if no result exists");
|
63
74
|
```
|
64
75
|
|
65
76
|
## Frontmatter
|
data/exe/markdown-run
CHANGED
@@ -89,6 +89,7 @@ class MarkdownProcessor
|
|
89
89
|
@current_block_lang = ""
|
90
90
|
@current_code_content = ""
|
91
91
|
@current_block_rerun = false
|
92
|
+
@current_block_run = true
|
92
93
|
@aliases = {}
|
93
94
|
end
|
94
95
|
|
@@ -204,6 +205,16 @@ class MarkdownProcessor
|
|
204
205
|
match[1].downcase == "true"
|
205
206
|
end
|
206
207
|
|
208
|
+
def parse_run_option(options_string)
|
209
|
+
return true unless options_string
|
210
|
+
|
211
|
+
# Match run=true or run=false
|
212
|
+
match = options_string.match(/run\s*=\s*(true|false)/i)
|
213
|
+
return true unless match
|
214
|
+
|
215
|
+
match[1].downcase == "true"
|
216
|
+
end
|
217
|
+
|
207
218
|
def safe_enum_operation(file_enum, operation)
|
208
219
|
file_enum.send(operation)
|
209
220
|
rescue StopIteration
|
@@ -271,6 +282,7 @@ class MarkdownProcessor
|
|
271
282
|
@output_lines << current_line
|
272
283
|
@current_block_lang = resolve_language(lang)
|
273
284
|
@current_block_rerun = parse_rerun_option(options_string)
|
285
|
+
@current_block_run = parse_run_option(options_string)
|
274
286
|
@state = :inside_code_block
|
275
287
|
@current_code_content = ""
|
276
288
|
end
|
@@ -296,6 +308,11 @@ class MarkdownProcessor
|
|
296
308
|
end
|
297
309
|
|
298
310
|
def decide_execution(file_enum)
|
311
|
+
# If run=false, skip execution entirely (no result block creation)
|
312
|
+
unless @current_block_run
|
313
|
+
return { execute: false, lines_to_pass_through: [] }
|
314
|
+
end
|
315
|
+
|
299
316
|
peek1 = peek_next_line(file_enum)
|
300
317
|
expected_header_regex = result_block_regex(@current_block_lang)
|
301
318
|
|
@@ -342,6 +359,12 @@ class MarkdownProcessor
|
|
342
359
|
end
|
343
360
|
|
344
361
|
def skip_and_pass_through_result(lines_to_pass_through, file_enum)
|
362
|
+
# Handle run=false case where there are no lines to pass through
|
363
|
+
if lines_to_pass_through.empty?
|
364
|
+
warn "Skipping execution due to run=false option."
|
365
|
+
return
|
366
|
+
end
|
367
|
+
|
345
368
|
lang_specific_result_type = ruby_style_result?(@current_block_lang) ? "```ruby RESULT" : "```RESULT"
|
346
369
|
|
347
370
|
warn "Found existing '#{lang_specific_result_type}' block for current #{@current_block_lang} block, skipping execution."
|
@@ -379,6 +402,7 @@ class MarkdownProcessor
|
|
379
402
|
@state = :outside_code_block
|
380
403
|
@current_code_content = ""
|
381
404
|
@current_block_rerun = false
|
405
|
+
@current_block_run = true
|
382
406
|
end
|
383
407
|
end
|
384
408
|
|
data/lib/markdown/run/version.rb
CHANGED
data/test_markdown_exec.rb
CHANGED
@@ -10,6 +10,9 @@ require "minitest/autorun"
|
|
10
10
|
require "fileutils"
|
11
11
|
require "tmpdir"
|
12
12
|
|
13
|
+
# Load the main script to access process_markdown_file_main
|
14
|
+
load File.expand_path("./exe/markdown-run", __dir__)
|
15
|
+
|
13
16
|
# --- Minitest Test Class Definition ---
|
14
17
|
class TestMarkdownExec < Minitest::Test
|
15
18
|
def setup
|
@@ -201,4 +204,94 @@ class TestMarkdownExec < Minitest::Test
|
|
201
204
|
refute file_content.include?("Should also change: 666666666"), "rerun=true with blank line should replace existing result"
|
202
205
|
assert file_content.match?(/Should also change: \d+/), "rerun=true with blank line should generate new result"
|
203
206
|
end
|
207
|
+
|
208
|
+
def test_run_functionality
|
209
|
+
# Test 1: Default behavior (run=true implicit) should execute new code block
|
210
|
+
md_content_default = <<~MARKDOWN
|
211
|
+
```ruby
|
212
|
+
puts "Should execute by default"
|
213
|
+
```
|
214
|
+
MARKDOWN
|
215
|
+
create_md_file(md_content_default)
|
216
|
+
process_markdown_file_main(@test_md_file_path)
|
217
|
+
|
218
|
+
file_content = read_md_file
|
219
|
+
assert file_content.include?("```ruby RESULT"), "Default behavior should create result block"
|
220
|
+
assert file_content.include?("Should execute by default"), "Default behavior should execute and show output"
|
221
|
+
|
222
|
+
# Test 2: run=true explicit should execute new code block
|
223
|
+
md_content_run_true = <<~MARKDOWN
|
224
|
+
```ruby run=true
|
225
|
+
puts "Should execute with run=true"
|
226
|
+
```
|
227
|
+
MARKDOWN
|
228
|
+
create_md_file(md_content_run_true)
|
229
|
+
process_markdown_file_main(@test_md_file_path)
|
230
|
+
|
231
|
+
file_content = read_md_file
|
232
|
+
assert file_content.include?("```ruby RESULT"), "run=true should create result block"
|
233
|
+
assert file_content.include?("Should execute with run=true"), "run=true should execute and show output"
|
234
|
+
|
235
|
+
# Test 3: run=false should not execute at all (no result block created)
|
236
|
+
md_content_run_false = <<~MARKDOWN
|
237
|
+
```ruby run=false
|
238
|
+
puts "Should not execute"
|
239
|
+
puts "No result block should be created"
|
240
|
+
```
|
241
|
+
MARKDOWN
|
242
|
+
create_md_file(md_content_run_false)
|
243
|
+
process_markdown_file_main(@test_md_file_path)
|
244
|
+
|
245
|
+
file_content = read_md_file
|
246
|
+
refute file_content.include?("```ruby RESULT"), "run=false should not create result block"
|
247
|
+
refute file_content.match?(/puts "Should not execute"\n# >>/), "run=false should not execute code (no # >> output)"
|
248
|
+
assert file_content.include?("puts \"Should not execute\""), "run=false should preserve original code block"
|
249
|
+
|
250
|
+
# Test 4: run=false with existing result block should skip execution but preserve result
|
251
|
+
md_content_run_false_with_result = <<~MARKDOWN
|
252
|
+
```ruby run=false
|
253
|
+
puts "Should not execute"
|
254
|
+
```
|
255
|
+
|
256
|
+
```ruby RESULT
|
257
|
+
Old result that should be preserved
|
258
|
+
```
|
259
|
+
MARKDOWN
|
260
|
+
create_md_file(md_content_run_false_with_result)
|
261
|
+
process_markdown_file_main(@test_md_file_path)
|
262
|
+
|
263
|
+
file_content = read_md_file
|
264
|
+
assert file_content.include?("Old result that should be preserved"), "run=false should preserve existing result"
|
265
|
+
refute file_content.match?(/puts "Should not execute"\n# >>/), "run=false should not create new execution output"
|
266
|
+
|
267
|
+
# Test 5: Combined options - run=false with rerun=true should still not execute
|
268
|
+
md_content_combined = <<~MARKDOWN
|
269
|
+
```ruby run=false rerun=true
|
270
|
+
puts "Should not execute despite rerun=true"
|
271
|
+
```
|
272
|
+
|
273
|
+
```ruby RESULT
|
274
|
+
Existing result
|
275
|
+
```
|
276
|
+
MARKDOWN
|
277
|
+
create_md_file(md_content_combined)
|
278
|
+
process_markdown_file_main(@test_md_file_path)
|
279
|
+
|
280
|
+
file_content = read_md_file
|
281
|
+
assert file_content.include?("Existing result"), "run=false should override rerun=true"
|
282
|
+
refute file_content.match?(/puts "Should not execute despite rerun=true"\n# >>/), "run=false should prevent execution even with rerun=true"
|
283
|
+
|
284
|
+
# Test 6: Combined options - run=true with rerun=false should execute if no result exists
|
285
|
+
md_content_run_true_rerun_false = <<~MARKDOWN
|
286
|
+
```ruby run=true rerun=false
|
287
|
+
puts "Should execute because no result exists"
|
288
|
+
```
|
289
|
+
MARKDOWN
|
290
|
+
create_md_file(md_content_run_true_rerun_false)
|
291
|
+
process_markdown_file_main(@test_md_file_path)
|
292
|
+
|
293
|
+
file_content = read_md_file
|
294
|
+
assert file_content.include?("```ruby RESULT"), "run=true rerun=false should execute when no result exists"
|
295
|
+
assert file_content.include?("Should execute because no result exists"), "run=true rerun=false should show output when no result exists"
|
296
|
+
end
|
204
297
|
end
|