Jekyll 如何防止KRAMBUT被C++包含混淆?

Jekyll 如何防止KRAMBUT被C++包含混淆?,jekyll,kramdown,Jekyll,Kramdown,我写了这个插件: module Jekyll module Tags class Prism < Liquid::Block def initialize(tag_name, text, tokens) @arg = text.strip super end def render(context)

我写了这个插件:

module Jekyll
    module Tags
        class Prism < Liquid::Block
            def initialize(tag_name, text, tokens)
                @arg = text.strip
                super
            end

            def render(context)
                output = super(context)
                "<pre><code class=\"language-#{@arg}\">#{output}</code></pre>"
            end
        end
    end
end 

Liquid::Template.register_tag('prism', Jekyll::Tags::Prism)
终止 终止 终止 终止 液体::模板。注册标签'prism',杰基尔::标签::prism 我就是这样使用它的:

{% highlight cpp %}
#include <iostream>

// Hello World
int main()
{
    cout << "hello world" << endl;
    int a = 10;
}
{% endhighlight %}
现在,问题是,我在网站上主要使用C++代码。当我现在用Jekyll生成这个标记时,{%endprism%}之后的所有文本仍然在标记中,因为Kramdown被我的转义弄糊涂了,\,然后我的插件按预期工作,但我的Javascript荧光笔被弄糊涂了


在不启用Jekyll的荧光灯的情况下,我如何解决这种情况?

我认为您试图使用中使用的防护代码块

你为什么不把现成的作品用在cpp上呢?高亮显示的基本css可用

尝试:


CGI模块中有一个函数,它允许转义HTML,就像PHP中的htmlspecialchars一样。我将liquid插件更改为以下内容:

终止 终止 终止 终止 液体::模板。注册标签'prism',杰基尔::标签::prism 它将全部转义为html特殊字符。因此Kramdown不会感到困惑,prism.js仍然能够正确地突出显示代码


因为我想使用prism.js。当杰基尔解析这个时,克拉姆敦怎么会不感到困惑呢?它是一样的,只是一个不同的降价标签。。。高亮显示而不是棱柱。此外,学习插件的东西。
{% highlight cpp %}
#include <iostream>

// Hello World
int main()
{
    cout << "hello world" << endl;
    int a = 10;
}
{% endhighlight %}
require 'cgi'

module Jekyll
    module Tags     
        class Prism < Liquid::Block
            def initialize(tag_name, text, tokens)
                @arg = text.strip
                super
            end

            def render(context)
                output = super(context)
                output = CGI.escapeHTML(output);
                "<pre><code class=\"language-#{@arg}\">#{output}</code></pre>"
            end
        end
    end
end 

Liquid::Template.register_tag('prism', Jekyll::Tags::Prism)