Jekyll:标记出现在 <p> 标签中

Jekyll: Markup Appearing in <p> Tag

我遇到了一个问题,我的 _/includes 文件夹中文件中的一些标记被打印到我的 <p> 标签内的页面。

这是我的 _includes/gallery.html 文件中的内容:

{% assign rows = page.gallery[include.gallery] %}

    </section> <!-- close this -->
  </div> <!-- and this -->
</div> <!-- this too -->

<section class="image-gallery">
  ...
</section>

<div class="container"> <!-- open this -->
  <div> <!-- and this -->
    <section> <!-- this too -->

我正在尝试关闭一些元素,然后在 .image-gallery 之后重新打开它们。但出于某种原因,我的结束标签和开始标签打印在 <p> 标签

像这样:

<pre><code>&lt;/section&gt;
  </code></pre>
    <p>&lt;/div&gt;
    &lt;/div&gt;</p>

    <section class="image-gallery">
        ...

有什么办法可以阻止这种情况发生吗?它似乎只影响非封闭标签,就像我例子中的标签一样。 .image-gallery 中的所有内容都正确显示。

有人知道为什么会这样吗?任何帮助表示赞赏。提前致谢!

好的,我明白了。

您从 .md 文件中包含 _includes/gallery.html,因此 markdown 首先包含,然后尝试解析代码。

由于您的代码开头有未打开的标签 (</section></div></div>),它们被视为降价,而不是 html。

编辑:

解决方案是用 :

包围您的代码
{::nomarkdown}
your code here
{:/nomarkdown}

这可以避免您的 html 被 kramdown 解析。