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 +4 -4
- data/README.md +37 -23
- data/ext/html_to_markdown_rb/Cargo.toml +1 -1
- data/ext/html_to_markdown_rb/native/Cargo.lock +3 -3
- data/ext/html_to_markdown_rb/native/Cargo.toml +2 -2
- data/ext/html_to_markdown_rb/src/lib.rs +1 -1
- data/lib/html_to_markdown/native.rb +1 -1
- data/lib/html_to_markdown/version.rb +2 -2
- data/lib/html_to_markdown.rb +3 -9
- data/lib/html_to_markdown_rb.so +0 -0
- data/sig/types.rbs +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d86281ca72b53b8f6b281a4243f7545dba4b495ff3363a0ea06f86e54be0c5e
|
|
4
|
+
data.tar.gz: ede622514b81fcba60b1afc2226ecb7f301396826c546628b889048fad0b634b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
155
|
+
**`convert(html, options_or_visitor = nil) -> ConversionResult`**
|
|
144
156
|
|
|
145
|
-
Converts HTML to Markdown. Returns a `ConversionResult`
|
|
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
|
|
152
|
-
metadata = result
|
|
153
|
-
tables = result
|
|
154
|
-
document = result
|
|
155
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
247
|
-
puts result
|
|
248
|
-
puts result
|
|
249
|
-
puts result
|
|
250
|
-
puts result
|
|
251
|
-
puts result
|
|
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
|
-
|
|
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') ?
|
|
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
|
-
|
|
290
|
-
|
|
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
|
|
@@ -260,7 +260,7 @@ checksum = "46c1ff2d1cbf39efe5af0900ced8a069b5e61557a17544eb0c4a50239937389e"
|
|
|
260
260
|
|
|
261
261
|
[[package]]
|
|
262
262
|
name = "html-to-markdown-rb"
|
|
263
|
-
version = "3.10.
|
|
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.
|
|
277
|
+
version = "3.10.5"
|
|
278
278
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
279
|
-
checksum = "
|
|
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.
|
|
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.
|
|
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:
|
|
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:
|
|
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:
|
|
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.
|
|
9
|
+
VERSION = "3.10.5"
|
|
10
10
|
end
|
data/lib/html_to_markdown.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# This file is auto-generated by alef — DO NOT EDIT.
|
|
2
|
-
# alef:hash:
|
|
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
|
-
#
|
|
21
|
-
#
|
|
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.
|
data/lib/html_to_markdown_rb.so
CHANGED
|
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:
|
|
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
|
+
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-
|
|
11
|
+
date: 2026-08-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rb_sys
|