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
Let say I have below Javascript file, name script.js:
functionsayHello(){console.log("Hello world!");}
Now I want to use it inside a Markdown file:
# Title
Steps:
1. Say Hello:
```javascript
{{#include ./script.js}}
sayHello();
```2. Shake hands
Currently what we get will be:
# Title
Steps:
1. Say Hello:
```javascriptfunctionsayHello() {
console.log("Hello world!");
}
sayHello();
```2. Shake hands
This will breaks as the included file doesn't have same indent with the code using it.
If we indent all lines in the file with same indent of include command, what we get will be:
# Title
Steps:
1. Say Hello:
```javascriptfunctionsayHello() {
console.log("Hello world!");
}
sayHello();
```2. Shake hands
Then it will be rendered correctly.
Why it would be useful?
Some time we have large code that we want include them in markdown file. I prefer to put it in seperate files, so I can get the benefit of syntax highlight, code suggestion, and can be used by other code.
When we use #include we will make our markdown file cleaner, and we don't have to maintain to places of same code, which is very easy to get out of sync.
Problem is right now we can only include it if in places where don't have indent, otherwise it will breaks.
By indent content of the files, we can make #include useful in many use cases.
Other use case
script.js file:
functionsayHello(){console.log("Hello world!");}
style.css file:
a {
text-decoration: none;
}
document.md file:
Look at this HTML:
```html
<html>
<head>
<style>
{{#include ./style.css}}</style>
<script>
{{#include ./script.js}}</script>
</head>
<body>
</body>
</html>
```
Currently, what we get will be:
Look at this HTML:
```html
<html>
<head>
<style>
a {text-decoration: none;}</style>
<script>
functionsayHello() {console.log("Hello world!");}</script>
</head>
<body>
</body>
</html>
```
If we indent the included file, we will get a nicely thing like this:
Look at this HTML:
```html
<html>
<head>
<style>
a {text-decoration: none; }</style>
<script>
functionsayHello() {console.log("Hello world!"); }</script>
</head>
<body>
</body>
</html>
```
The text was updated successfully, but these errors were encountered:
Use case
Let say I have below Javascript file, name script.js:
Now I want to use it inside a Markdown file:
Currently what we get will be:
This will breaks as the included file doesn't have same indent with the code using it.
If we indent all lines in the file with same indent of include command, what we get will be:
Then it will be rendered correctly.
Why it would be useful?
Some time we have large code that we want include them in markdown file. I prefer to put it in seperate files, so I can get the benefit of syntax highlight, code suggestion, and can be used by other code.
When we use
#include
we will make our markdown file cleaner, and we don't have to maintain to places of same code, which is very easy to get out of sync.Problem is right now we can only include it if in places where don't have indent, otherwise it will breaks.
By indent content of the files, we can make
#include
useful in many use cases.Other use case
script.js
file:style.css
file:document.md
file:Currently, what we get will be:
If we indent the included file, we will get a nicely thing like this:
The text was updated successfully, but these errors were encountered: