Skip to content

Commit

Permalink
docs: Add some more examples (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jan 29, 2023
1 parent 3717d3f commit 4c5b574
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 14 deletions.
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,39 @@ async function version(): Promise<string> {
The hash `#` portion of the file URL is used to set injection options. Each option is separated by a `&`.
| Option | Description |
| --------- | --------------------------------------------------------- |
| `heading` | Used to extract a section from a markdown file. |
| `lang` | Used to set the language of the code block |
| `quote` | Used to inject the file as a block quote |
| `L1-L10` | Used to inject only specified lines from the source file. |
| Option | Code | Markdown | Description |
| --------- | ---- | -------- | --------------------------------------------------------- |
| `heading` | ❌ | ✅ | Used to extract a section from a markdown file. |
| `code` | ❌ | ✅ | Convert the injected markdown into a Code Block. |
| `lang` | ✅ | ✅ | Used to set the language of the code block. |
| `quote` | ✅ | ✅ | Used to inject the file as a block quote. |
| `L1-L10` | ✅ | ✅ | Used to inject only specified lines from the source file. |
### Example 1
Extract a few lines from a Markdown files and quote them.
```markdown
<!--- @@inject: example.md#L5-L7&quote --->
```
> - first
> - second
> - third
### Example 2
Extract some lines from a code block in the source.
```markdown
<!--- @@inject-code: code.md#L24-L26&lang=js --->
```
> ```js
> export function sayGoodbye(name) {
> return `Goodbye ${name}`;
> }
> ```
<!--- @@inject-end: content/README.md --->
Expand Down
51 changes: 43 additions & 8 deletions content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ It is also possible to inject markdown:
<!--- @@inject-code: example.md --->
```

<!--- @@inject-code: example.md --->
<!--- @@inject-code: example.md#code --->

```markdown
# Example
Expand All @@ -76,7 +76,7 @@ This is an example bit of markdown.
- third
```

<!--- @@inject-end: example.md --->
<!--- @@inject-end: example.md#code --->

## Import a section from a Markdown file

Expand Down Expand Up @@ -130,9 +130,44 @@ async function version(): Promise<string> {
The hash `#` portion of the file URL is used to set injection options. Each option is separated by a `&`.
| Option | Description |
| --------- | --------------------------------------------------------- |
| `heading` | Used to extract a section from a markdown file. |
| `lang` | Used to set the language of the code block |
| `quote` | Used to inject the file as a block quote |
| `L1-L10` | Used to inject only specified lines from the source file. |
| Option | Code | Markdown | Description |
| --------- | ---- | -------- | --------------------------------------------------------- |
| `heading` | ❌ | ✅ | Used to extract a section from a markdown file. |
| `code` | ❌ | ✅ | Convert the injected markdown into a Code Block. |
| `lang` | ✅ | ✅ | Used to set the language of the code block. |
| `quote` | ✅ | ✅ | Used to inject the file as a block quote. |
| `L1-L10` | ✅ | ✅ | Used to inject only specified lines from the source file. |
### Example 1
Extract a few lines from a Markdown files and quote them.
```markdown
<!--- @@inject: example.md#L5-L7&quote --->
```
<!--- @@inject: example.md#L5-L7&quote --->
> - first
> - second
> - third
<!--- @@inject-end: example.md#L5-L7&quote --->
### Example 2
Extract some lines from a code block in the source.
```markdown
<!--- @@inject-code: code.md#L24-L26&lang=js --->
```
<!--- @@inject-code: code.md#L24-L26&lang=js&quote --->
> ```js
> export function sayGoodbye(name) {
> return `Goodbye ${name}`;
> }
> ```
<!--- @@inject-end: code.md#L24-L26&lang=js&quote --->
7 changes: 7 additions & 0 deletions content/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function sayHello(name) {
return `Hello ${name}`;
}

export function sayGoodbye(name) {
return `Goodbye ${name}`;
}
29 changes: 29 additions & 0 deletions content/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Example with embedded code

## TypeScript

<!--- @@inject: code.ts --->

```ts
export function sayHello(name: string): string {
return `Hello ${name}`;
}
```

<!--- @@inject-end: code.ts --->

## JavaScript

<!--- @@inject: code.js --->

```js
export function sayHello(name) {
return `Hello ${name}`;
}

export function sayGoodbye(name) {
return `Goodbye ${name}`;
}
```

<!--- @@inject-end: code.js --->

0 comments on commit 4c5b574

Please sign in to comment.