Markdown Converter API Documentation

Overview

The Markdown Converter library provides a simple API for converting HTML to Markdown format.

Key Features

API Reference

markdown_converter_new

Creates a new converter instance.

Signature

markdown_converter_t* markdown_converter_new(void);

Returns

Pointer to a new converter instance, or NULL on failure.

Example

markdown_converter_t *converter = markdown_converter_new();
if (converter == NULL) {
    fprintf(stderr, "Failed to create converter\n");
    return 1;
}

markdown_convert

Converts HTML to Markdown.

Signature

void markdown_convert(
    markdown_converter_t *converter,
    const uint8_t *html,
    size_t html_len,
    const markdown_options_t *options,
    markdown_result_t *result
);

Parameters

Parameter Type Description
converter markdown_converter_t* Converter instance
html const uint8_t* Input HTML bytes
html_len size_t Length of HTML input
options const markdown_options_t* Conversion options
result markdown_result_t* Output result structure

Example

const char *html = "<h1>Hello</h1><p>World</p>";
markdown_options_t options = {
    .flavor = MARKDOWN_FLAVOR_COMMONMARK,
    .timeout_ms = 5000,
    .generate_etag = 1,
    .estimate_tokens = 1,
    .front_matter = 0
};

markdown_result_t result;
markdown_convert(converter, (const uint8_t*)html, strlen(html), &options, &result);

if (result.error_code == 0) {
    printf("Markdown: %.*s\n", (int)result.markdown_len, result.markdown);
    printf("Tokens: %u\n", result.token_estimate);
    markdown_result_free(&result);
} else {
    fprintf(stderr, "Error: %.*s\n", (int)result.error_len, result.error_message);
}

Examples

Basic Conversion

use markdown_converter::convert_html_to_markdown;

let html = "<h1>Title</h1><p>Content</p>";
let markdown = convert_html_to_markdown(html)?;
println!("{}", markdown);

With Options

use markdown_converter::{Converter, Options, Flavor};

let options = Options {
    flavor: Flavor::GitHubFlavoredMarkdown,
    timeout_ms: 10000,
    generate_etag: true,
    estimate_tokens: true,
    front_matter: true,
};

let converter = Converter::new();
let result = converter.convert(html, &options)?;