-
{{ error.message }}
-- httpSMS is an - open source - application that converts your android phone into an SMS gateway so you - can send and receive SMS messages using a simple HTTP API. -
-- Start sending messages -
-- {{ phoneCountry(phonesStore.owner) }} -
-- {{ contactsStore.total }} - {{ contactsStore.total === 1 ? 'contact' : 'contacts' }} -
-- Download our - CSV template, fill it in and upload it here. Columns: Name, Emails, - PhoneNumbers (multiple values separated by ";"). -
-${content}`),
+ )
+ .replace(INLINE_CODE_PATTERN, (_, content: string) =>
+ placeholders.protect(`${content}`),
+ )
+}
+
+/**
+ * Converts WhatsApp-style formatted text into sanitized HTML.
+ * Supported syntax (each marker pair must be surrounded by whitespace,
+ * punctuation, or the start/end of the string, and must not have internal
+ * leading/trailing whitespace, matching WhatsApp's own formatting rules):
+ * - *bold*
+ * - _italic_
+ * - ~strikethrough~
+ * - `code` / ```code block``` (code content is never re-formatted)
+ * - "> " quoted lines (the space after ">" is required)
+ * - raw URLs, turned into clickable links
+ */
+export function formatWhatsappText(text: string): string {
+ const escaped = escapeHtml(text ?? '')
+ const placeholders = createPlaceholderStore()
+
+ const withLinks = linkifyUrls(escaped, placeholders)
+
+ const withQuotes = withLinks
+ .split('\n')
+ .map((line) => {
+ const quoteMatch = line.match(/^> (.*)$/)
+ if (quoteMatch) {
+ return `${quoteMatch[1]}`
+ }
+ return line
+ })
+ .join('\n')
+
+ const withCode = extractCodeSpans(withQuotes, placeholders)
+
+ const formatted = withCode
+ .replace(BOLD_PATTERN, '$1')
+ .replace(ITALIC_PATTERN, '$1')
+ .replace(STRIKE_PATTERN, '