sempdf
sempdf v1.9.1Functions

Function: htmlToBlocks()

sempdf v1.9.1


sempdf / htmlToBlocks

function htmlToBlocks(html, options?): TemplateBlock[];

Defined in: src/internal/html-blocks.ts:599

Converts an HTML fragment or document into template blocks.

Supported block elements: h1h6, p, div, ul/ol/li (nested, and mixed ordered/unordered), dl/dt/dd, pre (a code block), blockquote, table (with th/colspan/rowspan), hr, img, figure/figcaption, and the sectioning elements, which are unwrapped. Supported inline elements: strong/b, em/i, u, s/del/strike, mark, code/kbd/samp, sup, sub, small, span, a, and br.

Unknown elements are unwrapped so their text still renders; <script>, <style>, form controls, and embedded objects are dropped with their content.

Parameters

ParameterTypeDescription
htmlstringThe HTML to convert. Tag soup is tolerated.
optionsHtmlToBlocksOptionsMapping and styling options.

Returns

TemplateBlock[]

Blocks ready for renderTemplate, flow.render, or renderDocumentJson.

On this page