【发布时间】:2021-03-09 13:50:08
【问题描述】:
下面是创建一个带有换行符的字符串,稍后将在电子邮件中结束。
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}
`
};
但是,如果我像这样缩进这些行
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}
`
};
它还缩进输出。
问题 有没有办法在不缩进输出的情况下缩进行?
【问题讨论】:
-
不要使用模板文字(至少不要使用一个巨大的文字)
-
@Andreas 替代方案是什么?
标签: javascript node.js ecmascript-6