duck_block_utils
Erstellen, transformieren, validieren und extrahieren Sie Inhalte aus strukturierten Dokumenten mit dem Typ duck_block
Maintainer: teaguesterling
Installation und Laden
INSTALL duck_block_utils FROM community;LOAD duck_block_utils;Beispiel
-- Build a document programmaticallySELECT db_assemble([ db_heading(1, 'Hello World'), db_paragraph([ db_text('This is '), db_bold('important'), db_text(' content.') ]), db_code('sql', 'SELECT * FROM documents')]);
-- Works with markdown extension for reading/writing filesLOAD markdown;LOAD duck_block_utils;
-- Extract table of contents from markdownSELECT * FROM db_blocks_toc( (SELECT list(b) FROM read_markdown_blocks('README.md') b));
-- Convert blocks to plain textSELECT db_blocks_to_text( (SELECT list(b) FROM read_markdown_blocks('doc.md') b));
-- Validate document structureSELECT db_blocks_validate( (SELECT list(b) FROM read_markdown_blocks('doc.md') b));Über duck_block_utils
Die Erweiterung Duck Block Utils stellt Werkzeuge zum Erstellen, Transformieren, Validieren und
Extrahieren von Inhalten aus strukturierten Dokumenten bereit. Alle Funktionen nutzen den Typ duck_block –
eine einheitliche Darstellung für Dokumentelemente, die formatübergreifend funktioniert.
Dokumentation: duck-block-utils.readthedocs.io
Der Typ duck_block
Ein einheitliches Struct für Block- und Inline-Elemente:
STRUCT( kind VARCHAR, -- 'block' or 'inline' element_type VARCHAR, -- 'heading', 'paragraph', 'bold', 'link', etc. content VARCHAR, -- Textinhalt (NULL, wenn das Element Kinder hat) level INTEGER, -- Strukturtiefe (1=Block, 2+=Inline-Kinder) encoding VARCHAR, -- 'text', 'json', 'html', etc. attributes MAP(VARCHAR, VARCHAR), -- elementspezifische Metadaten element_order INTEGER -- Position im Dokument)V2-API-Design
Alle Builder-Funktionen geben LIST(duck_block) für eine einheitliche Komposition zurück:
-- Builder können natürlich verschachtelt werdenSELECT db_paragraph([ db_text('Click '), db_link('https://example.com', 'here'), db_text(' for more.')]);Block-Builder
| Function | Description |
|---|---|
db_heading(level, content) |
Überschrift erzeugen (h1–h6) |
db_paragraph(content) |
Absatz erzeugen |
db_code(language, content) |
Eingezäunten Codeblock erzeugen |
db_blockquote(content) |
Blockzitat erzeugen |
db_list_block(ordered, items[]) |
Geordnete/ungeordnete Liste erzeugen |
db_hr() |
Horizontale Linie erzeugen |
db_image(src, alt, title) |
Bildblock erzeugen |
db_metadata(content) |
YAML-Frontmatter erzeugen |
db_raw(format, content) |
Rohinhaltsblock erzeugen |
Inline-Builder
| Function | Description |
|---|---|
db_text(content) |
Klartext |
db_bold(content) |
Fett/stark hervorgehobener Text |
db_italic(content) |
Kursiver/betonter Text |
db_link(href, content) |
Hyperlink |
db_inline_code(content) |
Inline-Code |
db_math(content) |
Mathematikausdruck |
db_strikethrough(content) |
Durchgestrichener Text |
db_superscript(content) |
Hochgestellt |
db_subscript(content) |
Tiefgestellt |
Assemblierungsfunktionen
| Function | Description |
|---|---|
db_assemble(blocks[]) |
Blöcke zu einem Dokument kombinieren |
db_document(blocks[]) |
Alias für db_assemble |
db_section(level, title, children[]) |
Abschnitt mit Überschrift erzeugen |
db_concat(blocks1, blocks2) |
Blocklisten verketten |
db_rebase_levels(blocks, offset) |
Überschriftenebenen anpassen |
Extraktionsfunktionen
| Function | Description |
|---|---|
db_blocks_to_text(blocks) |
Klartext extrahieren |
db_blocks_headings(blocks) |
Überschriftenhierarchie extrahieren |
db_blocks_toc(blocks) |
Inhaltsverzeichnis erzeugen |
Validierung
| Function | Description |
|---|---|
db_blocks_validate(blocks) |
Dokumentstruktur validieren |
Pandoc-Integration
Konvertieren Sie zwischen Pandoc-JSON-AST und duck_block, ohne Pandoc zu benötigen:
| Function | Description |
|---|---|
pandoc_inlines_to_db_inlines(json) |
Pandoc-Inline-AST parsen |
db_inlines_to_pandoc(blocks) |
Nach Pandoc-Inline-AST konvertieren |
Ökosystem-Integration
Duck Block Utils arbeitet nahtlos mit anderen DuckDB-Dokumenterweiterungen zusammen:
- duckdb_markdown - Markdown-Dateien mit
read_markdown_blocks()lesen, mitCOPY ... TO ... (FORMAT markdown, MARKDOWN_MODE duck_block)schreiben - duckdb_webbed - HTML-Parsing und -Erzeugung
-- Markdown lesen, mit duck_block_utils bearbeiten, zurückschreibenLOAD markdown;LOAD duck_block_utils;
-- Add a disclaimer to all documentsCOPY ( SELECT block.* FROM ( SELECT unnest(db_assemble([ (SELECT list(b) FROM read_markdown_blocks('doc.md') b), db_hr(), db_paragraph('Generated by DuckDB') ])) as block )) TO 'output.md' (FORMAT markdown, MARKDOWN_MODE duck_block);Hinzugefügte Funktionen
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| db_assemble | scalar | NULL | NULL | |
| db_blockquote | scalar | NULL | NULL | |
| db_blocks_code_blocks | scalar | NULL | NULL | |
| db_blocks_exclude | scalar | NULL | NULL | |
| db_blocks_filter | scalar | NULL | NULL | |
| db_blocks_headings | scalar | NULL | NULL | |
| db_blocks_links | scalar | NULL | NULL | |
| db_blocks_lint | scalar | NULL | NULL | |
| db_blocks_merge | scalar | NULL | NULL | |
| db_blocks_render_ansi | scalar | NULL | NULL | |
| db_blocks_reorder | scalar | NULL | NULL | |
| db_blocks_slice | scalar | NULL | NULL | |
| db_blocks_stats | scalar | NULL | NULL | |
| db_blocks_structure | scalar | NULL | NULL | |
| db_blocks_to_text | scalar | NULL | NULL | |
| db_blocks_toc | scalar | NULL | NULL | |
| db_blocks_validate | scalar | NULL | NULL | |
| db_bold | scalar | NULL | NULL | |
| db_cite | scalar | NULL | NULL | |
| db_code | scalar | NULL | NULL | |
| db_concat | scalar | NULL | NULL | |
| db_div | scalar | NULL | NULL | |
| db_document | scalar | NULL | NULL | |
| db_heading | scalar | NULL | NULL | |
| db_hr | scalar | NULL | NULL | |
| db_image | scalar | NULL | NULL | |
| db_inline_code | scalar | NULL | NULL | |
| db_inline_image | scalar | NULL | NULL | |
| db_inlines_to_pandoc | scalar | NULL | NULL | |
| db_italic | scalar | NULL | NULL | |
| db_linebreak | scalar | NULL | NULL | |
| db_link | scalar | NULL | NULL | |
| db_list | scalar | NULL | NULL | |
| db_list_block | scalar | NULL | NULL | |
| db_list_item | scalar | NULL | NULL | |
| db_math | scalar | NULL | NULL | |
| db_metadata | scalar | NULL | NULL | |
| db_note | scalar | NULL | NULL | |
| db_paragraph | scalar | NULL | NULL | |
| db_quoted | scalar | NULL | NULL | |
| db_raw | scalar | NULL | NULL | |
| db_raw_inline | scalar | NULL | NULL | |
| db_rebase_levels | scalar | NULL | NULL | |
| db_section | scalar | NULL | NULL | |
| db_smallcaps | scalar | NULL | NULL | |
| db_softbreak | scalar | NULL | NULL | |
| db_space | scalar | NULL | NULL | |
| db_span | scalar | NULL | NULL | |
| db_strikethrough | scalar | NULL | NULL | |
| db_subscript | scalar | NULL | NULL | |
| db_superscript | scalar | NULL | NULL | |
| db_terminal_width | scalar | NULL | NULL | |
| db_text | scalar | NULL | NULL | |
| db_underline | scalar | NULL | NULL | |
| duck_block | scalar | NULL | NULL | |
| duck_block_aliases | pragma | NULL | NULL | |
| duck_block_attr | scalar | NULL | NULL | |
| duck_block_content | scalar | NULL | NULL | |
| duck_block_encoding | scalar | NULL | NULL | |
| duck_block_level | scalar | NULL | NULL | |
| duck_block_order | scalar | NULL | NULL | |
| duck_block_render | pragma | NULL | NULL | |
| duck_block_set_content | scalar | NULL | NULL | |
| duck_block_set_level | scalar | NULL | NULL | |
| duck_block_set_order | scalar | NULL | NULL | |
| duck_block_type | scalar | NULL | NULL | |
| duck_block_valid | scalar | NULL | NULL | |
| duck_blocks_to_pandoc_ast | scalar | NULL | NULL | |
| duck_blocks_to_pandoc_blocks | scalar | NULL | NULL | |
| pandoc_ast | table | NULL | NULL | |
| pandoc_ast_to_blocks | scalar | NULL | NULL | |
| pandoc_inlines_to_db_inlines | scalar | NULL | NULL | |
| pandoc_inlines_to_text | scalar | NULL | NULL | |
| read_pandoc_ast | scalar | NULL | NULL | |
| to_duck_block | scalar | NULL | NULL | |
| write_pandoc_ast | scalar | NULL | NULL |
Überladene Funktionen
Diese Erweiterung fügt keine Funktionsüberladungen hinzu.
Hinzugefügte Typen
| type_name | type_size | logical_type | type_category | internal |
|---|---|---|---|---|
| duck_block | 0 | STRUCT | COMPOSITE | true |
| duck_block_ext | 0 | STRUCT | COMPOSITE | true |
Hinzugefügte Einstellungen
Diese Erweiterung fügt keine Einstellungen hinzu.