class DataStyleSanitizer::Processor
def extract_styles
def extract_styles @doc.css("[data-style]").each do |node| style_string = node.get_attribute("data-style") next if style_string.nil? || style_string.strip.empty? # Skip empty attributes # Remove CSS comments and normalize spacing style_string = style_string.gsub(/\/\*.*?\*\//, "").strip style_string = style_string.split(";").map(&:strip).reject(&:empty?).join("; ") next if style_string.empty? # Skip if the style becomes empty after cleaning class_name = generate_class_name(style_string) # Apply class and remove attribute node.remove_attribute("data-style") node.set_attribute("class", [node.get_attribute("class"), class_name].compact.join(" ")) # Store unique styles @styles[class_name] ||= style_string end end