4

最初にマークダウンファイルで何かを行い、コンテンツをデフォルトのコンバーターに戻すjekyllプラグインを作成しようとしています

例えば、

module Jekyll
    class RMarkdownConverter < Converter
        safe :false
        priority :high

        def matches(ext)
            ext =~ /^\.(md|markdown)$/i
        end

        def output_ext(ext)
            ".html"
        end

        def convert(content)
            # do something with content
            # then pass it back to default converter
        end
    end
end

今、私が手に入れることができる最も近いもの

converter = Jekyll::Converters::Markdown::KramdownParser.new(@config)
converter.convert(content)

しかし、すべての強調表示コードの色が失われています...そして、他の問題があると思われます...

私の質問は次のとおりです。デフォルトのコンバーターを呼び出す正しい方法は何ですか?

4

1 に答える 1

6

方法は次のとおりです。

module Jekyll
    class MyConverter < Converter
        safe :false
        priority :high

        def matches(ext)
            ext =~ /^\.(md|markdown)$/i
        end

        def output_ext(ext)
            ".html"
        end

        def convert(content)
            # do your own thing with the content
            content = my_own_thing(content)

            # Now call the standard Markdown converter
            site = Jekyll::Site.new(@config)
            mkconverter = site.getConverterImpl(Jekyll::Converters::Markdown)
            mkconverter.convert(content)
        end
    end
end

基本的に、 を使用するのは正しかったのですが、 をJekyll::Converters::Markdown指定する必要はありません。コンストラクターに渡すときにKramdownParser、選択したパーサーが自動的に選択されるためです。Jekyll::Site@config

于 2014-09-27T13:53:42.007 に答える