1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Fix nokogiri errors

This commit is contained in:
James Cox 2019-01-22 16:43:22 -05:00
parent bf1ff1368c
commit 1e5c6c92f4
2 changed files with 31 additions and 1 deletions

View file

@ -0,0 +1,30 @@
require_relative '../base_formatter'
module AwesomePrint
module Formatters
class NokogiriDocumentFormatter < BaseFormatter
formatter_for :nokogiri_xml_document
def self.formattable?(object)
defined?(::Nokogiri) && object.is_a?(::Nokogiri::XML::Document)
end
def format(object)
xml = object.to_xml(indent: 2)
#
# Colorize tag, id/class name, and contents.
#
xml.gsub!(/(<)(\/?[A-Za-z1-9]+)/) { |tag| "#{$1}#{colorize($2, :keyword)}" }
xml.gsub!(/(id|class)="[^"]+"/i) { |id| colorize(id, :class) }
xml.gsub!(/>([^<]+)</) do |contents|
contents = colorize($1, :trueclass) if contents && !contents.empty?
">#{contents}<"
end
xml
end
end
end
end

View file

@ -2,7 +2,7 @@ require_relative '../base_formatter'
module AwesomePrint
module Formatters
class NokogiriNodeFormatter < BaseFormatter
class NokogiriNodesetFormatter < BaseFormatter
formatter_for :nokogiri_xml_nodeset