How can I automatically escape HTML content using Jekyll and Markdown?

后端 未结 1 1605
庸人自扰
庸人自扰 2021-02-13 19:42

In foo.markdown I have the following:

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

A little Ewok is sometimes referred too as 

. But pappa Ewok is

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-13 20:23

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

    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 

    . But pappa Ewok is called

    - if you know what's good for you.

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

    {{ page.content }}
    

    You would have this:

    {{ page.content | xml_escape | textilize }}
    

    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.

    EDIT:

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

    {{ page.content | xml_escape | markdownify }}
    

    0 讨论(0)
提交回复
热议问题