2014-03-31 31 views
2

我想先寫一個哲基爾插件,它做的東西就降價文件,並通過內容返回到默認的轉換器如何在自定義轉換後將內容傳遞給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

這裏是如何做到這一點:

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,但是當你通過@config到構造函數,你不需要指定KramdownParser,爲您所選擇的解析器將Jekyll::Site自動選擇。

+0

事實證明https://github.com/navarroj/krampygs解決了我的問題。感謝您的輸入。 –

相關問題