Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda