You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: truncate_html.rb
    path of file: ./repos/middleman-blog/lib/middleman-blog
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

begin
  require 'nokogiri'
rescue LoadError
  raise "Nokogiri 
    
    def truncate(max_length, ellipsis)
      return self if inner_text.length <= max_length

      truncated_node = dup
      truncated_node.children.remove

      children.each do |node|
        remaining_length = max_length - truncated_node.inner_text.length
        break if remaining_length <= 0

        truncated_node.add_child node.truncate(remaining_length, ellipsis)
      end
      truncated_node
    end