简体   繁体   English

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

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

How to make a Markdown preformatted fixed-width code block for variables? 如何为变量制作Markdown预格式化的固定宽度代码块?
I mean code block language 我的意思是代码块语言

Examples: 例子:

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

If I understand correctly, your problem boils down to escaping the backticks. 如果我理解正确,那么您的问题归结为逃避了引号。

In JavaScript, when you need to use the backtick character inside a template string, you must escape it: 在JavaScript中,当您需要在模板字符串中使用反引号字符时,必须对其进行转义:

const stringWithBacktick = `\``;

Hence, your template string might look like this: 因此,您的模板字符串可能如下所示:

const preformatted = `\`\`\`${variable}\`\`\``;
console.log(marked(preformatted));

Alternatively, you could just join the template string with the triple backticks like this: 或者,您可以仅将模板字符串与三个反引号连接起来,如下所示:

const preformatted = `${variable}`;
console.log(marked("```\n" + preformatted + "\n```"));

Or, in a more reusable way: 或者,以更可重用的方式:

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