2016-09-25 7 views
2

ジキルのstrip_htmlは許可し、特定のHTMLタグ私のジキルポストで

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

strip_htmlこの抜粋からすべてのHTMLを削除します。しかし、私はいくつかのHTML、具体的には<i><p>を含めたいと思います。

これを行うための設定(_config.yaml)がありますか、またはstrip_htmlにカスタマイズされていない制限がありますか?

答えて

2

AFAIK strip_htmlをカスタマイズする組み込みの方法はありません。

あなたが排他持っている場合は - そう長くはない - あなたの指名手配タグのリストを、あなたはまず、非HTMLのマーカーに置き換えて再びstrip_html、およびreplaceを使用するために保存しておきたいタグの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> 
+0

ありがとう、私はこれを試してみます。 –

関連する問題