class Metanorma::Utils::Log

def current_location(node)

def current_location(node)
  if node.nil? then ""
  elsif node.respond_to?(:id) && !node.id.nil? then "ID #{node.id}"
  elsif node.respond_to?(:id) && node.id.nil? && node.respond_to?(:parent)
    while !node.nil? && node.id.nil?
      node = node.parent
    end
    node.nil? ? "" : "ID #{node.id}"
  elsif node.respond_to?(:to_xml) && node.respond_to?(:parent)
    while !node.nil? && node["id"].nil? && node.respond_to?(:parent)
      node = node.parent
    end
    node.respond_to?(:parent) ? "ID #{node['anchor'] || node['id']}" : ""
  elsif node.is_a? String then node
  elsif node.respond_to?(:lineno) && !node.lineno.nil? &&
      !node.lineno.empty?
    "Asciidoctor Line #{'%06d' % node.lineno}"
  elsif node.respond_to?(:line) && !node.line.nil?
    "XML Line #{'%06d' % node.line}"
  elsif node.respond_to?(:parent)
    while !node.nil? &&
        (!node.respond_to?(:level) || node.level.positive?) &&
        (!node.respond_to?(:context) || node.context != :section)
      node = node.parent
      return "Section: #{node.title}" if node.respond_to?(:context) &&
        node&.context == :section
    end
    "??"
  else "??"
  end
end