how to pass content to jekyll default converter after custom conversion?

后端 未结 1 1139
猫巷女王i
猫巷女王i 2021-01-06 05:46

I am trying to write a jekyll plugin which do something on markdown files first and passing the content back to the default converter

For example,

mo         


        
相关标签:
1条回答
  • 2021-01-06 06:34

    Here's how to do it:

    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
    

    Basically, you were right in using Jekyll::Converters::Markdown, but you need not specify KramdownParser, as your chosen parser will be automatically chosen from Jekyll::Site when you pass @config into the constructor.

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