html-to-markdown 3.10.4 → 3.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2890030d32e03328ad17607655c944c1cfa52b66bc995f0c6a2be27d4e74c4bc
4
- data.tar.gz: d300b5b60b90df9913fd29c266244e0cf0f10fc9e491f9627379c5efce2ba51c
3
+ metadata.gz: 5d86281ca72b53b8f6b281a4243f7545dba4b495ff3363a0ea06f86e54be0c5e
4
+ data.tar.gz: ede622514b81fcba60b1afc2226ecb7f301396826c546628b889048fad0b634b
5
5
  SHA512:
6
- metadata.gz: 556ed54ead9067bb60a413f341e970322bf690a9c4a095355f2c29fcef18664863d06e03894d7a166efeffcfadd06787c4275f72da0fe7ec1bee7ed1357858f0
7
- data.tar.gz: cadd2c07a91b7d2f4db8c6e6ec5fd5cd40d56f0baab0c64f250bb7c2147680c2d5a45f320ae63311d29970a63319400805f00d9cfb24f860f3d6e28696b1e4d9
6
+ metadata.gz: 34cae0f9407bc236abaa39293815457b9a8137dcd9fcd43ae5e07963645eaf0fee3c5fcc74af8dc42794341822fcd6d07e89e67cb93023bc944b6145236b0e86
7
+ data.tar.gz: 4c16de0839f8aecd191202bc0dbf3ea54788a4f26f224221cb31025e1b4a10a4f71e626c78bb7c0f51a38a1f5501c9c6699adda0b9ab5a4dc0ae7a56492c4bf1
data/README.md CHANGED
@@ -111,11 +111,23 @@ Requires Ruby 3.2+ with Magnus native extension bindings. Published for Linux, m
111
111
 
112
112
  Basic conversion:
113
113
 
114
- <!-- snippet not found: getting-started/basic_usage.md -->
114
+ ```ruby
115
+ require 'html_to_markdown'
116
+
117
+ html = "<h1>Hello</h1><p>This is <strong>fast</strong>!</p>"
118
+ result = HtmlToMarkdown.convert(html)
119
+ markdown = result.content
120
+ ```
115
121
 
116
122
  With conversion options:
117
123
 
118
- <!-- snippet not found: getting-started/with_options.md -->
124
+ ```ruby
125
+ require 'html_to_markdown'
126
+
127
+ html = "<h1>Hello</h1><p>This is <strong>fast</strong>!</p>"
128
+ result = HtmlToMarkdown.convert(html, heading_style: :atx, code_block_style: :fenced)
129
+ markdown = result.content
130
+ ```
119
131
 
120
132
  ## Architecture
121
133
 
@@ -140,20 +152,19 @@ The dispatcher is invisible to the caller. Output is byte-identical across tiers
140
152
 
141
153
  ### Core Function
142
154
 
143
- **`convert(html, options: nil, visitor: nil) -> ConversionResult`**
155
+ **`convert(html, options_or_visitor = nil) -> ConversionResult`**
144
156
 
145
- Converts HTML to Markdown. Returns a `ConversionResult` hash with all results in a single call.
157
+ Converts HTML to Markdown. Returns a `ConversionResult` object with accessor methods for all results in a single call. The second positional argument accepts either an options `Hash`/`ConversionOptions` or a visitor object — not both.
146
158
 
147
159
  ```ruby
148
160
  require 'html_to_markdown'
149
161
 
150
162
  result = HtmlToMarkdown.convert(html)
151
- markdown = result[:content] # Converted Markdown string
152
- metadata = result[:metadata] # Metadata (when extract_metadata: true)
153
- tables = result[:tables] # Structured table data
154
- document = result[:document] # Document-level info
155
- images = result[:images] # Extracted images
156
- warnings = result[:warnings] # Any conversion warnings
163
+ markdown = result.content # Converted Markdown string
164
+ metadata = result.metadata # Metadata (when extract_metadata: true)
165
+ tables = result.tables # Structured table data (when include_document_structure: true)
166
+ document = result.document # Document-level info
167
+ warnings = result.warnings # Any conversion warnings
157
168
  ```
158
169
 
159
170
  ### Options
@@ -194,12 +205,12 @@ html = "<p>This is <strong>bold</strong> and <em>italic</em> text.</p>"
194
205
 
195
206
  # Default Markdown output
196
207
  markdown_result = HtmlToMarkdown.convert(html)
197
- markdown = markdown_result[:content]
208
+ markdown = markdown_result.content
198
209
  # Result: "This is **bold** and *italic* text."
199
210
 
200
211
  # Djot output
201
212
  djot_result = HtmlToMarkdown.convert(html, output_format: 'djot')
202
- djot = djot_result[:content]
213
+ djot = djot_result.content
203
214
  # Result: "This is *bold* and _italic_ text."
204
215
  ```
205
216
 
@@ -215,7 +226,7 @@ require 'html_to_markdown'
215
226
  html = "<h1>Title</h1><p>This is <strong>bold</strong> and <em>italic</em> text.</p>"
216
227
 
217
228
  result = HtmlToMarkdown.convert(html, output_format: 'plain')
218
- plain = result[:content]
229
+ plain = result.content
219
230
  # Result: "Title\n\nThis is bold and italic text."
220
231
  ```
221
232
 
@@ -243,12 +254,12 @@ require 'html_to_markdown'
243
254
  html = '<h1>Article</h1><img src="test.jpg" alt="test">'
244
255
  result = HtmlToMarkdown.convert(html, extract_metadata: true)
245
256
 
246
- puts result[:content] # Converted Markdown
247
- puts result[:metadata][:document][:title] # Document title
248
- puts result[:metadata][:headers] # All h1-h6 elements
249
- puts result[:metadata][:links] # All hyperlinks
250
- puts result[:metadata][:images] # All images with alt text
251
- puts result[:metadata][:structured_data] # JSON-LD, Microdata, RDFa
257
+ puts result.content # Converted Markdown
258
+ puts result.metadata.document.title # Document title
259
+ puts result.metadata.headers # All h1-h6 elements
260
+ puts result.metadata.links # All hyperlinks
261
+ puts result.metadata.images # All images with alt text
262
+ puts result.metadata.structured_data # JSON-LD, Microdata, RDFa
252
263
  ```
253
264
 
254
265
  ## Visitor Pattern
@@ -276,18 +287,21 @@ class MyVisitor
276
287
  if href.start_with?('https://old-cdn.com')
277
288
  href = href.sub('https://old-cdn.com', 'https://new-cdn.com')
278
289
  end
279
- { type: :custom, output: "[#{text}](#{href})" }
290
+ # Directive keys/symbols are matched case-sensitively: :Custom, :Skip, :Continue.
291
+ { Custom: "[#{text}](#{href})" }
280
292
  end
281
293
 
282
294
  def visit_image(ctx, src, alt = nil, title = nil)
283
295
  # Skip tracking pixels
284
- src.include?('tracking') ? { type: :skip } : { type: :continue }
296
+ src.include?('tracking') ? :Skip : :Continue
285
297
  end
286
298
  end
287
299
 
288
300
  html = '<a href="https://old-cdn.com/file.pdf">Download</a>'
289
- result = HtmlToMarkdown.convert(html, visitor: MyVisitor.new)
290
- markdown = result[:content]
301
+ # The visitor is the second positional argument — it cannot be combined
302
+ # with an options Hash in the same call.
303
+ result = HtmlToMarkdown.convert(html, MyVisitor.new)
304
+ markdown = result.content
291
305
  ```
292
306
 
293
307
  ## Examples
@@ -1,7 +1,7 @@
1
1
 
2
2
  [package]
3
3
  name = "html-to-markdown-rb"
4
- version = "3.10.4"
4
+ version = "3.10.5"
5
5
  edition = "2024"
6
6
  license = "MIT"
7
7
  [workspace]
@@ -260,7 +260,7 @@ checksum = "46c1ff2d1cbf39efe5af0900ced8a069b5e61557a17544eb0c4a50239937389e"
260
260
 
261
261
  [[package]]
262
262
  name = "html-to-markdown-rb"
263
- version = "3.10.2"
263
+ version = "3.10.4"
264
264
  dependencies = [
265
265
  "async-trait",
266
266
  "html-to-markdown-rs",
@@ -274,9 +274,9 @@ dependencies = [
274
274
 
275
275
  [[package]]
276
276
  name = "html-to-markdown-rs"
277
- version = "3.10.4"
277
+ version = "3.10.5"
278
278
  source = "registry+https://github.com/rust-lang/crates.io-index"
279
- checksum = "1b0fdf3ba00130a03686f79af007ba066f13e2b0ea3d736ede049cfd8b55015a"
279
+ checksum = "8d8796ce09cd945c9c31d0b7f273304768a54bfe95c6383e31fd09fef80fcb49"
280
280
  dependencies = [
281
281
  "ahash",
282
282
  "astral-tl",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "html-to-markdown-rb"
3
- version = "3.10.2"
3
+ version = "3.10.4"
4
4
  edition = "2024"
5
5
  license = "MIT"
6
6
  description = "High-performance HTML to Markdown converter"
@@ -25,7 +25,7 @@ visitor = ["html-to-markdown-rs/visitor"]
25
25
 
26
26
  [dependencies]
27
27
  async-trait = "0.1"
28
- html-to-markdown-rs = { version = "3.10.4", features = ["serde", "metadata", "visitor", "inline-images", "testkit"] }
28
+ html-to-markdown-rs = { version = "3.10.5", features = ["serde", "metadata", "visitor", "inline-images", "testkit"] }
29
29
  magnus = "0.8"
30
30
  rb-sys = ">=0.9, <0.9.128"
31
31
  serde = { version = "1", features = ["derive"] }
@@ -1,5 +1,5 @@
1
1
  // This file is auto-generated by alef. DO NOT EDIT.
2
- // alef:hash:9fe2f7328e5ff759a03fb0c68b0bd7281cbe14bbf83d07480cf79d29af39167b
2
+ // alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
3
3
  // Re-generate with: alef generate
4
4
  #![allow(dead_code, unused_imports, unused_variables)]
5
5
  #![allow(
@@ -1,5 +1,5 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:9fe2f7328e5ff759a03fb0c68b0bd7281cbe14bbf83d07480cf79d29af39167b
2
+ # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
3
3
  # To regenerate: alef generate
4
4
  # To verify freshness: alef verify --exit-code
5
5
  # frozen_string_literal: true
@@ -1,10 +1,10 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:bc59c59d83dd11947315504c8b33d8146488c6506d5ccc0f1f36a602630a84d4
2
+ # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
3
3
  # To regenerate: alef generate
4
4
  # To verify freshness: alef verify --exit-code
5
5
  # frozen_string_literal: true
6
6
 
7
7
  module HtmlToMarkdown
8
8
  ## The version string for this package.
9
- VERSION = "3.10.4"
9
+ VERSION = "3.10.5"
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:9fe2f7328e5ff759a03fb0c68b0bd7281cbe14bbf83d07480cf79d29af39167b
2
+ # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
3
3
  # To regenerate: alef generate
4
4
  # To verify freshness: alef verify --exit-code
5
5
  # frozen_string_literal: true
@@ -17,11 +17,5 @@ module HtmlToMarkdown
17
17
  # Re-export all types and functions from native extension
18
18
  end
19
19
 
20
- # Bring top-level HtmlToMarkdown classes into the global namespace so callers
21
- # (and the generated e2e suite) can reference them unqualified. The native
22
- # extension has already been required above, so every type constant is defined
23
- # under HtmlToMarkdown by this point.
24
- HtmlToMarkdown.constants.each do |const_name|
25
- value = HtmlToMarkdown.const_get(const_name)
26
- ::Object.const_set(const_name, value) if value.is_a?(Module) && !::Object.const_defined?(const_name)
27
- end
20
+ # Keep generated types under HtmlToMarkdown. Publishing generated constants
21
+ # into Object makes generic names collide with unrelated Ruby libraries.
Binary file
data/sig/types.rbs CHANGED
@@ -1,5 +1,5 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:9fe2f7328e5ff759a03fb0c68b0bd7281cbe14bbf83d07480cf79d29af39167b
2
+ # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
3
3
  # To regenerate: alef generate
4
4
  # To verify freshness: alef verify --exit-code
5
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-to-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.4
4
+ version: 3.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Na'aman Hirschfeld <naaman@xberg.io>
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-04 00:00:00.000000000 Z
11
+ date: 2026-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys