html-to-markdown 2.6.4 → 2.6.6

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.
@@ -1,28 +1,28 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mkmf'
4
- require 'rb_sys/mkmf'
5
- require 'rbconfig'
6
-
7
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
8
- devkit = ENV.fetch('RI_DEVKIT', nil)
9
- prefix = ENV['MSYSTEM_PREFIX'] || '/ucrt64'
10
-
11
- if devkit
12
- sysroot = "#{devkit}#{prefix}".tr('\\\\', '/')
13
- extra_args = [
14
- '--target=x86_64-pc-windows-gnu',
15
- "--sysroot=#{sysroot}"
16
- ]
17
-
18
- existing = ENV['BINDGEN_EXTRA_CLANG_ARGS'].to_s.split(/\s+/)
19
- ENV['BINDGEN_EXTRA_CLANG_ARGS'] = (existing + extra_args).uniq.join(' ')
20
- end
21
- end
22
-
23
- default_profile = ENV.fetch('CARGO_PROFILE', 'release')
24
-
25
- create_rust_makefile('html_to_markdown_rb') do |config|
26
- config.profile = default_profile.to_sym
27
- config.ext_dir = '../../../../crates/html-to-markdown-rb'
28
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ require 'rb_sys/mkmf'
5
+ require 'rbconfig'
6
+
7
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
8
+ devkit = ENV.fetch('RI_DEVKIT', nil)
9
+ prefix = ENV['MSYSTEM_PREFIX'] || '/ucrt64'
10
+
11
+ if devkit
12
+ sysroot = "#{devkit}#{prefix}".tr('\\\\', '/')
13
+ extra_args = [
14
+ '--target=x86_64-pc-windows-gnu',
15
+ "--sysroot=#{sysroot}"
16
+ ]
17
+
18
+ existing = ENV['BINDGEN_EXTRA_CLANG_ARGS'].to_s.split(/\s+/)
19
+ ENV['BINDGEN_EXTRA_CLANG_ARGS'] = (existing + extra_args).uniq.join(' ')
20
+ end
21
+ end
22
+
23
+ default_profile = ENV.fetch('CARGO_PROFILE', 'release')
24
+
25
+ create_rust_makefile('html_to_markdown_rb') do |config|
26
+ config.profile = default_profile.to_sym
27
+ config.ext_dir = File.expand_path('native', __dir__)
28
+ end
@@ -0,0 +1,28 @@
1
+ [package]
2
+ name = "html-to-markdown-rb"
3
+ version = "2.6.6"
4
+ edition = "2024"
5
+ authors = ["Na'aman Hirschfeld <nhirschfeld@gmail.com>"]
6
+ license = "MIT"
7
+ repository = "https://github.com/Goldziher/html-to-markdown"
8
+ homepage = "https://github.com/Goldziher/html-to-markdown"
9
+ documentation = "https://docs.rs/html-to-markdown-rs"
10
+ readme = "README.md"
11
+ rust-version = "1.85"
12
+ description = "Ruby bindings (Magnus) for html-to-markdown - high-performance HTML to Markdown converter"
13
+ keywords = ["html", "markdown", "ruby", "magnus", "bindings"]
14
+ categories = ["api-bindings"]
15
+
16
+ [lib]
17
+ name = "html_to_markdown_rb"
18
+ crate-type = ["cdylib", "rlib"]
19
+
20
+ [features]
21
+ default = []
22
+
23
+ [dependencies]
24
+ html-to-markdown-rs = { version = "2.6.5", features = ["inline-images"] }
25
+ magnus = { git = "https://github.com/matsadler/magnus", rev = "f6db11769efb517427bf7f121f9c32e18b059b38", features = ["rb-sys"] }
26
+
27
+ [dev-dependencies]
28
+ pretty_assertions = "1.4"
@@ -0,0 +1,209 @@
1
+ # html-to-markdown-rb
2
+
3
+ Blazing-fast HTML → Markdown conversion for Ruby, powered by the same Rust engine used by our Python, Node.js, WebAssembly, and PHP packages. Ship identical Markdown across every runtime while enjoying native extension performance.
4
+
5
+ [![Crates.io](https://img.shields.io/crates/v/html-to-markdown-rs.svg)](https://crates.io/crates/html-to-markdown-rs)
6
+ [![npm (node)](https://badge.fury.io/js/html-to-markdown-node.svg)](https://www.npmjs.com/package/html-to-markdown-node)
7
+ [![npm (wasm)](https://badge.fury.io/js/html-to-markdown-wasm.svg)](https://www.npmjs.com/package/html-to-markdown-wasm)
8
+ [![PyPI](https://badge.fury.io/py/html-to-markdown.svg)](https://pypi.org/project/html-to-markdown/)
9
+ [![Packagist](https://img.shields.io/packagist/v/goldziher/html-to-markdown.svg)](https://packagist.org/packages/goldziher/html-to-markdown)
10
+ [![RubyGems](https://badge.fury.io/rb/html-to-markdown.svg)](https://rubygems.org/gems/html-to-markdown)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Goldziher/html-to-markdown/blob/main/LICENSE)
12
+
13
+ ## Features
14
+
15
+ - ⚡ **Rust-fast**: Ruby bindings around a highly optimised Rust core (60‑80× faster than BeautifulSoup-based converters).
16
+ - 🔁 **Identical output**: Shares logic with the Python wheels, npm bindings, PHP extension, WASM package, and CLI — consistent Markdown everywhere.
17
+ - ⚙️ **Rich configuration**: Control heading styles, list indentation, whitespace handling, HTML preprocessing, and more.
18
+ - 🖼️ **Inline image extraction**: Pull out embedded images (PNG/JPEG/SVG/data URIs) alongside Markdown.
19
+ - 🧰 **Bundled CLI proxy**: Call the Rust CLI straight from Ruby or shell scripts.
20
+ - 🛠️ **First-class Rails support**: Works with `Gem.win_platform?` builds, supports Trusted Publishing, and compiles on install if no native gem matches.
21
+
22
+ ## Documentation & Support
23
+
24
+ - [GitHub repository](https://github.com/Goldziher/html-to-markdown)
25
+ - [Issue tracker](https://github.com/Goldziher/html-to-markdown/issues)
26
+ - [Changelog](https://github.com/Goldziher/html-to-markdown/blob/main/CHANGELOG.md)
27
+ - [Live demo (WASM)](https://goldziher.github.io/html-to-markdown/)
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ bundle add html-to-markdown
33
+ # or
34
+ gem install html-to-markdown
35
+ ```
36
+
37
+ Add the gem to your project and Bundler will compile the native Rust extension on first install.
38
+
39
+ ### Requirements
40
+
41
+ - Ruby **3.2+** (Magnus relies on the fiber scheduler APIs added in 3.2)
42
+ - Rust toolchain **1.85+** with Cargo available on your `$PATH`
43
+ - Ruby development headers (`ruby-dev`, `ruby-devel`, or the platform equivalent)
44
+
45
+ **Windows**: install [RubyInstaller with MSYS2](https://rubyinstaller.org/) (UCRT64). Run once:
46
+
47
+ ```powershell
48
+ ridk exec pacman -S --needed --noconfirm base-devel mingw-w64-ucrt-x86_64-toolchain
49
+ ```
50
+
51
+ This provides the standard headers (including `strings.h`) required for the bindgen step.
52
+
53
+ ## Performance Snapshot
54
+
55
+ Apple M4 • Real Wikipedia documents • `HtmlToMarkdown.convert` (Ruby)
56
+
57
+ | Document | Size | Latency | Throughput | Docs/sec |
58
+ | ------------------- | ----- | ------- | ---------- | -------- |
59
+ | Lists (Timeline) | 129KB | 0.69ms | 187 MB/s | 1,450 |
60
+ | Tables (Countries) | 360KB | 2.19ms | 164 MB/s | 456 |
61
+ | Mixed (Python wiki) | 656KB | 4.88ms | 134 MB/s | 205 |
62
+
63
+ > Same core, same benchmarks: the Ruby extension stays within single-digit % of the Rust CLI and mirrors the Python/Node numbers.
64
+
65
+ ## Quick Start
66
+
67
+ ```ruby
68
+ require 'html_to_markdown'
69
+
70
+ html = <<~HTML
71
+ <h1>Welcome</h1>
72
+ <p>This is <strong>Rust-fast</strong> conversion!</p>
73
+ <ul>
74
+ <li>Native extension</li>
75
+ <li>Identical output across languages</li>
76
+ </ul>
77
+ HTML
78
+
79
+ markdown = HtmlToMarkdown.convert(html)
80
+ puts markdown
81
+ # # Welcome
82
+ #
83
+ # This is **Rust-fast** conversion!
84
+ #
85
+ # - Native extension
86
+ # - Identical output across languages
87
+ ```
88
+
89
+ ## API
90
+
91
+ ### Conversion Options
92
+
93
+ Pass a Ruby hash (string or symbol keys) to tweak rendering. Every option maps one-for-one with the Rust/Python/Node APIs.
94
+
95
+ ```ruby
96
+ require 'html_to_markdown'
97
+
98
+ markdown = HtmlToMarkdown.convert(
99
+ '<pre><code class="language-ruby">puts "hi"</code></pre>',
100
+ heading_style: :atx,
101
+ code_block_style: :fenced,
102
+ bullets: '*+-',
103
+ list_indent_type: :spaces,
104
+ list_indent_width: 2,
105
+ whitespace_mode: :normalized,
106
+ highlight_style: :double_equal
107
+ )
108
+
109
+ puts markdown
110
+ ```
111
+
112
+ ### HTML Preprocessing
113
+
114
+ Clean up scraped HTML (navigation, forms, malformed markup) before conversion:
115
+
116
+ ```ruby
117
+ require 'html_to_markdown'
118
+
119
+ markdown = HtmlToMarkdown.convert(
120
+ html,
121
+ preprocessing: {
122
+ enabled: true,
123
+ preset: :aggressive, # :minimal, :standard, :aggressive
124
+ remove_navigation: true,
125
+ remove_forms: true
126
+ }
127
+ )
128
+ ```
129
+
130
+ ### Inline Images
131
+
132
+ Extract inline binary data (data URIs, SVG) together with the converted Markdown.
133
+
134
+ ```ruby
135
+ require 'html_to_markdown'
136
+
137
+ result = HtmlToMarkdown.convert_with_inline_images(
138
+ '<img src="data:image/png;base64,iVBORw0..." alt="Pixel">',
139
+ image_config: {
140
+ max_decoded_size_bytes: 1 * 1024 * 1024,
141
+ infer_dimensions: true,
142
+ filename_prefix: 'img_',
143
+ capture_svg: true
144
+ }
145
+ )
146
+
147
+ puts result.markdown
148
+ result.inline_images.each do |img|
149
+ puts "#{img.filename} -> #{img.format} (#{img.data.bytesize} bytes)"
150
+ end
151
+ ```
152
+
153
+ ## CLI
154
+
155
+ The gem bundles a small proxy for the Rust CLI binary. Use it when you need parity with the standalone `html-to-markdown` executable.
156
+
157
+ ```ruby
158
+ require 'html_to_markdown/cli'
159
+
160
+ HtmlToMarkdown::CLI.run(%w[--heading-style atx input.html], stdout: $stdout)
161
+ # => writes converted Markdown to STDOUT
162
+ ```
163
+
164
+ You can also call the CLI binary directly for scripting:
165
+
166
+ ```ruby
167
+ HtmlToMarkdown::CLIProxy.call(['--version'])
168
+ # => "html-to-markdown 2.5.7"
169
+ ```
170
+
171
+ Rebuild the CLI locally if you see `CLI binary not built` during tests:
172
+
173
+ ```bash
174
+ bundle exec rake compile # builds the extension
175
+ bundle exec ruby scripts/prepare_ruby_gem.rb # copies the CLI into lib/bin/
176
+ ```
177
+
178
+ ## Error Handling
179
+
180
+ Conversion errors raise `HtmlToMarkdown::Error` (wrapping the Rust error context). CLI invocations use specialised subclasses:
181
+
182
+ - `HtmlToMarkdown::CLIProxy::MissingBinaryError`
183
+ - `HtmlToMarkdown::CLIProxy::CLIExecutionError`
184
+
185
+ Rescue them to provide clearer feedback in your application.
186
+
187
+ ## Consistent Across Languages
188
+
189
+ The Ruby gem shares the exact Rust core with:
190
+
191
+ - [Python wheels](https://pypi.org/project/html-to-markdown/)
192
+ - [Node.js / Bun bindings](https://www.npmjs.com/package/html-to-markdown-node)
193
+ - [WebAssembly package](https://www.npmjs.com/package/html-to-markdown-wasm)
194
+ - The Rust crate and CLI
195
+
196
+ Use whichever runtime fits your stack while keeping formatting behaviour identical.
197
+
198
+ ## Development
199
+
200
+ ```bash
201
+ bundle exec rake compile # build the native extension
202
+ bundle exec rspec # run test suite
203
+ ```
204
+
205
+ The extension uses [Magnus](https://github.com/matsadler/magnus) plus `rb-sys` for bindgen. When editing the Rust code under `src/`, rerun `rake compile`.
206
+
207
+ ## License
208
+
209
+ MIT © Na'aman Hirschfeld
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../extconf'