// Match the inline styles Messages can display. Keep code and escapes opaque // so delimiters inside examples never turn into formatting. const styles = /\\([\\*_~`])|(?= fence.length && !line.trim().slice(marker.length).trim() ) { fence = undefined; } text += line; continue; } if (marker) { fence = marker; text += line; continue; } let offset = 0; for (const match of line.matchAll(styles)) { const [token, escaped, , delimiter, content] = match; text += line.slice(offset, match.index); offset = match.index + token.length; if (!delimiter) { text += escaped ?? token; continue; } // JavaScript string lengths are UTF-16 code units, as Photon requires. const start = text.length; const length = content.length; if (delimiter === '~~') { formatting.push({ type: 'strikethrough', start, length }); } else { if (delimiter.length >= 2) formatting.push({ type: 'bold', start, length }); if (delimiter.length % 2) formatting.push({ type: 'italic', start, length }); } text += content; } text += line.slice(offset); } return { text, formatting }; }