Skip to main content

Crate h2m

Crate h2m 

Source
Expand description

§h2m

Fast, extensible HTML-to-Markdown converter for Rust — CommonMark + GFM, plugin architecture, zero unsafe.

§Quick start

let md = h2m::convert("<h1>Hello</h1><p>World</p>");
assert_eq!(md, "# Hello\n\nWorld");

§Builder API

use h2m::{Converter, Options};
use h2m::plugins::Gfm;
use h2m::rules::CommonMark;

let converter = Converter::builder()
    .options(Options::default())
    .use_plugin(&CommonMark)
    .use_plugin(&Gfm)
    .domain("example.com")
    .build();

let md = converter.convert(r#"<a href="/about">About</a>"#);
assert_eq!(md, "[About](https://example.com/about)");

§HTML utilities

The html module provides helpers for extracting page metadata without running a full conversion:

let title = h2m::html::extract_title("<title>Hello</title>");
assert_eq!(title.as_deref(), Some("Hello"));

Re-exports§

pub use converter::Action;
pub use converter::Converter;
pub use converter::ConverterBuilder;
pub use converter::Plugin;
pub use converter::Rule;
pub use options::BulletMarker;
pub use options::CodeBlockStyle;
pub use options::EmDelimiter;
pub use options::EscapeMode;
pub use options::Fence;
pub use options::HeadingStyle;
pub use options::HorizontalRule;
pub use options::LinkReferenceStyle;
pub use options::LinkStyle;
pub use options::Options;
pub use options::StrongDelimiter;

Modules§

converter
Core converter: traits, builder, frozen converter, and traversal pipeline.
html
HTML inspection utilities for extracting metadata from parsed documents.
options
Configuration options for the HTML-to-Markdown converter.
plugins
Plugins for extending the converter with additional format support.
rules
Built-in CommonMark conversion rules.

Structs§

Context
State maintained during the conversion traversal.

Enums§

ConvertError
Errors that can occur during HTML-to-Markdown conversion.

Functions§

convert
Converts HTML to Markdown using default CommonMark settings.
convert_gfm
Converts HTML to Markdown with GFM (GitHub Flavored Markdown) extensions.

Type Aliases§

Result
A specialized Result type for h2m operations.