htmd
An HTML to Markdown converter for Rust, inspired by turndown.js.
Features
- Rich options, same as turndown.js
- Reliable, it passes all test cases of turndown.js
- Minimum dependencies, it uses only html5ever
- Fast, it takes ~100ms to convert a ~1.4MB Wikipedia page on an i5 7th gen CPU
Looking for the cli tool? Try htmd-cli now!
Usages
Add the dependency
= "0.1"
Basic
Skip tags
use HtmlToMarkdown;
let converter = builder
.skip_tags
.build;
assert_eq!;
Options
use ;
let converter = builder
.options
.build;
assert_eq!;
Custom tag handlers
use HtmlToMarkdown;
let converter = builder
.add_handler
.build;
assert_eq!;
Multithreading
You can safely share HtmlToMarkdown between multiple threads when only using built-in tag handlers.
let converter = new;
for _ in 0..10
If you have custom tag handlers that are not stateless, you likely need a thread-safe mechanism. See AnchorElementHandler for example.
Credits
License
Copyright 2024 letmutex
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.