不知道如何关闭 MD 文件中的变量

Don't know how to close a variable in an MD file

我的 GitHub 项目有问题。我试图在 trustworthy.netlify.com 上在线获取它,但出现页面构建错误:

Your site is having problems building: The variable {{a} on line 50 in functions/node_modules/balanced-match/README.md was not properly closed with }}. For more information, see https://help.github.com/articles/page-build-failed-tag-not-properly-terminated/.

我认为我可以在 {a} 之后添加“}}”,但这是它所指的代码行:

If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.

我对 Markdown 语言或 GitHub 了解不够,不知道在哪里添加“}}”,即使我应该知道,我不想不小心造成巨大的问题我的网站。我该怎么办?

您需要使用 {% raw %}{% endraw %} 转义模板语法。

Jekyll passes your Markdown through the Liquid 解析为 Markdown 之前的模板系统。这允许您在文档中定义变量,Liquid 将用这些变量替换内容。然后将现在完整的文档传递给 Markdown 解析器以将其转换为 HTML。

虽然当你想在文档中包含变量时这很有用,但当你想在 Markdown 中包含模板之类的语法作为代码示例时,它可能会很烦人。很容易假设因为模板语法在代码块或代码段中,所以它会被忽略。但是,Liquid 不了解 Markdown 语法,无法区分实际模板变量和代码示例。

在您的特定情况下,Liquid 提出了一个错误,坚持认为 {{a} 应该是 {{a}}。当然,这是不正确的。 {{a} 只是 Markdown 中的代码示例。但是 Jekyll 永远不会进入 Markdown 解析器,因为它挂在 Liquid 认为是模板语法错误的地方。因此,您需要使用 Liquid 的 escaping mechanism 来告诉 Liquid 忽略代码示例:

{% raw %}
If the `str` contains more `a` than `b` / there are unmatched pairs, 
the first match that was closed will be used. For example, `{{a}` 
will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
{% endraw %}

通过将整个段落包裹在 {% raw %}{% endraw %} 标签中,我们告诉 Liquid 忽略内容并通过它不加改变地传递。 Liquid 将删除原始标签,Markdown 解析器将收到您想要的内容。