Class: Nukitori::HtmlPreprocessor
- Inherits:
-
Object
- Object
- Nukitori::HtmlPreprocessor
- Defined in:
- lib/nukitori/html_preprocessor.rb
Overview
Preprocesses HTML to reduce token size for LLM
Class Method Summary collapse
-
.process(html) ⇒ String
Cleaned HTML.
Class Method Details
.process(html) ⇒ String
Returns Cleaned HTML.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/nukitori/html_preprocessor.rb', line 8 def self.process(html) doc = html.is_a?(Nokogiri::HTML::Document) ? html.dup : Nokogiri::HTML(html) # Remove non-content elements doc.css('script, style, noscript, svg, path, meta, link, head').remove # Remove style attributes doc.css('*').each { |node| node.remove_attribute('style') } # Collapse whitespace doc.to_html.gsub(/\s+/, ' ') end |