Skip to content

Commit 8a3ce5b

Browse files
committed
Include more example in README
1 parent 8436f4a commit 8a3ce5b

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
- Include some example in README
6+
37
## 0.1.0
48

59
- Initial release

README.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,37 @@ This extension depends on the following extension:
3535

3636
* `markdown-run-snippet.mdToVscodeTypeMap`
3737

38+
Map from language specified in Markdown to Visual Studio Code's filetype.
39+
If there is no entry, the same string is used as Visual Studio Code's filetype.
40+
3841
Example:
3942

4043
```json
4144
"markdown-run-snippet.mdToVscodeTypeMap": {
42-
"cpp": "C++"
45+
"c++": "cpp"
4346
}
4447
```
4548

46-
Map from language specified in Markdown to Visual Studio Code's filetype.
47-
If there is no entry, the same string is used as Visual Studio Code's filetype.
49+
With the above setting, we can collectly set the filetype to `cpp` for
50+
snippet below:
51+
52+
```c++
53+
std::cout << "hello!" << std::endl;
54+
```
55+
56+
Without the above setting, this extension assume the filetype `c++`. However
57+
Visual Studio Code can't recognize it, so it fails to run this snippet.
58+
4859

4960
* `markdown-run-snippet.mdTypeToTemplateMap`
5061

62+
Map from language specified in Markdown to template (that will be applied to
63+
the snippet). Template feature is useful for importing common modules,
64+
including common headers, defining main() function. selected snippet will be
65+
placed at the position of `$snippet`. The leading ' '(whitespace) before
66+
`$snippet` is important, because the same amount of ' ' will be prepended to
67+
all lines of selected snippet.
68+
5169
Example:
5270

5371
```json
@@ -56,14 +74,41 @@ This extension depends on the following extension:
5674
}
5775
```
5876

59-
Map from language specified in Markdown to template (that will be applied to
60-
the snippet). Template feature is useful for importing common modules,
61-
including common headers, defining main() function. selected snippet will be
62-
placed at the position of `$snippet`. The leading ' '(whitespace) before
63-
`$snippet` is important, because the same amount of ' ' will be prepended to
64-
all lines of selected snippet.
77+
With above setting, we can run snippet below even if we have to define
78+
`main()` function in Rust language:
79+
80+
```rust
81+
let name = "foo";
82+
println!("Hello, {}", name);
83+
```
84+
85+
The above snippet will be expanded as follows:
86+
87+
```rust
88+
fn main() {
89+
let name = "foo";
90+
println!("Hello, {}", name);
91+
}
92+
```
93+
94+
Similary, C++ requires to define `main()` function. Also C++ needs a lot of
95+
header files to run. Let's make it template:
96+
97+
```json
98+
"markdown-run-snippet.mdTypeToTemplateMap": {
99+
"rust": "fn main() {\n $snippet\n}",
100+
"c++": "#include <iostream>\n#include <string>\nint main(void) {\n $snippet\n}"
101+
}
102+
```
103+
104+
Now we can run the snippet below:
105+
106+
```c++
107+
std::string name = "foo";
108+
std::cout << "Hello, " << name << std::endl;
109+
```
65110

66-
Configurations defined by default are very very few.
111+
Very very few (almost no) configurations are defined by default.
67112

68113
## Known Issues
69114

0 commit comments

Comments
 (0)