Sha256: ebb818318cad5eb9020880a1fbebd9cec816462e5ac28773f2c81db523ff7f04

Contents?: true

Size: 1.24 KB

Versions: 27

Compression:

Stored size: 1.24 KB

Contents

# ------------------------------------------------------------------------------
#  ~/_plugins/prettify.rb
#  Liquid filter for J1 Template to beautify HTML code
#
#  Product/Info:
#  http://jekyll.one
#
#  Copyright (C) 2019 Juergen Adams
#
#  J1 Template is licensed under the MIT License.
#  See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
#
# ------------------------------------------------------------------------------
#
#   NOTE:
#   CustomFilters cannot be used in SAFE mode (e.g not usable for
#   rendering pages with Jekyll on GitHub
#
#   USAGE:
#     {% capture cache_name %}
#
#       liquid code to generate HTML output goes here
#
#     {% endcapture %}
#     {{ cache_name | pretty_print }}
#
# ------------------------------------------------------------------------------
require 'nokogiri'
require 'nokogiri-pretty'
require 'htmlbeautifier'

module Jekyll
  module PrettyPrint
    def pretty_print(input)
      # 1st_stage cleanup
      content = Nokogiri::HTML input
      parsed_content = content.to_html
      # 2nd_stage cleanup
      pretty = HtmlBeautifier.beautify(parsed_content)
      pretty = pretty.sub('\s*<!DOCTYPE html>">','<!DOCTYPE html>')
    end
  end
end

Liquid::Template.register_filter(Jekyll::PrettyPrint)

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
j1_template_mde-2018.4.36 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.35 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.34 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.33 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.32 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.31 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.30 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.29 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.28 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.27 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.26 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.25 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.24 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.23 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.22 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.21 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.20 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.19 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.18 lib/starter_web/_plugins/prettify.rb
j1_template_mde-2018.4.17 lib/starter_web/_plugins/prettify.rb