【问题标题】:Don't know how to close a variable in an MD file不知道如何关闭 MD 文件中的变量
【发布时间】:2019-04-10 08:07:22
【问题描述】:

我的 GitHub 项目有问题。我正在尝试通过 trustworthy.netlify.com 使其在线,但出现页面构建错误:

您的网站在构建时遇到问题:functions/node_modules/balanced-match/README.md 中第 50 行的变量 {{a} 未使用 }} 正确关闭。如需更多信息,请参阅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 的了解不够,不知道在哪里添加“}}”,或者即使我应该添加,我也不想意外地给我的网站造成巨大的问题。我该怎么办?

【问题讨论】:

  • 您在 Github 上进行版本控制并在 Netlify 上进行部署。这个错误来自哪里(github页面或netlify部署)?你在用 Jekyll 吗?

标签: github build markdown github-pages readme


【解决方案1】:

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

Jekyll passes 你的 Markdown 在被解析为 Markdown 之前通过 Liquid 模板系统。这允许您在文档中定义变量,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 解析器将接收您想要的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多