如何为变量制作预先格式化的固定宽度代码块?
I指代码块语言
示例:
`*${variable}*` // *bold text* ok
`_${variable}_` // _italic text_ ok
````${variable}```` // ```pre-formatted fixed-width code block``` not work发布于 2018-02-07 23:18:15
如果我没听错的话,你的问题归结为逃避后背。
在JavaScript中,当需要在模板字符串中使用回勾字符时,必须转义它:
const stringWithBacktick = `\``;因此,模板字符串可能如下所示:
const preformatted = `\`\`\`${variable}\`\`\``;
console.log(marked(preformatted));或者,您也可以加入模板字符串,并使用下面的三重回标:
const preformatted = `${variable}`;
console.log(marked("```\n" + preformatted + "\n```"));或者,以一种更可重用的方式:
const preOpen = "```\n";
const preClose = "\n```";
const preformatted = `${preOpen}${variable}${preClose}`;
console.log(marked(preformatted));https://stackoverflow.com/questions/48674633
复制相似问题