Skip to content
DuckDB community extension

duck_block_utils

Build, transform, validate, and extract content from structured documents using the duck_block type

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL duck_block_utils FROM community;
LOAD duck_block_utils FROM community;

Try it in a temporary SQL session with duck_block_utils already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Build a document programmatically

SQL
-- Build a document programmatically
SELECT duck_blocks_assemble([
    duck_block_heading(1, 'Hello World'),
    duck_block_paragraph([
        duck_block_text('This is '),
        duck_block_bold('important'),
        duck_block_text(' content.')
    ]),
    duck_block_code('sql', 'SELECT * FROM documents')
]);

-- Render it as plain text
SELECT duck_blocks_to_text(duck_blocks_assemble([
    duck_block_heading(1, 'Hello World'),
    duck_block_paragraph('Some prose.')
]));

-- Works with the markdown extension for reading and writing files
LOAD markdown;

-- Table of contents from a markdown file
SELECT * FROM duck_blocks_toc_rows(
    (SELECT list(b) FROM read_markdown_blocks('README.md') b)
);

-- Validate document structure
SELECT duck_blocks_validate(
    (SELECT list(b) FROM read_markdown_blocks('doc.md') b)
);

Provided by teaguesterling. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

The Duck Block Utils extension provides tools for building, transforming, validating, and extracting content from structured documents. All functions use the duck_block type - a unified representation for document elements that works across formats.

Nine names and eleven overloads left this extension for duckdb_panduck, with no alias path: pandoc_ast_to_blocks, read_pandoc_ast, write_pandoc_ast, duck_blocks_to_pandoc_ast, duck_blocks_to_pandoc_blocks, pandoc_ast, pandoc_inlines_to_db_inlines, pandoc_inlines_to_text and duck_blocks_inlines_to_pandoc. This extension is utility macros over the duck_block type; the Pandoc AST is panduck's subject.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
teaguesterling/duckdb_duck_block_utils
License
MIT
Maintainers
teaguesterling
Written in
C++
Build source
65f03cb7f776
Build definition
Community descriptor