Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Possible to indent lines in template without also indeting the content?

Below am creating a string with newlines, and will end up in an email later on.

    if (action) {
      description = `
Git pull request action:        ${action}
Git pull request for repo:      ${req.body.repository.full_name}
Git pull request for repo URL:  ${req.body.repository.html_url}

Git pull request title:         ${req.body.pull_request.title}
Git pull request description:   ${req.body.pull_request.body}
Git pull request by user:       ${req.body.pull_request.user.login}
Git pull request URL:           ${req.body.pull_request.html_url}
`
    };

However if I indent the lines like so

    if (action) {
      description = `
        Git pull request action:        ${action}
        Git pull request for repo:      ${req.body.repository.full_name}
        Git pull request for repo URL:  ${req.body.repository.html_url}

        Git pull request title:         ${req.body.pull_request.title}
        Git pull request description:   ${req.body.pull_request.body}
        Git pull request by user:       ${req.body.pull_request.user.login}
        Git pull request URL:           ${req.body.pull_request.html_url}
     `
    };

it also indents the output.

Question Is there a way to indent the lines without also indenting the output?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Currently, it is not possible to do that.

However there is a TC39 proposal to change that (Still in draft phase).
So maybe it will be possible in the future.

In the meantime, you can use the zero-dependency dedent library which does exactly that.

let dedent = require("dedent");

// ...

if (action) {
  description = dedent`
    Git pull request action:        ${action}
    Git pull request for repo:      ${req.body.repository.full_name}
    Git pull request for repo URL:  ${req.body.repository.html_url}

    Git pull request title:         ${req.body.pull_request.title}
    Git pull request description:   ${req.body.pull_request.body}
    Git pull request by user:       ${req.body.pull_request.user.login}
    Git pull request URL:           ${req.body.pull_request.html_url}
  `
};

It takes care of different types of line-breaks, empty lines, escaped back-ticks, and keeps all other indentation consistent.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!