Javascript 用于变量的标记预格式化固定宽度代码块语言

Javascript 用于变量的标记预格式化固定宽度代码块语言,javascript,node.js,markdown,eslint,Javascript,Node.js,Markdown,Eslint,如何为变量制作标记预格式化的固定宽度代码块? 我指的是代码块语言 示例: `*${variable}*` // *bold text* ok `_${variable}_` // _italic text_ ok ````${variable}```` // ```pre-formatted fixed-width code block``` not work 如果我理解正确的话,你的问题归结为逃避挫折 在JavaScript中,当需要在模板字

如何为变量制作标记预格式化的固定宽度代码块?
我指的是代码块语言

示例:

`*${variable}*`      // *bold text*        ok
`_${variable}_`      // _italic text_      ok
````${variable}````  // ```pre-formatted fixed-width code block```   not work

如果我理解正确的话,你的问题归结为逃避挫折

在JavaScript中,当需要在模板字符串中使用反勾号字符时,必须对其进行转义:

const stringWithBacktick = `\``;
因此,您的模板字符串可能如下所示:

const preformatted = `\`\`\`${variable}\`\`\``;
console.log(marked(preformatted));
const preformatted = `${variable}`;
console.log(marked("```\n" + preformatted + "\n```"));
或者,您可以使用三个反勾号连接模板字符串,如下所示:

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));

您是否尝试过在字符和代码之间添加换行符?我遇到了解析错误:意外标记,应为“,”