Some text
'); -- Returns list with 2 blocks: heading and paragraph -- Get all headings from a document SELECT block.content, block.level FROM (SELECT unnest(html_to_duck_blocks(html)) as block FROM documents) WHERE block.block_type = 'heading'; -- Count blocks by type SELECT block.block_type, COUNT(*) FROM (SELECT unnest(html_to_duck_blocks(html)) as block FROM documents) GROUP BY block.block_type; -- Extract code blocks with their language SELECT block.content, block.attributes['language'] as language FROM (SELECT unnest(html_to_duck_blocks( 'print("hello")'
)) as block)
WHERE block.block_type = 'code';
duck_blocks_to_html
~~~~~~~~~~~~~~~~~~
Convert a list of document blocks back to HTML. This is the inverse of ``html_to_duck_blocks``.
**Syntax:**
.. code-block:: sql
duck_blocks_to_html(blocks)
**Parameters:**
- ``blocks`` (LIST(duck_block)): A list of document blocks
**Returns:** HTML - The reconstructed HTML content
**Examples:**
.. code-block:: sql
-- Round-trip conversion
SELECT duck_blocks_to_html(html_to_duck_blocks('Text
')); -- Result:Text
-- Filter and reconstruct (keep only headings and paragraphs) SELECT duck_blocks_to_html( list_filter( html_to_duck_blocks(html), block -> block.block_type IN ('heading', 'paragraph') ) ) FROM documents; -- Reorder blocks SELECT duck_blocks_to_html( list_sort( html_to_duck_blocks(html), block -> block.block_order DESC ) ) FROM documents; Using with duck_block_utils for Markdown Conversion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When combined with the `duck_block_utilsThis is a paragraph.
This is a paragraph with bold text.