You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-7Lines changed: 69 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,19 @@ This document includes the necessary code for testing within invisible code bloc
78
78
79
79
Code blocks embedded in this document can be saved to files using the [`mdcode extract`](#mdcode-extract) command. A `README_test.go` and a `README.test.js` file will be created in the current directory. After modification, the code blocks can be updated from these files to the document using the [`mdcode update`](#mdcode-update) command.
80
80
81
+
After the modification, it is advisable to test the above examples using the following commands:
82
+
83
+
```sh name=test
84
+
go test ./...
85
+
node --test
86
+
```
87
+
88
+
Since the above code block has a name (`test`), it can also be run with the [`mdcode run`](#mdcode-run) command:
89
+
90
+
```
91
+
mdcode run -n test
92
+
```
93
+
81
94
More examples can be found in the [examples](examples/) directory and in the [tutorial](docs/testable-markdown-code-blocks.md).
82
95
83
96
### Features
@@ -239,11 +252,11 @@ Or if only block comments can be used (CSS):
239
252
240
253
/* #endregion */
241
254
242
-
Regions marked this way are used by IDEs to collapse parts of the source code.
255
+
Regions marked in this way are used by IDEs to collapse parts of the source code.
243
256
244
257
In the case of `mdcode`, regions can be referenced with the `region` metadata. If a region is specified for a code block, the subcommand (update or extract) applies only to the specified region of the file. That is, the update command only embeds the specified region from the file to the markdown document, and the extract command overwrites only the specified region in the file.
245
258
246
-
`mdcode` can handle regions in any programming language, the only requirement is that the comments indicating the beginning and end of the region are placed in separate lines containing only the given comment.
259
+
`mdcode` can handle regions in any programming language, the only requirement is that the comment indicating the beginning and end of the region is placed in a separate line containing only the given comment.
247
260
<!-- #endregion regions -->
248
261
249
262
### Invisible
@@ -435,7 +448,7 @@ The optional argument of the `mdcode` command is the name of the markdown file.
Extract code blocks to the file system and run shell commands on them
561
+
562
+
The code blocks are written to the file named in the `file` metadata.
563
+
564
+
The code block may include `region` metadata, which contains the name of the region. In this case, the code block is written to the appropriate part of the file marked with the `#region` comment.
565
+
566
+
The optional argument of the `mdcode run` command is the name of the markdown file. If it is missing, the `README.md` file in the current directory (if it exists) is processed.
567
+
568
+
This can be followed by a double dash (`--`) and then the shell command line to be executed (even a complex command, such as `for`).
569
+
570
+
Alternatively, the commands to be executed can be embedded in a code block in the document. In this case, the language must be `sh` and it is necessary to name the code block with the metadata `name`. The name of the code block containing the commands can be specified with the `--name` flag (if not, the first code block containing the `sh` language and `name` metadata will be executed).
571
+
572
+
Code blocks are extracted to a temporary directory. This directory will be the current directory when running the commands. The temporary directory is deleted after executing the commands (deletion can be prevented by using the `--keep` flag). Instead of a temporary directory, the name of the directory to be used can be specified with the `--dir` flag. In this case, of course, the directory is not deleted after executing the commands.
573
+
574
+
575
+
```
576
+
mdcode run [flags] [filename] [-- commands]
577
+
```
578
+
579
+
### Flags
580
+
581
+
```
582
+
-d, --dir string base directory name (default ".")
583
+
-h, --help help for run
584
+
-k, --keep don't remove temporary directory
585
+
-n, --name string code block name contains commands
Copy file name to clipboardExpand all lines: internal/cmd/help/filtering.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
By default, `mdcode` work with all code blocks in a markdown document. It is possible to filter code blocks based on programming language or metadata. In this case, `mdcode`ignore code blocks that do not meet the filter criteria.
1
+
By default, `mdcode` work with all code blocks in a markdown document. It is possible to filter code blocks based on programming language or metadata. In this case, `mdcode`ignores code blocks that do not meet the filter criteria.
2
2
3
3
A language filter pattern can be specified using the `--lang` flag. Then only code blocks with a language matching the pattern will be processed. For example, filtering for code blocks containing JavaScript code:
Extract code blocks to the file system and run shell commands on them
2
+
3
+
The code blocks are written to the file named in the `file` metadata.
4
+
5
+
The code block may include `region` metadata, which contains the name of the region. In this case, the code block is written to the appropriate part of the file marked with the `#region` comment.
6
+
7
+
The optional argument of the `mdcode run` command is the name of the markdown file. If it is missing, the `README.md` file in the current directory (if it exists) is processed.
8
+
9
+
This can be followed by a double dash (`--`) and then the shell command line to be executed (even a complex command, such as `for`).
10
+
11
+
Alternatively, the commands to be executed can be embedded in a code block in the document. In this case, the language must be `sh` and it is necessary to name the code block with the metadata `name`. The name of the code block containing the commands can be specified with the `--name` flag (if not, the first code block containing the `sh` language and `name` metadata will be executed).
12
+
13
+
Code blocks are extracted to a temporary directory. This directory will be the current directory when running the commands. The temporary directory is deleted after executing the commands (deletion can be prevented by using the `--keep` flag). Instead of a temporary directory, the name of the directory to be used can be specified with the `--dir` flag. In this case, of course, the directory is not deleted after executing the commands.
0 commit comments