markdown-run 0.1.2 → 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 +9 -1
- data/README.md +38 -4
- data/docs/markdown-run-vscode.gif +0 -0
- data/exe/markdown-run +47 -18
- data/lib/markdown/run/version.rb +1 -1
- data/markdown-run-sample.md +78 -0
- metadata +18 -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
@@ -30,8 +30,7 @@ SUPPORTED_LANGUAGES = {
|
|
30
30
|
command: ->(code_content, _temp_file_path) {
|
31
31
|
psql_exists = system("command -v psql > /dev/null 2>&1")
|
32
32
|
unless psql_exists
|
33
|
-
|
34
|
-
exit 1 # Abort the script
|
33
|
+
abort "Error: psql command not found. Please install PostgreSQL or ensure psql is in your PATH."
|
35
34
|
end
|
36
35
|
[ "psql -A -t -X", { stdin_data: code_content } ]
|
37
36
|
}
|
@@ -40,8 +39,7 @@ SUPPORTED_LANGUAGES = {
|
|
40
39
|
command: ->(_code_content, temp_file_path) {
|
41
40
|
xmpfilter_exists = system("command -v xmpfilter > /dev/null 2>&1")
|
42
41
|
unless xmpfilter_exists
|
43
|
-
|
44
|
-
exit 1 # Abort the script
|
42
|
+
abort "Error: xmpfilter command not found. Please install xmpfilter or ensure it is in your PATH."
|
45
43
|
end
|
46
44
|
[ "xmpfilter #{temp_file_path}", {} ]
|
47
45
|
},
|
@@ -51,26 +49,43 @@ SUPPORTED_LANGUAGES = {
|
|
51
49
|
"js" => JS_CONFIG,
|
52
50
|
"javascript" => JS_CONFIG, # Alias for js
|
53
51
|
"sqlite" => SQLITE_CONFIG,
|
54
|
-
"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
|
+
}
|
55
83
|
}.freeze
|
56
84
|
|
57
85
|
LANGUAGE_REGEX_PART = SUPPORTED_LANGUAGES.keys.map { |lang| Regexp.escape(lang) }.join("|").freeze
|
58
86
|
CODE_BLOCK_START_REGEX = /^```(#{LANGUAGE_REGEX_PART})$/i
|
59
87
|
# --- End Language Execution Configuration ---
|
60
88
|
|
61
|
-
if ARGV.empty?
|
62
|
-
require "bundler/inline"
|
63
|
-
gemfile(true) do
|
64
|
-
source "https://rubygems.org"
|
65
|
-
gem "minitest" # You can specify a version like '~> 5.10' if needed
|
66
|
-
gem "rcodetools"
|
67
|
-
end
|
68
|
-
|
69
|
-
puts "Running tests..."
|
70
|
-
require "minitest/spec"
|
71
|
-
require "minitest/autorun"
|
72
|
-
end
|
73
|
-
|
74
89
|
# Script to process markdown files, execute code blocks based on language,
|
75
90
|
# and insert their results back into the markdown.
|
76
91
|
|
@@ -290,6 +305,19 @@ def process_markdown_file_main(input_file_path)
|
|
290
305
|
true # Indicate success
|
291
306
|
end
|
292
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
|
+
|
293
321
|
# --- Minitest Test Class Definition ---
|
294
322
|
class TestMarkdownExec < Minitest::Test
|
295
323
|
def setup
|
@@ -387,5 +415,6 @@ class TestMarkdownExec < Minitest::Test
|
|
387
415
|
assert_equal original_content.strip, read_md_file.strip, "Should not execute if ```ruby RESULT block exists"
|
388
416
|
end
|
389
417
|
end
|
418
|
+
end
|
390
419
|
|
391
420
|
process_markdown_file_main(ARGV[0]) unless ARGV.empty?
|
data/lib/markdown/run/version.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
This is an example markdown file
|
2
|
+
|
3
|
+
The following psql code block should be executed
|
4
|
+
And the result should be shown in a following codeblock
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
p "foo"
|
8
|
+
```
|
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
|
+
|
39
|
+
```js
|
40
|
+
1 + 2;
|
41
|
+
console.log(3);
|
42
|
+
```
|
43
|
+
|
44
|
+
```RESULT
|
45
|
+
3
|
46
|
+
```
|
47
|
+
|
48
|
+
```psql
|
49
|
+
\d
|
50
|
+
```
|
51
|
+
|
52
|
+
```RESULT
|
53
|
+
public|ar_internal_metadata|table|aurelienbottazini
|
54
|
+
public|schema_migrations|table|aurelienbottazini
|
55
|
+
```
|
56
|
+
|
57
|
+
```sqlite3
|
58
|
+
.stats
|
59
|
+
```
|
60
|
+
|
61
|
+
```RESULT
|
62
|
+
Memory Used: 147824 (max 147888) bytes
|
63
|
+
Number of Outstanding Allocations: 169 (max 170)
|
64
|
+
Number of Pcache Overflow Bytes: 4608 (max 4608) bytes
|
65
|
+
Largest Allocation: 122400 bytes
|
66
|
+
Largest Pcache Allocation: 4104 bytes
|
67
|
+
Lookaside Slots Used: 34 (max 34)
|
68
|
+
Successful lookaside attempts: 34
|
69
|
+
Lookaside failures due to size: 0
|
70
|
+
Lookaside failures due to OOM: 0
|
71
|
+
Pager Heap Usage: 5632 bytes
|
72
|
+
Page cache hits: 0
|
73
|
+
Page cache misses: 0
|
74
|
+
Page cache writes: 0
|
75
|
+
Page cache spills: 0
|
76
|
+
Schema Heap Usage: 0 bytes
|
77
|
+
Statement Heap/Lookaside Usage: 0 bytes
|
78
|
+
```
|
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,8 +52,10 @@ 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
|
58
|
+
- markdown-run-sample.md
|
43
59
|
homepage: https://rubygems.org/gems/markdown-run
|
44
60
|
licenses:
|
45
61
|
- MIT
|