UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

22 lines (21 loc) 891 B
// src/utils/htmlLineBreaks.ts var BLOCK_LEVEL_TAG = /<(p|div|h[1-6]|ul|ol|li|blockquote|pre|table|figure|section|article)\b/i; var STANDALONE_IMAGE = /^<img\b[^>]*\/?>$/i; function normalizeLineBreaksInHtml(html, options = {}) { if (!html?.includes("\n")) return html; const normalizedHtml = html.replaceAll("\r\n", "\n"); if (BLOCK_LEVEL_TAG.test(normalizedHtml)) return normalizedHtml; const blocks = normalizedHtml.split(/\n{2,}/).map((block) => block.trim()).filter(Boolean); if (blocks.length === 0) return normalizedHtml; if (options.inline) { return blocks.map((block) => block.replaceAll("\n", "<br>")).join("<br><br>"); } return blocks.map((block) => { if (STANDALONE_IMAGE.test(block)) return block; return `<p>${block.replaceAll("\n", "<br>")}</p>`; }).join(""); } export { normalizeLineBreaksInHtml }; //# sourceMappingURL=chunk-QV5SUP4T.mjs.map