feat: Provide code fragments feature (#748)
This commit is contained in:
parent
6ac7bace21
commit
1447c8a40a
4 changed files with 37 additions and 0 deletions
16
docs/_media/example.js
Normal file
16
docs/_media/example.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import fetch from 'fetch'
|
||||
|
||||
const URL = 'https://example.com'
|
||||
const PORT = 8080
|
||||
|
||||
/// [demo]
|
||||
const result = fetch(`${URL}:${PORT}`)
|
||||
.then(function(response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function(myJson) {
|
||||
console.log(JSON.stringify(myJson));
|
||||
});
|
||||
/// [demo]
|
||||
|
||||
result.then(console.log).catch(console.error)
|
||||
|
|
@ -39,6 +39,21 @@ You will get it
|
|||
|
||||
[filename](_media/example.md ':include :type=code')
|
||||
|
||||
## Embedded code fragments
|
||||
Sometimes you don't want to embed a whole file. Maybe because you need just a few lines but you want to compile and test the file in CI.
|
||||
|
||||
```markdown
|
||||
[filename](_media/example.js ':include :type=code :fragment=demo')
|
||||
```
|
||||
|
||||
In your code file you need to surround the fragment between `/// [demo]` lines (before and after the fragment).
|
||||
Alternatively you can use `### [demo]`.
|
||||
|
||||
Example:
|
||||
|
||||
[filename](_media/example.js ':include :type=code :fragment=demo')
|
||||
|
||||
|
||||
## Tag attribute
|
||||
|
||||
If you embed the file as `iframe`, `audio` and `video`, then you may need to set the attributes of these tags.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue