| | |
| | | return container.innerHTML |
| | | } |
| | | |
| | | function preserveConsecutiveSpaces(html: string) { |
| | | if (!html || typeof document === 'undefined') |
| | | return html || '' |
| | | |
| | | const container = document.createElement('div') |
| | | container.innerHTML = html |
| | | |
| | | const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT) |
| | | const textNodes: Text[] = [] |
| | | |
| | | let currentNode = walker.nextNode() |
| | | while (currentNode) { |
| | | textNodes.push(currentNode as Text) |
| | | currentNode = walker.nextNode() |
| | | } |
| | | |
| | | textNodes.forEach((node) => { |
| | | const text = node.nodeValue || '' |
| | | if (!text.includes(' ')) |
| | | return |
| | | |
| | | // Convert consecutive spaces to non-breaking spaces so backend echoes |
| | | // and mini-program rich text both preserve the original spacing. |
| | | node.nodeValue = text.replace(/ {2,}/g, spaces => '\u00A0'.repeat(spaces.length)) |
| | | }) |
| | | |
| | | return container.innerHTML |
| | | } |
| | | |
| | | function formatRichTextContent(html: string) { |
| | | return formatRichTextList(formatTableForMiniProgram(html)) |
| | | return preserveConsecutiveSpaces(formatRichTextList(formatTableForMiniProgram(html))) |
| | | } |
| | | |
| | | function syncModelValue(html: string) { |