Class: SwarmSDK::Tools::DocumentConverters::HtmlConverter

Inherits:
BaseConverter
  • Object
show all
Defined in:
lib/swarm_sdk/tools/document_converters/html_converter.rb

Overview

Converter for HTML to Markdown Uses reverse_markdown gem if available, otherwise falls back to simple regex-based conversion

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseConverter

available?, gem_available?

Class Method Details

.extensionsObject



18
19
20
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 18

def extensions
  [".html", ".htm"]
end

.format_nameObject



14
15
16
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 14

def format_name
  "HTML"
end

.gem_nameObject



10
11
12
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 10

def gem_name
  "reverse_markdown"
end

Instance Method Details

#convert(file_path) ⇒ String

Convert HTML file to Markdown

Parameters:

  • file_path (String)

    Path to HTML file

Returns:

  • (String)

    Markdown content



37
38
39
40
41
42
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 37

def convert(file_path)
  html = File.read(file_path)
  convert_string(html)
rescue StandardError => e
  error("Failed to read HTML file: #{e.message}")
end

#convert_string(html) ⇒ String

Convert HTML string to Markdown

Parameters:

  • html (String)

    HTML content to convert

Returns:

  • (String)

    Markdown content



26
27
28
29
30
31
32
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 26

def convert_string(html)
  if self.class.available?
    convert_with_gem(html)
  else
    convert_simple(html)
  end
end