Sha256: bdb9c7296d08645fa7971a22dced7f14c93c353d1542745c2dceb5bd96805058

Contents?: true

Size: 1.24 KB

Versions: 7

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-org/j1_template/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

7 entries across 7 versions & 1 rubygems

Version Path
j1_template-2019.4.12 lib/starter_web/_plugins/prettify.rb
j1_template-2019.4.11 lib/starter_web/_plugins/prettify.rb
j1_template-2019.4.10 lib/starter_web/_plugins/prettify.rb
j1_template-2019.4.8 lib/starter_web/_plugins/prettify.rb
j1_template-2019.4.7 lib/starter_web/_plugins/prettify.rb
j1_template-2019.4.5 lib/starter_web/_plugins/prettify.rb
j1_template-2019.4.4 lib/starter_web/_plugins/prettify.rb