Sample code for 30+ languages & platforms
Zig

Convert HTML to plain-text

See more HTML-to-XML/Text Examples

Demonstrates how to convert HTML to plain-text.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const h2t = try chilkat.HtmlToText.init();
    defer h2t.deinit();

    // Set the HTML:
    const html = "<html><body><p>This is a test.</p><blockquote>Here is text within a blockquote</blockquote></body></html>";

    const plain_text = try h2t.toText(alloc, html);

    std.debug.print("{s}\n", .{plain_text});

    // The output looks like this:

    // This is a test.
    //
    //     Here is text within a blockquote
}