Install and load
Run these commands in a Haybarn SQL session. The extension is available from the community repository.
INSTALL markdown FROM community;
LOAD markdown FROM community;
Try it in a temporary SQL session with markdown 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.
Usage example
Read Markdown files with glob patterns
-- Load the extension
-- Read Markdown files with glob patterns
SELECT content FROM read_markdown('docs/**/*.md');
-- Parse into block-level elements (duck_block shape)
SELECT element_type, content, level
FROM read_markdown_blocks('README.md')
ORDER BY element_order;
-- Extract code blocks from Markdown text
SELECT cb.language, cb.code
FROM (
SELECT UNNEST(md_extract_code_blocks('```python\nprint("Hello")\n```')) as cb
);
-- Build rich text with inline elements
SELECT duck_blocks_to_md([
{kind: 'inline', element_type: 'text', content: 'Check out ', level: 1, encoding: 'text', attributes: MAP{}, element_order: 0},
{kind: 'inline', element_type: 'link', content: 'our docs', level: 1, encoding: 'text', attributes: MAP{'href': 'https://duckdb-markdown.readthedocs.io/'}, element_order: 1}
]);
-- Export query results as Markdown table
COPY (SELECT * FROM my_table) TO 'output.md' (FORMAT MARKDOWN);
-- Round-trip: read blocks, transform, write back
COPY (
SELECT kind, element_type, content, level, encoding, attributes
FROM read_markdown_blocks('doc.md')
) TO 'copy.md' (FORMAT MARKDOWN, markdown_mode 'blocks');
Provided by teaguesterling. Not yet verified on Haybarn 2.0.0.
Sample data & setupAbout this extension
The Markdown extension adds comprehensive Markdown processing capabilities to DuckDB, enabling structured analysis, transformation, and generation of Markdown documents.
Real-world benchmark: Processing 287 Markdown files (2,699 sections, 1,137 code blocks, 1,174 links) in 603ms.
Project overview from the community descriptor.
Documentation and resources
Project and build details
- Repository
- teaguesterling/duckdb_markdown
- License
- MIT
- Maintainers
- teaguesterling
- Written in
- C++
- Build source
6fc7013de640- Build definition
- Community descriptor