Class: SwarmSDK::Tools::DocumentConverters::HtmlConverter
- Inherits:
-
BaseConverter
- Object
- BaseConverter
- SwarmSDK::Tools::DocumentConverters::HtmlConverter
- 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
-
#convert(file_path) ⇒ String
Convert HTML file to Markdown.
-
#convert_string(html) ⇒ String
Convert HTML string to Markdown.
Methods inherited from BaseConverter
Class Method Details
.extensions ⇒ Object
18 19 20 |
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 18 def extensions [".html", ".htm"] end |
.format_name ⇒ Object
14 15 16 |
# File 'lib/swarm_sdk/tools/document_converters/html_converter.rb', line 14 def format_name "HTML" end |
.gem_name ⇒ Object
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
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
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 |