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

时间:2015-05-10 12:18:10

标签: jekyll kramdown

我写过这个插件:

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 cpp %}
#include <iostream>

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

现在,问题是,我主要在我的网站上使用C ++代码。当我现在使用Jekyll生成此降价时,{% endprism %}之后的所有文本仍然在<pre>标记内,因为Kramdown被<iostream>弄糊涂了如果我逃避它,({{1}然后我的插件按预期工作,但我的Javascript荧光笔让人感到困惑。

如果不启用Jekyll的荧光笔,我怎样才能解决这种情况呢?

1 个答案:

答案 0 :(得分:0)

我认为您尝试使用GitHub Flavored Markdown中使用的隔离代码块。

为什么不使用cpp完全开箱即用的Jekyll code highlighting作品?可以使用基本css突出显示here

尝试:

{% highlight cpp %}
#include <iostream>

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