markdown-run 0.1.3 → 0.1.4
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 +6 -2
- data/README.md +38 -4
- data/docs/markdown-run-vscode.gif +0 -0
- data/exe/markdown-run +45 -14
- data/lib/markdown/run/version.rb +1 -1
- data/markdown-run-sample.md +29 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00367c7c6c302db7b935780c6bb63f6deec1175516f82999ed7295f4b88794b6
|
4
|
+
data.tar.gz: dbf713b531a435d794e40da3f9e4f2d04b9a78e859bedba44649ed0ac46a5898
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5680e8dfa751cd59afc0cd5e92070cd6eb6d3d24c13a53f44212cc7f4398cd2504e3f63718c15f3e00ba92b8d87aced3a9d92804e9a25922b7af833c9d4608bb
|
7
|
+
data.tar.gz: 5778ebed3f7495f478fdc370faa06c8b7c38ada306de254103849ee18a14251f94a281d0fd91d78207c79fe27bac125e4cdf24dd78c039085e0013b67796b898
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
[](https://github.com/aurelienbottazini/markdown-run/actions/workflows/main.yml)
|
2
|
-
|
3
|
-
[](https://badge.fury.io/rb/markdown-run)
|
1
|
+
[](https://github.com/aurelienbottazini/markdown-run/actions/workflows/main.yml) [](https://badge.fury.io/rb/markdown-run)
|
4
2
|
|
5
3
|
# Markdown-run
|
6
4
|
|
5
|
+
Execute code blocks from your markdown files.
|
6
|
+
Save results to a new code block appended after the initial code block.
|
7
|
+
Do not rerun code blocks if result block is present.
|
8
|
+
|
9
|
+
Meant to be used from the terminal or from an editor with a keybinding.
|
10
|
+
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
`gem install markdown-run`
|
@@ -13,6 +17,36 @@
|
|
13
17
|
- Run specs `markdown-run`
|
14
18
|
- Run on a markdown file `markdown-run your-filename`
|
15
19
|
|
20
|
+
example vscode keybinding
|
21
|
+
|
22
|
+
```json
|
23
|
+
{
|
24
|
+
"key": "ctrl+shift+b",
|
25
|
+
"command": "runCommands",
|
26
|
+
"args": {
|
27
|
+
"commands": [
|
28
|
+
{
|
29
|
+
"command": "workbench.action.files.save"
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"command": "workbench.action.terminal.sendSequence",
|
33
|
+
"args": {
|
34
|
+
"text": "markdown-run \"${file}\"\n"
|
35
|
+
}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"command": "workbench.action.files.revert"
|
39
|
+
}
|
40
|
+
]
|
41
|
+
},
|
42
|
+
"when": "editorTextFocus && editorLangId == 'markdown'"
|
43
|
+
},
|
44
|
+
```
|
45
|
+
|
46
|
+
## Demo
|
47
|
+
|
48
|
+

|
49
|
+
|
16
50
|
## Development
|
17
51
|
|
18
52
|
Just run the script with `./exe/markdown-run`
|
@@ -25,4 +59,4 @@ Bug reports are welcome on GitHub at https://github.com/aurelienbottazini/markdo
|
|
25
59
|
|
26
60
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
27
61
|
|
28
|
-
## [
|
62
|
+
## [Code of conduct](https://github.com/aurelienbottazini/markdown-run/blob/main/CODE_OF_CONDUCT.md).
|
Binary file
|
data/exe/markdown-run
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require "tempfile"
|
4
4
|
require "open3"
|
5
5
|
require "fileutils"
|
6
|
-
require "minitest/spec"
|
7
6
|
|
8
7
|
# --- Language Execution Configuration ---
|
9
8
|
JS_CONFIG = {
|
@@ -50,25 +49,43 @@ SUPPORTED_LANGUAGES = {
|
|
50
49
|
"js" => JS_CONFIG,
|
51
50
|
"javascript" => JS_CONFIG, # Alias for js
|
52
51
|
"sqlite" => SQLITE_CONFIG,
|
53
|
-
"sqlite3" => SQLITE_CONFIG # Alias for sqlite
|
52
|
+
"sqlite3" => SQLITE_CONFIG, # Alias for sqlite
|
53
|
+
"bash" => {
|
54
|
+
command: ->(_code_content, temp_file_path) {
|
55
|
+
bash_exists = system("command -v bash > /dev/null 2>&1")
|
56
|
+
unless bash_exists
|
57
|
+
abort "Error: bash command not found. Please ensure bash is in your PATH."
|
58
|
+
end
|
59
|
+
[ "bash #{temp_file_path}", {} ]
|
60
|
+
},
|
61
|
+
temp_file_suffix: ".sh"
|
62
|
+
},
|
63
|
+
"zsh" => {
|
64
|
+
command: ->(_code_content, temp_file_path) {
|
65
|
+
zsh_exists = system("command -v zsh > /dev/null 2>&1")
|
66
|
+
unless zsh_exists
|
67
|
+
abort "Error: zsh command not found. Please ensure zsh is in your PATH."
|
68
|
+
end
|
69
|
+
[ "zsh #{temp_file_path}", {} ]
|
70
|
+
},
|
71
|
+
temp_file_suffix: ".zsh"
|
72
|
+
},
|
73
|
+
"sh" => {
|
74
|
+
command: ->(_code_content, temp_file_path) {
|
75
|
+
sh_exists = system("command -v sh > /dev/null 2>&1")
|
76
|
+
unless sh_exists
|
77
|
+
abort "Error: sh command not found. Please ensure sh is in your PATH."
|
78
|
+
end
|
79
|
+
[ "sh #{temp_file_path}", {} ]
|
80
|
+
},
|
81
|
+
temp_file_suffix: ".sh"
|
82
|
+
}
|
54
83
|
}.freeze
|
55
84
|
|
56
85
|
LANGUAGE_REGEX_PART = SUPPORTED_LANGUAGES.keys.map { |lang| Regexp.escape(lang) }.join("|").freeze
|
57
86
|
CODE_BLOCK_START_REGEX = /^```(#{LANGUAGE_REGEX_PART})$/i
|
58
87
|
# --- End Language Execution Configuration ---
|
59
88
|
|
60
|
-
if ARGV.empty?
|
61
|
-
require "bundler/inline"
|
62
|
-
gemfile(true) do
|
63
|
-
source "https://rubygems.org"
|
64
|
-
gem "minitest" # You can specify a version like '~> 5.10' if needed
|
65
|
-
gem "rcodetools"
|
66
|
-
end
|
67
|
-
|
68
|
-
puts "Running tests..."
|
69
|
-
require "minitest/autorun"
|
70
|
-
end
|
71
|
-
|
72
89
|
# Script to process markdown files, execute code blocks based on language,
|
73
90
|
# and insert their results back into the markdown.
|
74
91
|
|
@@ -288,6 +305,19 @@ def process_markdown_file_main(input_file_path)
|
|
288
305
|
true # Indicate success
|
289
306
|
end
|
290
307
|
|
308
|
+
if ARGV.empty?
|
309
|
+
|
310
|
+
require "minitest/spec"
|
311
|
+
require "bundler/inline"
|
312
|
+
gemfile(true) do
|
313
|
+
source "https://rubygems.org"
|
314
|
+
gem "minitest", "5.25.5" # Specify the required version
|
315
|
+
gem "rcodetools"
|
316
|
+
end
|
317
|
+
|
318
|
+
puts "Running tests..."
|
319
|
+
require "minitest/autorun"
|
320
|
+
|
291
321
|
# --- Minitest Test Class Definition ---
|
292
322
|
class TestMarkdownExec < Minitest::Test
|
293
323
|
def setup
|
@@ -385,5 +415,6 @@ class TestMarkdownExec < Minitest::Test
|
|
385
415
|
assert_equal original_content.strip, read_md_file.strip, "Should not execute if ```ruby RESULT block exists"
|
386
416
|
end
|
387
417
|
end
|
418
|
+
end
|
388
419
|
|
389
420
|
process_markdown_file_main(ARGV[0]) unless ARGV.empty?
|
data/lib/markdown/run/version.rb
CHANGED
data/markdown-run-sample.md
CHANGED
@@ -7,6 +7,35 @@ And the result should be shown in a following codeblock
|
|
7
7
|
p "foo"
|
8
8
|
```
|
9
9
|
|
10
|
+
```ruby RESULT
|
11
|
+
p "foo"
|
12
|
+
# >> "foo"
|
13
|
+
```
|
14
|
+
|
15
|
+
```bash
|
16
|
+
date
|
17
|
+
```
|
18
|
+
|
19
|
+
```RESULT
|
20
|
+
Sun May 18 15:05:35 CEST 2025
|
21
|
+
```
|
22
|
+
|
23
|
+
```zsh
|
24
|
+
date
|
25
|
+
```
|
26
|
+
|
27
|
+
```RESULT
|
28
|
+
Sun May 18 15:05:13 CEST 2025
|
29
|
+
```
|
30
|
+
|
31
|
+
```sh
|
32
|
+
date
|
33
|
+
```
|
34
|
+
|
35
|
+
```RESULT
|
36
|
+
Sun May 18 15:07:05 CEST 2025
|
37
|
+
```
|
38
|
+
|
10
39
|
```js
|
11
40
|
1 + 2;
|
12
41
|
console.log(3);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown-run
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aurélien Bottazini
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rcodetools
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.25.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.25.5
|
27
41
|
description: Run code blocks in Markdown files for Ruby, JavaScript, sqlite and psql.
|
28
42
|
Insert execution results next to the original code blocks.
|
29
43
|
email:
|
@@ -38,6 +52,7 @@ files:
|
|
38
52
|
- CODE_OF_CONDUCT.md
|
39
53
|
- LICENSE.txt
|
40
54
|
- README.md
|
55
|
+
- docs/markdown-run-vscode.gif
|
41
56
|
- exe/markdown-run
|
42
57
|
- lib/markdown/run/version.rb
|
43
58
|
- markdown-run-sample.md
|