'use strict'; const { decodeEntities } = require('./util'); /** * Parse sanitized description HTML (see core/sanitize.js) into a flat list * of blocks with inline formatting runs, for renderers (PDF) that need to * preserve bold/italic/links/lists rather than flattening to plain text. * * Each block: { type, runs, indent, n? } * type: 'p' | 'h1'..'h4' | 'blockquote' | 'li' | 'oli' | 'hr' * runs: [{ text, bold, italic, code, href }] (absent for 'hr') * indent: list/quote nesting depth (0 = top level) * n: list item number, only for 'oli' */ const TAG_RE = /<\s*(\/?)\s*([a-zA-Z][a-zA-Z0-9]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g; const HREF_RE = /href\s*=\s*"([^"]*)"|href\s*=\s*'([^']*)'/i; function htmlToBlocks(html) { const blocks = []; let current = null; const styleStack = [{}]; const context = []; // nesting of