html_to_markdown_rust library
HTML to Markdown Converter (Rust-powered)
A high-performance Dart package that converts HTML to Markdown using Rust's html-to-markdown-rs library via FFI (Foreign Function Interface).
Usage
import 'package:html_to_markdown_rust/html_to_markdown_rust.dart';
void main() {
final html = '<h1>Hello World</h1><p>This is a test.</p>';
final markdown = htmlToMarkdown(html);
print(markdown);
}
With Options
final options = ConversionOptions(
headingStyle: HeadingStyle.atx,
bullets: '*',
skipImages: true,
);
final markdown = htmlToMarkdown(html, options);
With Metadata Extraction
final result = htmlToMarkdownWithMetadata(
html,
options: ConversionOptions(),
metadataConfig: MetadataConfig(),
);
print(result.markdown);
print(result.metadata?.title);
With Inline Images Extraction
final result = htmlToMarkdownWithInlineImages(
html,
imageConfig: InlineImageConfig(maxDecodedSizeBytes: 10 * 1024 * 1024),
);
print(result.markdown);
for (final img in result.inlineImages) {
print('Image: ${img.filename}, format: ${img.format}');
}
Classes
- ConversionOptions
- Main configuration options for converting HTML to Markdown.
- ConversionResult
- Result of an HTML to Markdown conversion.
- DocumentMetadata
- Collected metadata from the document.
- HeaderMetadata
- Metadata about a header found in the document.
- ImageMetadata
- Metadata about an image found in the document.
- InlineImage
- Represents an inline image extracted from the HTML.
- InlineImageConfig
- Configuration for handling inline images.
- InlineImagesResult
- Result of an HTML to Markdown conversion with inline images.
- InlineImageWarning
- Warning generated during inline image processing.
- LinkMetadata
- Metadata about a link found in the document.
- MetadataConfig
- Configuration for metadata extraction.
- PreprocessingOptions
- Configuration options for HTML preprocessing before conversion.
Enums
- CodeBlockStyle
- Style for code blocks.
- HeadingStyle
- Style for Markdown headings.
- HighlightStyle
- Style for highlighting.
- InlineImageFormat
- Supported formats for inline images.
- InlineImageSource
- Source type of an inline image.
- ListIndentType
- Type of indentation for lists.
- NewlineStyle
- Style for handling newlines.
- PreprocessingPreset
- Presets for HTML preprocessing options.
- WhitespaceMode
- Mode for handling white spaces.
Functions
-
htmlToMarkdown(
String html, [ConversionOptions? options]) → String - Converts an HTML string to Markdown.
-
htmlToMarkdownWithInlineImages(
String html, {ConversionOptions? options, InlineImageConfig? imageConfig}) → InlineImagesResult - Converts an HTML string to Markdown and extracts inline images.
-
htmlToMarkdownWithMetadata(
String html, {ConversionOptions? options, MetadataConfig? metadataConfig}) → ConversionResult - Converts an HTML string to Markdown and extracts metadata.