Module: HtmlToMarkdown

Defined in:
lib/html_to_markdown.rb,
lib/html_to_markdown/version.rb,
ext/html_to_markdown_rb/src/html-to-markdown.rb,
ext/html_to_markdown_rb/src/html-to-markdown/version.rb

Overview

This file is auto-generated by alef — DO NOT EDIT. alef:hash:ea7b0309f2a6d285c48e922b5178305805266a4f1e223cf91395e98065c881a1 To regenerate: alef generate To verify freshness: alef verify –exit-code Issues & docs: github.com/kreuzberg-dev/alef frozen_string_literal: true

Constant Summary collapse

VERSION =
"3.4.0.pre.rc.21"

Class Method Summary collapse

Class Method Details

.convert(html, options = {}, visitor = nil) ⇒ String

Convert HTML to Markdown.

Parameters:

  • html (String)

    The HTML content to convert.

  • options (Hash) (defaults to: {})

    Optional conversion options. Supported keys (all optional):

    • :heading_style - ‘atx’, ‘atx_closed’, ‘setext’, ‘underlined’

    • :code_block_style - ‘backticks’, ‘tildes’, ‘indented’

    • :escape_asterisks - Boolean

    • :escape_underscores - Boolean

    • :escape_misc - Boolean

    • :escape_ascii - Boolean

    • :strip_newlines - Boolean

    • :keep_inline_images_in - Array of tag names

    • :strip_tags - Array of tag names to strip

    • :preserve_tags - Array of tag names to preserve verbatim

    (and more, matching ConversionOptions fields)

Returns:

  • (String)

    The converted Markdown content.



32
33
34
35
36
37
38
39
# File 'lib/html_to_markdown.rb', line 32

def self.convert(html, options = {}, visitor = nil)
  # The Rust FFI expects options as a JSON string; serialise the hash here
  # rather than constructing a ConversionOptions object, which the generated
  # FFI layer cannot coerce back to String (see issue #334).
  opts_json = options.nil? || options.empty? ? nil : options.to_json
  result = HtmlToMarkdownRs.convert(html, opts_json, visitor)
  result.content || ''
end