Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a Liquid filter from a Jekyll plugin

Liquid has two filters named newline_to_br and escape.

I'm working on a Jekyll plugin that needs to run a string through those filters. Rather than install a separate gem which does this, or write my own code for it, is there any way to call those filters directly from inside of the plugin?

like image 225
IQAndreas Avatar asked May 26 '26 21:05

IQAndreas


1 Answers

Those filters can become available with the line include Liquid::StandardFilters.

For example:

class PlaintextConverter
    include Liquid::StandardFilters
    def convert(content)
        content = escape(content)
        content = newline_to_br(content)
        content
    end
end

For a full list of functions that become available in this way, you can view the source of standardfilters.rb

like image 52
IQAndreas Avatar answered May 28 '26 15:05

IQAndreas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!