Sha256: 4554356eb015a4b190292624cf9ea18bc3cd266879cbbba5e3835882e5d70f4c

Contents?: true

Size: 1.22 KB

Versions: 80

Compression:

Stored size: 1.22 KB

Contents

# ------------------------------------------------------------------------------
# ~/_plugins/prettify.rb
# Liquid filter for J1 Template to beautify HTML code
#
# Product/Info:
# http://jekyll.one
#
# Copyright (C) 2021 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

80 entries across 80 versions & 1 rubygems

Version Path
j1-template-2022.0.18 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.17 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.16 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.15 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.14 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.13 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.12 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.11 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.10 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.9 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.8 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.7 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.6 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.5 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.4 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.3 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.2 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.1 lib/starter_web/_plugins/prettify.rb
j1-template-2022.0.0 lib/starter_web/_plugins/prettify.rb
j1-template-2021.3.2 lib/starter_web/_plugins/prettify.rb