Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Indent content of {{#include ...}} #1636

Closed
tuyen-at-work opened this issue Aug 30, 2021 · 2 comments
Closed

Feature request: Indent content of {{#include ...}} #1636

tuyen-at-work opened this issue Aug 30, 2021 · 2 comments

Comments

@tuyen-at-work
Copy link
Contributor

tuyen-at-work commented Aug 30, 2021

Use case

Let say I have below Javascript file, name script.js:

function sayHello() {
  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:

   ```javascript
function sayHello() {
  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:

   ```javascript
   function sayHello() {
     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:

function sayHello() {
  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>
function sayHello() {
  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>
      function sayHello() {
        console.log("Hello world!");
      }
    </script>
  </head>
  <body>
  </body>
</html>
```
@ehuss
Copy link
Contributor

ehuss commented Aug 30, 2021

Is this essentially the same as #1564?

@tuyen-at-work
Copy link
Contributor Author

@ehuss my bad, yes exactly the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants