使用转换子进程时,字符串插入不正确

String is not interpolated correct when using convert sub process

我正在使用节点 14 和 https://github.com/google/zx 来创建带有文本的图像。
字符串是插值的,但在图像中显示的格式很奇怪。

子进程是这样​​调用的:

let annotation = `${title}\n ${date.mtime.toISOString()}`
await $`convert ${frameImage} -gravity south -fill white -pointsize 36 -annotate +0+10 "${annotation}" ${frameImage}`

结果如图所示:

$'Title 
2021-02-03T07:05:01.00Z'

我希望它在没有 $' 的情况下呈现,例如:

Title 
2021-02-03T07:05:01.00Z

示例图片:

问题出在命令中的引号,只需省略它们,然后输出就如您所愿。

await $`convert ${frameImage} -gravity south -fill white -pointsize 36 -annotate +0+10 ${annotation} ${frameImage}`

Zx 负责自动转义,因此添加引号有点双重: https://github.com/google/zx/blob/main/docs/quotes.md