gpt4 book ai didi

Jekyll strip_html 但允许某些 HTML 标签

转载 作者:行者123 更新时间:2023-12-02 18:14:08 31 4
gpt4 key购买 nike

在我的 Jekyll 帖子中,我使用 strip_html在主页上显示该帖子的 50 字简短介绍:

<p>{{ post.content | strip_html | truncatewords:50 }}</p>

strip_html从此摘录中删除所有 HTML。但我想包含一些 HTML,特别是 <i><p> .

是否有用于执行此操作的配置( _config.yaml ),或者是否存在 strip_html 的限制没有自定义功能?

最佳答案

据我所知,没有内置的方法来自定义 strip_html

如果您有一个专属的(而且不是太长)所需标签列表,您可以首先在要保留的标签上使用 replace 将其替换为非 html 标记,然后使用strip_html,然后再次replace来取回html:

{% assign preprocessed_content=post.content | replace: '<p>', '__p__' %}
{% assign preprocessed_content=preprocessed_content | replace: '</p>', '__/p__' %}

{% assign truncated_content=preprocessed_content | strip_html | truncatewords:50 %}

{% assign cleaned_content=truncated_content | replace: '__p__', '<p>' %}
{% assign cleaned_content=cleaned_content | replace: '__/p__', '</p>' %}

<p>{{ cleaned_content }}</p>

关于Jekyll strip_html 但允许某些 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39691139/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com