如何使用Jekyll和Markdown自动转义HTML内容? [英] How can I automatically escape HTML content using Jekyll and Markdown?

查看:161
本文介绍了如何使用Jekyll和Markdown自动转义HTML内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在foo.markdown中,我有以下内容:

In foo.markdown I have the following:

---
layout: default
title: Snarky little Ewok
---

A little Ewok is sometimes referred too as <h3>. But pappa Ewok is called <h1> - if you know what's good for you.

好吧,我希望Jekyll自动对大于和小于字符的html进行转义.经过今天的学徒训练后,我感到非常疲倦,而且我懒得手动手动逃脱html:> h3<

Well, I want Jekyll to automatically html escape the greater than and less than characters. I'm seriously fatigued after today's apprentice training and I'm just too lazy to manually html escape myself: >h3<

是否有配置选项或自动跳出Jekyll降价内容的内容?

Is there a config option or something to automatically escape Jekyll markdown content?

推荐答案

如果您使用纺织品而不是降价促销,那将是一种方法.

If you used textile instead of markdown, there would be a way.

液体标记具有将其纹理化和逃脱过滤器;这两个可以让您做自己想做的,但要在纺织品上做.您将必须将文件另存为文本(文件扩展名:txt),然后在进行文本化之前对html进行转义:

Liquid markup has textilize & escape filters; those two would allow you to do what you wanted, but on textile. You would have to save your files as text (file extension: txt), and then escape the html before textilizing:

---
layout: default
title: Snarky little Ewok
---

This file's extension is .txt

A little Ewok is sometimes referred too as <h3>. But pappa Ewok is called <h1> - if you know what's good for you.

然后使用default.html布局,而不是:

Then on the default.html layout, instead of having:

{{ page.content }}

您将拥有:

{{ page.content | xml_escape | textilize }}

由于Jekyll上还没有"markdownify"过滤器,因此您无法使用markdown做到这一点. Jekyll有一个问题(问题)用于添加markdownify过滤器.

Since there's no 'markdownify' filter on Jekyll yet, you can't do that with markdown. There's an issue (Issue 134) on Jekyll for adding a markdownify filter.

现在可以使用markdown(自jekyll 0.10.1起)

It's now possible to use markdown (since jekyll 0.10.1)

{{ page.content | xml_escape | markdownify }}

这篇关于如何使用Jekyll和Markdown自动转义HTML内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆