在Jekyll前端中包含HTML(帖子标题)

问题描述 投票:3回答:1

如何将HTML标签放置在Jekyll帖子(经YAML编码)的开头,并阻止该HTML在最终输出中转义?我的内容(包括帖子标题)除使用首页语言外,还使用多种语言,并且这需要使用span lang="XX"标签进行适当的标记,以用于屏幕阅读器和某些自动提取。但是,尝试编写以下内容:

---
layout: post
title: A post that says <span lang="fr">Bonjour</span> and <span lang="es">Hola</span>
---

导致这些标记转义的HTML输出结果:

<h1 class="post-title p-name" itemprop="name headline">A post that says &lt;span lang=&quot;fr&quot;&gt;Bonjour&lt;/span&gt; and &lt;span lang=&quot;es&quot;&gt;Hola&lt;/span&gt;</h1>
html jekyll
1个回答
1
投票

因此,您正在使用的Jekyll的minima theme上,在escape上已根据设计设置了escape过滤器。

从文档中:

通过用转义序列替换字符来转义字符串(例如,可以在URL中使用该字符串)。它不会更改没有任何可转义的字符串。

来源:page.title] >>

如果要显示https://shopify.github.io/liquid/filters/escape/,则应编辑文件__ layout / post.html

并删除此span过滤器。

此文件的第7行应如下所示

espace

来源: <h1 class="post-title p-name" itemprop="name headline">{{ page.title | escape }}</h1>

] >>

更改它,使其显示为

https://github.com/jekyll/minima/blob/49f6dce0727a2441f0b0c265b41b5efc7b042eb6/_layouts/post.html#L7

然后您将达到预期的行为。

© www.soinside.com 2019 - 2024. All rights reserved.