繁体   English   中英

Markdown变量的预格式化固定宽度代码块语言

[英]Markdown preformatted fixed-width code block language for variables

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

例子:

`*${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 preOpen = "```\n";
const preClose = "\n```";
const preformatted = `${preOpen}${variable}${preClose}`;
console.log(marked(preformatted));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM