githubbuildmarkdowngithub-pages

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


I'm having a problem with my GitHub project. I'm trying to get it online at trustworthy.netlify.com, but there's a pagebuild error:

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/.

I thought that I could just add "}}" after {a}, but this is the line of code it's referring to:

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', '}']`.

I don't know enough about the Markdown Language or GitHub to know where to add the "}}", or even if I should, and I don't want to accidentally cause huge problems with my site. What should I do?


Solution

  • You need to escape the template syntax with {% raw %} and {% endraw %}.

    Jekyll passes your Markdown through the Liquid template system before it is parsed as Markdown. This allows you to define variables in your documents, which Liquid will swap out for content. The now complete document is then passed to the Markdown parser to be converted to HTML.

    While that is useful when you want to include variables in a document, it can be annoying when you want to include template like syntax as code samples in your Markdown. It is easy to assume that because the template syntax is in a code block or span, it will be ignored. However, Liquid has no knowledge of Markdown syntax and can't tell the difference between actual template variables and code samples.

    In your particular case, Liquid is raising an error insisting that {{a} should be {{a}}. Of course, that is not correct. {{a} is simply a code sample in your Markdown. But Jekyll never gets to the Markdown parser because it gets hung up on what Liquid sees as a template syntax error. Therefore, you need to use Liquid's escaping mechanism to tell Liquid to ignore the code samples:

    {% 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 %}
    

    By wrapping the complete paragraph in {% raw %} and {% endraw %} tags, we tell Liquid to ignore the contents and pass it through unaltered. Liquid will remove the raw tags and the Markdown parser will receive the content you intended.