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.
- checksums.yaml +4 -4
- data/.rubocop.yml +29 -29
- data/Gemfile +15 -15
- data/Gemfile.lock +2 -3
- data/README.md +209 -210
- data/Rakefile +24 -24
- data/exe/html-to-markdown +6 -6
- data/ext/html-to-markdown-rb/extconf.rb +28 -28
- data/ext/html-to-markdown-rb/native/Cargo.toml +28 -0
- data/ext/html-to-markdown-rb/native/README.md +209 -0
- data/ext/html-to-markdown-rb/native/extconf.rb +3 -0
- data/ext/html-to-markdown-rb/native/src/lib.rs +432 -0
- data/html-to-markdown-rb.gemspec +59 -59
- data/lib/html_to_markdown/cli.rb +21 -21
- data/lib/html_to_markdown/cli_proxy.rb +71 -71
- data/lib/html_to_markdown/version.rb +5 -5
- data/lib/html_to_markdown.rb +24 -24
- data/spec/cli_proxy_spec.rb +42 -42
- data/spec/convert_spec.rb +29 -29
- data/spec/spec_helper.rb +10 -10
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 957492df2cee14d93b3cd74ac48f819058c886ecf93b63fe3649afc0f9e19935
|
|
4
|
+
data.tar.gz: 97c0dce3aa1621c33b42d82a2c1f2253b0d02b71ea9ff6cbd7f10ad9ba3a0d22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 74eb762ff081d375a44cac7265950b4648a068a5a5c9125dd8d4f8aa3ca1a3a6083c2bc37f393ae4ade99ce15958bbf12a7d908881760ac28985aafb93f6c92f
|
|
7
|
+
data.tar.gz: 80ab5cefd151fb887ddd792875d16146228253dc32d4b31d3ab3b033b25726a85ccbee345d7bdb71ee592de7ce882ad648b45dd92f79076a2b7ed04c8bec81b9
|
data/.rubocop.yml
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
plugins:
|
|
2
|
-
- rubocop-rspec
|
|
3
|
-
|
|
4
|
-
AllCops:
|
|
5
|
-
NewCops: enable
|
|
6
|
-
TargetRubyVersion: 3.2
|
|
7
|
-
Exclude:
|
|
8
|
-
- "tmp/**/*"
|
|
9
|
-
- "vendor/**/*"
|
|
10
|
-
|
|
11
|
-
Style/Documentation:
|
|
12
|
-
Enabled: false
|
|
13
|
-
|
|
14
|
-
Metrics/BlockLength:
|
|
15
|
-
Exclude:
|
|
16
|
-
- "spec/**/*"
|
|
17
|
-
- "*.gemspec"
|
|
18
|
-
|
|
19
|
-
Metrics/MethodLength:
|
|
20
|
-
Max: 15
|
|
21
|
-
|
|
22
|
-
RSpec/MultipleExpectations:
|
|
23
|
-
Enabled: false
|
|
24
|
-
|
|
25
|
-
RSpec/ExampleLength:
|
|
26
|
-
Enabled: false
|
|
27
|
-
|
|
28
|
-
RSpec/SpecFilePathFormat:
|
|
29
|
-
Enabled: false
|
|
1
|
+
plugins:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
NewCops: enable
|
|
6
|
+
TargetRubyVersion: 3.2
|
|
7
|
+
Exclude:
|
|
8
|
+
- "tmp/**/*"
|
|
9
|
+
- "vendor/**/*"
|
|
10
|
+
|
|
11
|
+
Style/Documentation:
|
|
12
|
+
Enabled: false
|
|
13
|
+
|
|
14
|
+
Metrics/BlockLength:
|
|
15
|
+
Exclude:
|
|
16
|
+
- "spec/**/*"
|
|
17
|
+
- "*.gemspec"
|
|
18
|
+
|
|
19
|
+
Metrics/MethodLength:
|
|
20
|
+
Max: 15
|
|
21
|
+
|
|
22
|
+
RSpec/MultipleExpectations:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
RSpec/ExampleLength:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
RSpec/SpecFilePathFormat:
|
|
29
|
+
Enabled: false
|
data/Gemfile
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
source 'https://rubygems.org'
|
|
4
|
-
|
|
5
|
-
ruby '>= 3.2'
|
|
6
|
-
|
|
7
|
-
gemspec
|
|
8
|
-
|
|
9
|
-
group :development, :test do
|
|
10
|
-
gem 'rake-compiler'
|
|
11
|
-
gem 'rb_sys' # provides build tooling when developing locally
|
|
12
|
-
gem 'rspec'
|
|
13
|
-
gem 'rubocop', require: false
|
|
14
|
-
gem 'rubocop-rspec', require: false
|
|
15
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
ruby '>= 3.2'
|
|
6
|
+
|
|
7
|
+
gemspec
|
|
8
|
+
|
|
9
|
+
group :development, :test do
|
|
10
|
+
gem 'rake-compiler'
|
|
11
|
+
gem 'rb_sys' # provides build tooling when developing locally
|
|
12
|
+
gem 'rspec'
|
|
13
|
+
gem 'rubocop', require: false
|
|
14
|
+
gem 'rubocop-rspec', require: false
|
|
15
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
html-to-markdown (2.6.
|
|
4
|
+
html-to-markdown (2.6.6)
|
|
5
5
|
rb_sys (>= 0.9, < 1.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -50,7 +50,7 @@ GEM
|
|
|
50
50
|
rubocop-ast (>= 1.47.1, < 2.0)
|
|
51
51
|
ruby-progressbar (~> 1.7)
|
|
52
52
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
53
|
-
rubocop-ast (1.
|
|
53
|
+
rubocop-ast (1.48.0)
|
|
54
54
|
parser (>= 3.3.7.2)
|
|
55
55
|
prism (~> 1.4)
|
|
56
56
|
rubocop-rspec (3.7.0)
|
|
@@ -64,7 +64,6 @@ GEM
|
|
|
64
64
|
PLATFORMS
|
|
65
65
|
arm64-darwin-24
|
|
66
66
|
ruby
|
|
67
|
-
x64-mingw-ucrt
|
|
68
67
|
|
|
69
68
|
DEPENDENCIES
|
|
70
69
|
html-to-markdown!
|
data/README.md
CHANGED
|
@@ -1,210 +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, and
|
|
4
|
-
|
|
5
|
-
[](https://crates.io/crates/html-to-markdown-rs)
|
|
6
|
-
[](https://www.npmjs.com/package/html-to-markdown-node)
|
|
7
|
-
[](https://www.npmjs.com/package/html-to-markdown-wasm)
|
|
8
|
-
[](https://crates.io/crates/html-to-markdown-rs)
|
|
6
|
+
[](https://www.npmjs.com/package/html-to-markdown-node)
|
|
7
|
+
[](https://www.npmjs.com/package/html-to-markdown-wasm)
|
|
8
|
+
[](https://pypi.org/project/html-to-markdown/)
|
|
9
|
+
[](https://packagist.org/packages/goldziher/html-to-markdown)
|
|
10
|
+
[](https://rubygems.org/gems/html-to-markdown)
|
|
11
|
+
[](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
|
data/Rakefile
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'bundler/gem_tasks'
|
|
4
|
-
require 'rb_sys/extensiontask'
|
|
5
|
-
require 'rspec/core/rake_task'
|
|
6
|
-
|
|
7
|
-
GEMSPEC = Gem::Specification.load(File.expand_path('html-to-markdown-rb.gemspec', __dir__))
|
|
8
|
-
|
|
9
|
-
RbSys::ExtensionTask.new('html-to-markdown-rb', GEMSPEC) do |ext|
|
|
10
|
-
ext.lib_dir = 'lib'
|
|
11
|
-
ext.ext_dir = 'ext/html-to-markdown-rb'
|
|
12
|
-
ext.cross_compile = true
|
|
13
|
-
ext.cross_platform = %w[
|
|
14
|
-
x86_64-linux
|
|
15
|
-
x86_64-darwin
|
|
16
|
-
arm64-darwin
|
|
17
|
-
x64-mingw32
|
|
18
|
-
]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
22
|
-
|
|
23
|
-
task spec: :compile
|
|
24
|
-
task default: :spec
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rb_sys/extensiontask'
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
|
|
7
|
+
GEMSPEC = Gem::Specification.load(File.expand_path('html-to-markdown-rb.gemspec', __dir__))
|
|
8
|
+
|
|
9
|
+
RbSys::ExtensionTask.new('html-to-markdown-rb', GEMSPEC) do |ext|
|
|
10
|
+
ext.lib_dir = 'lib'
|
|
11
|
+
ext.ext_dir = 'ext/html-to-markdown-rb'
|
|
12
|
+
ext.cross_compile = true
|
|
13
|
+
ext.cross_platform = %w[
|
|
14
|
+
x86_64-linux
|
|
15
|
+
x86_64-darwin
|
|
16
|
+
arm64-darwin
|
|
17
|
+
x64-mingw32
|
|
18
|
+
]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
22
|
+
|
|
23
|
+
task spec: :compile
|
|
24
|
+
task default: :spec
|
data/exe/html-to-markdown
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'html_to_markdown/cli'
|
|
5
|
-
|
|
6
|
-
exit HtmlToMarkdown::CLI.run(ARGV)
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'html_to_markdown/cli'
|
|
5
|
+
|
|
6
|
+
exit HtmlToMarkdown::CLI.run(ARGV)
|