# File lib/pdfkit/pdfkit.rb, line 118
  def append_stylesheets
    raise ImproperSourceError.new('Stylesheets may only be added to an HTML source') if stylesheets.any? && !@source.html?

    stylesheets.each do |stylesheet|
      if @source.to_s.match(/<\/head>/)
        @source = Source.new(@source.to_s.gsub(/(<\/head>)/) {|s| style_tag_for(stylesheet) + s })
      else
        @source.to_s.insert(0, style_tag_for(stylesheet))
      end
    end
  end